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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81721): https://edk2.groups.io/g/devel/message/81721
Mute This Topic: https://groups.io/mt/86198794/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-