Adds ARM implementation of EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI.

Cc: Andrew Fish <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Michael D Kinney <[email protected]>
Cc: Chasel Chiu <[email protected]>
Signed-off-by: Nate DeSimone <[email protected]>
---
 EmulatorPkg/Sec/Arm/SwitchRam.S | 32 ++++++++++++++++++
 EmulatorPkg/Sec/Arm/TempRam.c   | 58 +++++++++++++++++++++++++++++++++
 EmulatorPkg/Sec/Sec.inf         |  9 ++++-
 3 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 EmulatorPkg/Sec/Arm/SwitchRam.S
 create mode 100644 EmulatorPkg/Sec/Arm/TempRam.c

diff --git a/EmulatorPkg/Sec/Arm/SwitchRam.S b/EmulatorPkg/Sec/Arm/SwitchRam.S
new file mode 100644
index 0000000000..d64772b8ed
--- /dev/null
+++ b/EmulatorPkg/Sec/Arm/SwitchRam.S
@@ -0,0 +1,32 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#------------------------------------------------------------------------------
+
+#include <AsmMacroIoLib.h>
+
+#/**
+#  This allows the caller to switch the stack and return
+#
+# @param      StackDelta     Signed amount by which to modify the stack pointer
+#
+# @return     Nothing. Goes to the Entry Point passing in the new parameters
+#
+#**/
+#VOID
+#EFIAPI
+#SecSwitchStack (
+#  VOID  *StackDelta
+#  )#
+#
+ASM_FUNC(SecSwitchStack)
+    mov   R1, R13
+    add   R1, R0, R1
+    mov   R13, R1
+    bx    LR
+
+
+
diff --git a/EmulatorPkg/Sec/Arm/TempRam.c b/EmulatorPkg/Sec/Arm/TempRam.c
new file mode 100644
index 0000000000..0a6b215591
--- /dev/null
+++ b/EmulatorPkg/Sec/Arm/TempRam.c
@@ -0,0 +1,58 @@
+/*++ @file
+  Temp RAM PPI
+
+  Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+  Copyright (c) 2023, Intel Corporation. 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
+SecSwitchStack (
+  INTN  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 ((UINTN)(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..264666f544 100644
--- a/EmulatorPkg/Sec/Sec.inf
+++ b/EmulatorPkg/Sec/Sec.inf
@@ -3,7 +3,7 @@
 #
 # Main executable file of Unix Emulator that loads PEI core after 
initialization finished.
 # Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
-# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2012 - 2023, Intel Corporation. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -30,10 +30,17 @@
   Ia32/SwitchRam.asm
   Ia32/SwitchRam.S
 
+[Sources.ARM]
+  Arm/TempRam.c
+  Arm/SwitchRam.S
+
 [Packages]
   MdePkg/MdePkg.dec
   EmulatorPkg/EmulatorPkg.dec
 
+[Packages.ARM]
+  ArmPkg/ArmPkg.dec
+
 [LibraryClasses]
   DebugLib
   PeCoffGetEntryPointLib
-- 
2.30.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#100706): https://edk2.groups.io/g/devel/message/100706
Mute This Topic: https://groups.io/mt/97414910/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to