+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+; Portitions copyright (c) 2011, Apple Inc. All rights reserved.\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution. The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+EXTERN CopyMem:PROC\r
+EXTERN ZeroMem:PROC\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; EFI_STATUS\r
+; EFIAPI\r
+; SecTemporaryRamSupport (\r
+; IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx\r
+; IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx\r
+; IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8\r
+; IN UINTN CopySize // %r9\r
+; )\r
+;------------------------------------------------------------------------------\r
+SecTemporaryRamSupport PROC\r
+ ; Adjust callers %rbp to account for stack move\r
+ sub rbp, rdx ; Calc offset of %rbp in Temp Memory\r
+ add rbp, r8 ; add in permanent base to offset\r
+\r
+ push rbp ; stack frame is for the debugger\r
+ mov rbp, rsp\r
+\r
+ push rdx ; Save TemporaryMemoryBase\r
+ push r8 ; Save PermanentMemoryBase\r
+ push r9 ; Save CopySize\r
+\r
+ ;\r
+ ; Copy all of temp RAM to permanent memory, including stack\r
+ ;\r
+ ; CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize);\r
+ ; %rcx, %rdx, %r8\r
+ mov rcx, r8 ; Shift arguments\r
+ mov r8, r9\r
+ sub rsp, 028h ; Allocate register spill area & 16-byte align stack\r
+ call CopyMem\r
+ ; Temp mem stack now copied to permanent location. %esp still in temp memory\r
+ add rsp, 028h\r
+\r
+ pop r9 ; CopySize (old stack)\r
+ pop r8 ; PermanentMemoryBase (old stack)\r
+ pop rdx ; TemporaryMemoryBase (old stack)\r
+\r
+ mov rcx, rsp ; Move to new stack\r
+ sub rcx, rdx ; Calc offset of stack in Temp Memory\r
+ add rcx, r8 ; Calc PermanentMemoryBase address\r
+ mov rsp, rcx ; Update stack\r
+ ; Stack now points to permanent memory\r
+\r
+ ; ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */);\r
+ mov rcx, rdx\r
+ mov rdx, r9\r
+ sub rsp, 028h ; Allocate register spill area & 16-byte align stack\r
+ call ZeroMem\r
+ add rsp, 028h\r
+\r
+ ; This data comes off the NEW stack\r
+ pop rbp\r
+ ret\r
+SecTemporaryRamSupport ENDP\r
+\r
+ END\r