]> git.proxmox.com Git - mirror_edk2.git/commitdiff
InOsEmuPkg: Fix IA-32 SEC temp ram code.
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 18 Jun 2011 23:36:36 +0000 (23:36 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 18 Jun 2011 23:36:36 +0000 (23:36 +0000)
Now we crash early in DXE Core.

Signed-off-by: andrewfish
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11852 6f19259b-4bc3-4df7-8a09-765794883524

InOsEmuPkg/Sec/Ia32/SwitchRam.S
InOsEmuPkg/Sec/Ia32/TempRam.c [new file with mode: 0644]
InOsEmuPkg/Sec/Sec.inf

index abb8e7dac1b9d541d3a611c1373219903b6b4ea4..81e478be820501641bd20ac38c2a5004d2b40a2d 100644 (file)
  .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
@@ -41,63 +30,66 @@ ASM_PFX(SecTemporaryRamSupport):
 //   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
diff --git a/InOsEmuPkg/Sec/Ia32/TempRam.c b/InOsEmuPkg/Sec/Ia32/TempRam.c
new file mode 100644 (file)
index 0000000..525fb95
--- /dev/null
@@ -0,0 +1,65 @@
+/*++ @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;
+}
index 5d875b55b57c955197483aa526f79da517ebfeec..8b9d604eec468b1223ad3bb44166bfa0da7673ba 100644 (file)
@@ -29,6 +29,7 @@
   X64/SwitchRam.S\r
 \r
 [Sources.IA32]\r
+  Ia32/TempRam.c\r
   Ia32/SwitchRam.S\r
 \r
 [Packages]\r