public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Akira Moroo" <retrage01@gmail.com>
To: devel@edk2.groups.io
Cc: afish@apple.com, ray.ni@intel.com, Akira Moroo <retrage01@gmail.com>
Subject: [RFC PATCH 2/4] EmulatorPkg/Sec: Add AArch64 support
Date: Sun, 10 Oct 2021 00:49:16 +0900	[thread overview]
Message-ID: <963e9d53c9011af94afeeea1ddb39ec171329ab5.1633789833.git.retrage01@gmail.com> (raw)
In-Reply-To: <cover.1633789833.git.retrage01@gmail.com>

This commit adds AArch64 support to EmulatorPkg/Sec. The architecture
specific part is switching stack from temporary to permanent.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
---
 EmulatorPkg/Sec/AArch64/SwitchRam.S | 22 +++++++++++
 EmulatorPkg/Sec/AArch64/TempRam.c   | 58 +++++++++++++++++++++++++++++
 EmulatorPkg/Sec/Sec.inf             |  4 ++
 3 files changed, 84 insertions(+)
 create mode 100644 EmulatorPkg/Sec/AArch64/SwitchRam.S
 create mode 100644 EmulatorPkg/Sec/AArch64/TempRam.c

diff --git a/EmulatorPkg/Sec/AArch64/SwitchRam.S b/EmulatorPkg/Sec/AArch64/SwitchRam.S
new file mode 100644
index 0000000000..9ec8ddd627
--- /dev/null
+++ b/EmulatorPkg/Sec/AArch64/SwitchRam.S
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2011, Apple Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#------------------------------------------------------------------------------
+
+
+// VOID
+// EFIAPI
+// SecSwitchStack (
+//   VOID  *StackDelta
+//   )
+//
+ASM_GLOBAL ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+    mov   x1, sp
+    add   x1, x0, x1
+    mov   sp, x1
+    ret
+
diff --git a/EmulatorPkg/Sec/AArch64/TempRam.c b/EmulatorPkg/Sec/AArch64/TempRam.c
new file mode 100644
index 0000000000..cce1dc559a
--- /dev/null
+++ b/EmulatorPkg/Sec/AArch64/TempRam.c
@@ -0,0 +1,58 @@
+/*++ @file
+  Temp RAM PPI
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <Ppi/TemporaryRamSupport.h>
+
+VOID
+EFIAPI
+SecSwitchStack (
+  VOID  *StackDelta
+  );
+
+
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+  IN CONST EFI_PEI_SERVICES   **PeiServices,
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
+  IN UINTN                    CopySize
+  )
+{
+  //
+  // Migrate the whole temporary memory to permanent memory.
+  //
+  CopyMem (
+    (VOID*)(UINTN)PermanentMemoryBase,
+    (VOID*)(UINTN)TemporaryMemoryBase,
+    CopySize
+    );
+
+  //
+  // SecSwitchStack function must be invoked after the memory migration
+  // immediately, also we need fixup the stack change caused by new call into
+  // permanent memory.
+  //
+  SecSwitchStack ((VOID *)(PermanentMemoryBase - TemporaryMemoryBase));
+
+  //
+  // We need *not* fix the return address because currently,
+  // The PeiCore is executed in flash.
+  //
+
+  //
+  // Simulate to invalid temporary memory, terminate temporary memory
+  //
+  ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
+
+  return EFI_SUCCESS;
+}
diff --git a/EmulatorPkg/Sec/Sec.inf b/EmulatorPkg/Sec/Sec.inf
index 2f9e3d4780..83248fbaca 100644
--- a/EmulatorPkg/Sec/Sec.inf
+++ b/EmulatorPkg/Sec/Sec.inf
@@ -30,6 +30,10 @@
   Ia32/SwitchRam.asm
   Ia32/SwitchRam.S
 
+[Sources.AARCH64]
+  AArch64/TempRam.c
+  AArch64/SwitchRam.S
+
 [Packages]
   MdePkg/MdePkg.dec
   EmulatorPkg/EmulatorPkg.dec
-- 
2.33.0


  parent reply	other threads:[~2021-10-09 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
2021-10-09 15:49 ` [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo Akira Moroo
2021-10-09 15:49 ` Akira Moroo [this message]
2021-10-09 15:49 ` [RFC PATCH 3/4] EmulatorPkg/Unix/Host: Add AArch64 support Akira Moroo
2021-10-09 15:49 ` [RFC PATCH 4/4] EmulatorPkg: Add AArch64 Unix host build support Akira Moroo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=963e9d53c9011af94afeeea1ddb39ec171329ab5.1633789833.git.retrage01@gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox