]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
• Set the default value of PcdDxeIplSwitchToLongMode to TRUE.
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / Ia32 / DxeLoadFunc.c
CommitLineData
878ddf1f 1/*++\r
2\r
eeb1cd5a 3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
878ddf1f 11\r
12Module Name:\r
13\r
14 DxeLoadFunc.c\r
15\r
16Abstract:\r
17\r
18 Ia32-specifc functionality for DxeLoad.\r
19\r
20--*/\r
21\r
abb26634 22#include "DxeIpl.h"\r
878ddf1f 23\r
eeb1cd5a 24VOID\r
657d3918 25HandOffToDxeCore (\r
26 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,\r
27 IN EFI_PEI_HOB_POINTERS HobList\r
eeb1cd5a 28 )\r
29{\r
657d3918 30 EFI_STATUS Status;\r
31 EFI_PHYSICAL_ADDRESS BaseOfStack;\r
32 EFI_PHYSICAL_ADDRESS TopOfStack;\r
33 EFI_PHYSICAL_ADDRESS PageTables;\r
34\r
35 Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
36 ASSERT_EFI_ERROR (Status);\r
37 \r
38 if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {\r
39 //\r
40 // Compute the top of the stack we were allocated, which is used to load X64 dxe core. \r
41 // Pre-allocate a 32 bytes which confroms to x64 calling convention.\r
42 //\r
43 // The first four parameters to a function are passed in rcx, rdx, r8 and r9. \r
44 // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the \r
45 // register parameters is reserved on the stack, in case the called function \r
46 // wants to spill them; this is important if the function is variadic. \r
47 //\r
48 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;\r
49\r
50 //\r
51 // X64 Calling Conventions requires that the stack must be aligned to 16 bytes\r
52 //\r
53 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);\r
54 //\r
55 // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA\r
56 // memory, it may be corrupted when copying FV to high-end memory \r
57 //\r
58 LoadGo64Gdt();\r
59 //\r
60 // Limit to 36 bits of addressing for debug. Should get it from CPU\r
61 //\r
62 PageTables = CreateIdentityMappingPageTables (36);\r
63 //\r
64 // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.\r
65 // Call x64 drivers passing in single argument, a pointer to the HOBs.\r
66 //\r
67 ActivateLongMode (\r
68 PageTables, \r
69 (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw), \r
70 TopOfStack,\r
71 0x00000000,\r
72 DxeCoreEntryPoint\r
73 );\r
74 } else {\r
75 //\r
76 // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
77 // for safety.\r
78 //\r
79 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;\r
80 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
81\r
82 SwitchStack (\r
83 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
84 HobList.Raw,\r
85 NULL,\r
86 (VOID *) (UINTN) TopOfStack\r
87 );\r
88 } \r
eeb1cd5a 89}\r