aboutsummaryrefslogtreecommitdiffstats
path: root/roms/edk2/EmulatorPkg/Sec
diff options
context:
space:
mode:
Diffstat (limited to 'roms/edk2/EmulatorPkg/Sec')
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.S89
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.asm88
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Ia32/TempRam.c59
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Sec.c140
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Sec.h45
-rw-r--r--roms/edk2/EmulatorPkg/Sec/Sec.inf48
-rw-r--r--roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.S66
-rw-r--r--roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.asm70
8 files changed, 605 insertions, 0 deletions
diff --git a/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.S b/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.S
new file mode 100644
index 000000000..d8298223a
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.S
@@ -0,0 +1,89 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# Module Name:
+#
+# Stack.asm
+#
+# Abstract:
+#
+# Switch the stack from temporary memory to permanent memory.
+#
+#------------------------------------------------------------------------------
+
+ .text
+
+
+//------------------------------------------------------------------------------
+// VOID
+// EFIAPI
+// SecSwitchStack (
+// UINT32 TemporaryMemoryBase,
+// UINT32 PermenentMemoryBase
+// )//
+//------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+#
+# Save three register: eax, ebx, ecx
+#
+ push %eax
+ push %ebx
+ push %ecx
+ push %edx
+
+#
+# !!CAUTION!! this function address's is pushed into stack after
+# migration of whole temporary memory, so need save it to permanent
+# memory at first!
+#
+
+ movl 20(%esp), %ebx # Save the first parameter
+ movl 24(%esp), %ecx # Save the second parameter
+
+#
+# Save this function's return address into permanent memory at first.
+# Then, Fixup the esp point to permanent memory
+#
+
+ movl %esp, %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl (%esp), %edx # copy pushed register's value to permanent memory
+ movl %edx, (%eax)
+ movl 4(%esp), %edx
+ movl %edx, 4(%eax)
+ movl 8(%esp), %edx
+ movl %edx, 8(%eax)
+ movl 12(%esp), %edx
+ movl %edx, 12(%eax)
+ movl 16(%esp), %edx
+ movl %edx, 16(%eax)
+ movl %eax, %esp # From now, esp is pointed to permanent memory
+
+#
+# Fixup the ebp point to permanent memory
+#
+#ifndef __APPLE__
+ movl %ebp, %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl %eax, %ebp # From now, ebp is pointed to permanent memory
+
+#
+# Fixup callee's ebp point for PeiDispatch
+#
+ movl (%ebp), %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permanent memory
+#endif
+
+ pop %edx
+ pop %ecx
+ pop %ebx
+ pop %eax
+ ret
+
diff --git a/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.asm b/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.asm
new file mode 100644
index 000000000..99ef00298
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Ia32/SwitchRam.asm
@@ -0,0 +1,88 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+; Stack.asm
+;
+; Abstract:
+;
+; Switch the stack from temporary memory to permanent memory.
+;
+;------------------------------------------------------------------------------
+
+ .586p
+ .model flat,C
+ .code
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; SecSwitchStack (
+; UINT32 TemporaryMemoryBase,
+; UINT32 PermenentMemoryBase
+; );
+;------------------------------------------------------------------------------
+SecSwitchStack PROC
+ ;
+ ; Save three register: eax, ebx, ecx
+ ;
+ push eax
+ push ebx
+ push ecx
+ push edx
+
+ ;
+ ; !!CAUTION!! this function address's is pushed into stack after
+ ; migration of whole temporary memory, so need save it to permanent
+ ; memory at first!
+ ;
+
+ mov ebx, [esp + 20] ; Save the first parameter
+ mov ecx, [esp + 24] ; Save the second parameter
+
+ ;
+ ; Save this function's return address into permanent memory at first.
+ ; Then, Fixup the esp point to permanent memory
+ ;
+ mov eax, esp
+ sub eax, ebx
+ add eax, ecx
+ mov edx, dword ptr [esp] ; copy pushed register's value to permanent memory
+ mov dword ptr [eax], edx
+ mov edx, dword ptr [esp + 4]
+ mov dword ptr [eax + 4], edx
+ mov edx, dword ptr [esp + 8]
+ mov dword ptr [eax + 8], edx
+ mov edx, dword ptr [esp + 12]
+ mov dword ptr [eax + 12], edx
+ mov edx, dword ptr [esp + 16] ; Update this function's return address into permanent memory
+ mov dword ptr [eax + 16], edx
+ mov esp, eax ; From now, esp is pointed to permanent memory
+
+ ;
+ ; Fixup the ebp point to permanent memory
+ ;
+ mov eax, ebp
+ sub eax, ebx
+ add eax, ecx
+ mov ebp, eax ; From now, ebp is pointed to permanent memory
+
+ ;
+ ; Fixup callee's ebp point for PeiDispatch
+ ;
+ mov eax, dword ptr [ebp]
+ sub eax, ebx
+ add eax, ecx
+ mov dword ptr [ebp], eax ; From now, Temporary's PPI caller's stack is in permanent memory
+
+ pop edx
+ pop ecx
+ pop ebx
+ pop eax
+ ret
+SecSwitchStack ENDP
+
+ END
diff --git a/roms/edk2/EmulatorPkg/Sec/Ia32/TempRam.c b/roms/edk2/EmulatorPkg/Sec/Ia32/TempRam.c
new file mode 100644
index 000000000..e8b0d53bb
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Ia32/TempRam.c
@@ -0,0 +1,59 @@
+/*++ @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 (
+ UINT32 TemporaryMemoryBase,
+ UINT32 PermenentMemoryBase
+ );
+
+
+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 ((UINT32) TemporaryMemoryBase, (UINT32) PermanentMemoryBase);
+
+ //
+ // 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/roms/edk2/EmulatorPkg/Sec/Sec.c b/roms/edk2/EmulatorPkg/Sec/Sec.c
new file mode 100644
index 000000000..1c0f73d66
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Sec.c
@@ -0,0 +1,140 @@
+/*++ @file
+ Stub SEC that is called from the OS application that is the root of the emulator.
+
+ The OS application will call the SEC with the PEI Entry Point API.
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Sec.h"
+
+
+
+EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {
+ SecTemporaryRamSupport
+};
+
+
+EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gEfiTemporaryRamSupportPpiGuid,
+ &mSecTemporaryRamSupportPpi
+ }
+};
+
+
+
+/**
+ The entry point of PE/COFF Image for the PEI Core, that has been hijacked by this
+ SEC that sits on top of an OS application. So the entry and exit of this module
+ has the same API.
+
+ This function is the entry point for the PEI Foundation, which allows the SEC phase
+ to pass information about the stack, temporary RAM and the Boot Firmware Volume.
+ In addition, it also allows the SEC phase to pass services and data forward for use
+ during the PEI phase in the form of one or more PPIs.
+ There is no limit to the number of additional PPIs that can be passed from SEC into
+ the PEI Foundation. As part of its initialization phase, the PEI Foundation will add
+ these SEC-hosted PPIs to its PPI database such that both the PEI Foundation and any
+ modules can leverage the associated service calls and/or code in these early PPIs.
+ This function is required to call ProcessModuleEntryPointList() with the Context
+ parameter set to NULL. ProcessModuleEntryPoint() is never expected to return.
+ The PEI Core is responsible for calling ProcessLibraryConstructorList() as soon as
+ the PEI Services Table and the file handle for the PEI Core itself have been established.
+ If ProcessModuleEntryPointList() returns, then ASSERT() and halt the system.
+
+ @param SecCoreData Points to a data structure containing information about the PEI
+ core's operating environment, such as the size and location of
+ temporary RAM, the stack location and the BFV location.
+
+ @param PpiList Points to a list of one or more PPI descriptors to be installed
+ initially by the PEI core. An empty PPI list consists of a single
+ descriptor with the end-tag EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST.
+ As part of its initialization phase, the PEI Foundation will add
+ these SEC-hosted PPIs to its PPI database such that both the PEI
+ Foundation and any modules can leverage the associated service calls
+ and/or code in these early PPIs.
+
+**/
+VOID
+EFIAPI
+_ModuleEntryPoint (
+ IN EFI_SEC_PEI_HAND_OFF *SecCoreData,
+ IN EFI_PEI_PPI_DESCRIPTOR *PpiList
+ )
+{
+ EFI_STATUS Status;
+ EFI_PEI_FV_HANDLE VolumeHandle;
+ EFI_PEI_FILE_HANDLE FileHandle;
+ VOID *PeCoffImage;
+ EFI_PEI_CORE_ENTRY_POINT EntryPoint;
+ EFI_PEI_PPI_DESCRIPTOR *Ppi;
+ EFI_PEI_PPI_DESCRIPTOR *SecPpiList;
+ UINTN SecReseveredMemorySize;
+ UINTN Index;
+ EFI_PEI_PPI_DESCRIPTOR PpiArray[10];
+
+ EMU_MAGIC_PAGE()->PpiList = PpiList;
+ ProcessLibraryConstructorList ();
+
+ DEBUG ((EFI_D_ERROR, "SEC Has Started\n"));
+
+ //
+ // Add Our PPIs to the list
+ //
+ SecReseveredMemorySize = sizeof (gPrivateDispatchTable);
+ for (Ppi = PpiList, Index = 1; ; Ppi++, Index++) {
+ SecReseveredMemorySize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
+
+ if ((Ppi->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
+ // Since we are appending, need to clear out previous list terminator.
+ Ppi->Flags &= ~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
+ break;
+ }
+ }
+
+ // Keep everything on a good alignment
+ SecReseveredMemorySize = ALIGN_VALUE (SecReseveredMemorySize, CPU_STACK_ALIGNMENT);
+
+#if 0
+ // Tell the PEI Core to not use our buffer in temp RAM
+ SecPpiList = (EFI_PEI_PPI_DESCRIPTOR *)SecCoreData->PeiTemporaryRamBase;
+ SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + SecReseveredMemorySize);
+ SecCoreData->PeiTemporaryRamSize -= SecReseveredMemorySize;
+#else
+ //
+ // When I subtrack from SecCoreData->PeiTemporaryRamBase PEI Core crashes? Either there is a bug
+ // or I don't understand temp RAM correctly?
+ //
+
+ SecPpiList = &PpiArray[0];
+ ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize);
+#endif
+ // Copy existing list, and append our entries.
+ CopyMem (SecPpiList, PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR) * Index);
+ CopyMem (&SecPpiList[Index], gPrivateDispatchTable, sizeof (gPrivateDispatchTable));
+
+ // Find PEI Core and transfer control
+ VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)SecCoreData->BootFirmwareVolumeBase;
+ FileHandle = NULL;
+ Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_PEI_CORE, VolumeHandle, &FileHandle);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = PeCoffLoaderGetEntryPoint (PeCoffImage, (VOID **)&EntryPoint);
+ ASSERT_EFI_ERROR (Status);
+
+ // Transfer control to PEI Core
+ EntryPoint (SecCoreData, SecPpiList);
+
+ // PEI Core never returns
+ ASSERT (FALSE);
+ return;
+}
+
+
diff --git a/roms/edk2/EmulatorPkg/Sec/Sec.h b/roms/edk2/EmulatorPkg/Sec/Sec.h
new file mode 100644
index 000000000..42554e05b
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Sec.h
@@ -0,0 +1,45 @@
+/*++ @file
+ Stub SEC that is called from the OS application that is the root of the emulator.
+
+ The OS application will call the SEC with the PEI Entry Point API.
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __SEC_H___
+#define __SEC_H___
+
+
+#include <PiPei.h>
+#include <Library/EmuMagicPageLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <Ppi/TemporaryRamSupport.h>
+
+
+//
+// I think this should be defined in a MdePkg include file?
+//
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+ VOID
+ );
+
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+ IN CONST EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
+ IN UINTN CopySize
+ );
+
+
+#endif
+
diff --git a/roms/edk2/EmulatorPkg/Sec/Sec.inf b/roms/edk2/EmulatorPkg/Sec/Sec.inf
new file mode 100644
index 000000000..2f9e3d478
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/Sec.inf
@@ -0,0 +1,48 @@
+## @file
+# Entry Point of Emu Emulator
+#
+# 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>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = EmuSec
+ FILE_GUID = BCAF98C9-22B0-3B4F-9CBD-C8A6B4DBCEE9
+ MODULE_TYPE = SEC
+ VERSION_STRING = 1.0
+
+
+[Sources]
+ Sec.c
+
+[Sources.X64]
+ X64/SwitchRam.asm
+ X64/SwitchRam.S
+
+[Sources.IA32]
+ Ia32/TempRam.c
+ Ia32/SwitchRam.asm
+ Ia32/SwitchRam.S
+
+[Packages]
+ MdePkg/MdePkg.dec
+ EmulatorPkg/EmulatorPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ PeCoffGetEntryPointLib
+ PeiServicesLib
+ PpiListLib
+ BaseMemoryLib
+
+[Ppis]
+ gEfiTemporaryRamSupportPpiGuid
+
+[Pcd]
+ gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage
diff --git a/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.S b/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.S
new file mode 100644
index 000000000..59d4e2ede
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.S
@@ -0,0 +1,66 @@
+#------------------------------------------------------------------------------
+#
+# 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
+#
+#------------------------------------------------------------------------------
+
+
+
+// EFI_STATUS
+// EFIAPI
+// SecTemporaryRamSupport (
+// IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx
+// IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx
+// IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8
+// IN UINTN CopySize // %r9
+// )
+//
+ASM_GLOBAL ASM_PFX(SecTemporaryRamSupport)
+ASM_PFX(SecTemporaryRamSupport):
+ // Adjust callers %rbp to account for stack move
+ subq %rdx, %rbp // Calc offset of %rbp in Temp Memory
+ addq %r8, %rbp // add in permanent base to offset
+
+ pushq %rbp // stack frame is for the debugger
+ movq %rsp, %rbp
+
+ pushq %rdx // Save TemporaryMemoryBase
+ pushq %r8 // Save PermanentMemoryBase
+ pushq %r9 // Save CopySize
+
+ //
+ // Copy all of temp RAM to permanent memory, including stack
+ //
+ // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
+ // %rcx, %rdx, %r8
+ movq %r8, %rcx // Shift arguments
+ movq %r9, %r8
+ subq $0x28, %rsp // Allocate register spill area & 16-byte align stack
+ call ASM_PFX(CopyMem)
+ // Temp mem stack now copied to permanent location. %esp still in temp memory
+ addq $0x28, %rsp
+
+ popq %r9 // CopySize (old stack)
+ popq %r8 // PermanentMemoryBase (old stack)
+ popq %rdx // TemporaryMemoryBase (old stack)
+
+ movq %rsp, %rcx // Move to new stack
+ subq %rdx, %rcx // Calc offset of stack in Temp Memory
+ addq %r8, %rcx // Calc PermanentMemoryBase address
+ movq %rcx, %rsp // Update stack
+ // Stack now points to permanent memory
+
+ // ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */);
+ movq %rdx, %rcx
+ movq %r9, %rdx
+ subq $0x28, %rsp // Allocate register spill area & 16-byte align stack
+ call ASM_PFX(ZeroMem)
+ addq $0x28, %rsp
+
+ // This data comes off the NEW stack
+ popq %rbp
+ ret
+
+
diff --git a/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.asm b/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.asm
new file mode 100644
index 000000000..e66bda5bf
--- /dev/null
+++ b/roms/edk2/EmulatorPkg/Sec/X64/SwitchRam.asm
@@ -0,0 +1,70 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+; Portions copyright (c) 2011, Apple Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;------------------------------------------------------------------------------
+
+EXTERN CopyMem:PROC
+EXTERN ZeroMem:PROC
+
+ .code
+
+;------------------------------------------------------------------------------
+; EFI_STATUS
+; EFIAPI
+; SecTemporaryRamSupport (
+; IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx
+; IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx
+; IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8
+; IN UINTN CopySize // %r9
+; )
+;------------------------------------------------------------------------------
+SecTemporaryRamSupport PROC
+ ; Adjust callers %rbp to account for stack move
+ sub rbp, rdx ; Calc offset of %rbp in Temp Memory
+ add rbp, r8 ; add in permanent base to offset
+
+ push rbp ; stack frame is for the debugger
+ mov rbp, rsp
+
+ push rdx ; Save TemporaryMemoryBase
+ push r8 ; Save PermanentMemoryBase
+ push r9 ; Save CopySize
+
+ ;
+ ; Copy all of temp RAM to permanent memory, including stack
+ ;
+ ; CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);
+ ; %rcx, %rdx, %r8
+ mov rcx, r8 ; Shift arguments
+ mov r8, r9
+ sub rsp, 028h ; Allocate register spill area & 16-byte align stack
+ call CopyMem
+ ; Temp mem stack now copied to permanent location. %esp still in temp memory
+ add rsp, 028h
+
+ pop r9 ; CopySize (old stack)
+ pop r8 ; PermanentMemoryBase (old stack)
+ pop rdx ; TemporaryMemoryBase (old stack)
+
+ mov rcx, rsp ; Move to new stack
+ sub rcx, rdx ; Calc offset of stack in Temp Memory
+ add rcx, r8 ; Calc PermanentMemoryBase address
+ mov rsp, rcx ; Update stack
+ ; Stack now points to permanent memory
+
+ ; ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */);
+ mov rcx, rdx
+ mov rdx, r9
+ sub rsp, 028h ; Allocate register spill area & 16-byte align stack
+ call ZeroMem
+ add rsp, 028h
+
+ ; This data comes off the NEW stack
+ pop rbp
+ ret
+SecTemporaryRamSupport ENDP
+
+ END