.text\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
-ASM_GLOBAL ASM_PFX(SecTemporaryRamSupport)\r
-ASM_PFX(SecTemporaryRamSupport):\r
//------------------------------------------------------------------------------\r
// VOID\r
// EFIAPI\r
// UINT32 PermenentMemoryBase\r
// )//\r
//------------------------------------------------------------------------------ \r
-\r
- //\r
- // Save three register: eax, ebx, ecx\r
- //\r
+ASM_GLOBAL ASM_PFX(SecSwitchStack)\r
+ASM_PFX(SecSwitchStack):\r
+#\r
+# Save three register: eax, ebx, ecx\r
+# \r
push %eax\r
push %ebx\r
push %ecx\r
push %edx\r
-\r
-#if 0 \r
-// Port me to GAS syntax\r
- //\r
- // !!CAUTION!! this function addresss is pushed into stack after\r
- // migration of whole temporary memory, so need save it to permenent\r
- // memory at first!\r
- //\r
\r
- mov ebx, [esp + 20] // Save the first parameter\r
- mov ecx, [esp + 24] // Save the second parameter\r
+#\r
+# !!CAUTION!! this function address's is pushed into stack after\r
+# migration of whole temporary memory, so need save it to permenent\r
+# memory at first!\r
+# \r
+ \r
+ movl 20(%esp), %ebx # Save the first parameter\r
+ movl 24(%esp), %ecx # Save the second parameter\r
+ \r
+#\r
+# Save this function's return address into permenent memory at first.\r
+# Then, Fixup the esp point to permenent memory\r
+#\r
+\r
+ movl %esp, %eax\r
+ subl %ebx, %eax\r
+ addl %ecx, %eax\r
+ movl (%esp), %edx # copy pushed register's value to permenent memory\r
+ movl %edx, (%eax)\r
+ movl 4(%esp), %edx\r
+ movl %edx, 4(%eax)\r
+ movl 8(%esp), %edx\r
+ movl %edx, 8(%eax)\r
+ movl 12(%esp), %edx\r
+ movl %edx, 12(%eax)\r
+ movl 16(%esp), %edx\r
+ movl %edx, 16(%eax)\r
+ movl %eax, %esp # From now, esp is pointed to permenent memory\r
+\r
+#\r
+# Fixup the ebp point to permenent memory\r
+#\r
+#ifndef __APPLE__\r
+ movl %ebp, %eax\r
+ subl %ebx, %eax\r
+ addl %ecx, %eax\r
+ movl %eax, %ebp # From now, ebp is pointed to permenent memory\r
\r
- //\r
- // Save this functions return address into permenent memory at first.\r
- // Then, Fixup the esp point to permenent memory\r
- //\r
- mov eax, esp\r
- sub eax, ebx\r
- add eax, ecx\r
- mov edx, dword ptr [esp] // copy pushed registers value to permenent memory\r
- mov dword ptr [eax], edx \r
- mov edx, dword ptr [esp + 4]\r
- mov dword ptr [eax + 4], edx \r
- mov edx, dword ptr [esp + 8]\r
- mov dword ptr [eax + 8], edx \r
- mov edx, dword ptr [esp + 12]\r
- mov dword ptr [eax + 12], edx \r
- mov edx, dword ptr [esp + 16] // Update this functions return address into permenent memory\r
- mov dword ptr [eax + 16], edx \r
- mov esp, eax // From now, esp is pointed to permenent memory\r
- \r
- //\r
- // Fixup the ebp point to permenent memory\r
- //\r
- mov eax, ebp\r
- sub eax, ebx\r
- add eax, ecx\r
- mov ebp, eax // From now, ebp is pointed to permenent memory\r
+#\r
+# Fixup callee's ebp point for PeiDispatch\r
+# \r
+ movl (%ebp), %eax\r
+ subl %ebx, %eax\r
+ addl %ecx, %eax\r
+ movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory\r
+#endif \r
\r
- //\r
- // Fixup callees ebp point for PeiDispatch\r
- //\r
- mov eax, dword ptr [ebp]\r
- sub eax, ebx\r
- add eax, ecx\r
- mov dword ptr [ebp], eax // From now, Temporarys PPI callers stack is in permenent memory\r
-#endif\r
pop %edx\r
pop %ecx\r
pop %ebx\r
pop %eax\r
ret\r
+\r
--- /dev/null
+/*++ @file
+ Temp RAM PPI
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#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 permenent memory.
+ //
+ CopyMem (
+ (VOID*)(UINTN)PermanentMemoryBase,
+ (VOID*)(UINTN)TemporaryMemoryBase,
+ CopySize
+ );
+
+ //
+ // SecSwitchStack function must be invoked after the memory migration
+ // immediatly, also we need fixup the stack change caused by new call into
+ // permenent memory.
+ //
+ SecSwitchStack ((UINT32) TemporaryMemoryBase, (UINT32) PermanentMemoryBase);
+
+ //
+ // We need *not* fix the return address because currently,
+ // The PeiCore is excuted in flash.
+ //
+
+ //
+ // Simulate to invalid temporary memory, terminate temporary memory
+ //
+ //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
+
+ return EFI_SUCCESS;
+}