]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
• Set the default value of PcdDxeIplSwitchToLongMode to TRUE.
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / Ia32 / DxeLoadFunc.c
index 4d1015bbd89099be45c8fba916415153e9a2e1eb..6b61086cf2d86397152f039f1f2de593b8a45f21 100644 (file)
@@ -1,13 +1,13 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
 Module Name:\r
 \r
@@ -19,33 +19,71 @@ Abstract:
 \r
 --*/\r
 \r
-#include <DxeIpl.h>\r
+#include "DxeIpl.h"\r
 \r
-EFI_STATUS\r
-CreateArchSpecificHobs (\r
-  OUT EFI_PHYSICAL_ADDRESS      *BspStore\r
+VOID\r
+HandOffToDxeCore (\r
+  IN EFI_PHYSICAL_ADDRESS   DxeCoreEntryPoint,\r
+  IN EFI_PEI_HOB_POINTERS   HobList\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Creates architecture-specific HOBs.\r
-\r
-  Note: New parameters should NOT be added for any HOBs that are added to this\r
-        function.  BspStore is a special case because it is required for the\r
-        call to SwitchStacks() in DxeLoad().\r
-\r
-Arguments:\r
-\r
-  BspStore    - The address of the BSP Store for those architectures that need\r
-                it.  Otherwise 0.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS   - The HOBs were created successfully.\r
-\r
---*/\r
 {\r
-  *BspStore = 0;\r
-  return EFI_SUCCESS;\r
+  EFI_STATUS                Status;\r
+  EFI_PHYSICAL_ADDRESS      BaseOfStack;\r
+  EFI_PHYSICAL_ADDRESS      TopOfStack;\r
+  EFI_PHYSICAL_ADDRESS      PageTables;\r
+\r
+  Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {\r
+    //\r
+    // Compute the top of the stack we were allocated, which is used to load X64 dxe core. \r
+    // Pre-allocate a 32 bytes which confroms to x64 calling convention.\r
+    //\r
+    // The first four parameters to a function are passed in rcx, rdx, r8 and r9. \r
+    // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the \r
+    // register parameters is reserved on the stack, in case the called function \r
+    // wants to spill them; this is important if the function is variadic. \r
+    //\r
+    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;\r
+\r
+    //\r
+    //  X64 Calling Conventions requires that the stack must be aligned to 16 bytes\r
+    //\r
+    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);\r
+    //\r
+    // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA\r
+    // memory, it may be corrupted when copying FV to high-end memory \r
+    //\r
+    LoadGo64Gdt();\r
+    //\r
+    // Limit to 36 bits of addressing for debug. Should get it from CPU\r
+    //\r
+    PageTables = CreateIdentityMappingPageTables (36);\r
+    //\r
+    // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.\r
+    // Call x64 drivers passing in single argument, a pointer to the HOBs.\r
+    //\r
+    ActivateLongMode (\r
+      PageTables, \r
+      (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw), \r
+      TopOfStack,\r
+      0x00000000,\r
+      DxeCoreEntryPoint\r
+      );\r
+  } else {\r
+    //\r
+    // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
+    // for safety.\r
+    //\r
+    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;\r
+    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
+\r
+    SwitchStack (\r
+      (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
+      HobList.Raw,\r
+      NULL,\r
+      (VOID *) (UINTN) TopOfStack\r
+      );\r
+  } \r
 }\r