]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
Update SEC Platform Information PPI according to PI 1.2 errata A.
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / Ia32 / DxeLoadFunc.c
CommitLineData
96226baa 1/** @file\r
48557c65 2 Ia32-specific functionality for DxeLoad.\r
95276127 3\r
0cf27ce0 4Copyright (c) 2006 - 2010, Intel Corporation. <BR>\r
95276127 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
96226baa 13**/\r
95276127 14\r
95276127 15#include "DxeIpl.h"\r
16#include "VirtualMemory.h"\r
17\r
18//\r
19// Global Descriptor Table (GDT)\r
20//\r
b98da1b1 21GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries[] = {\r
0cf27ce0 22/* selector { Global Segment Descriptor } */\r
23/* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor\r
95276127 24/* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor\r
25/* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor\r
26/* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor\r
27/* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor\r
28/* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor\r
29/* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor\r
30/* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor\r
31/* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor\r
32};\r
33\r
34//\r
35// IA32 Gdt register\r
36//\r
37GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {\r
38 sizeof (gGdtEntries) - 1,\r
39 (UINTN) gGdtEntries\r
40 };\r
41\r
5d582956 42GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {\r
43 sizeof (X64_IDT_GATE_DESCRIPTOR) * 32 - 1,\r
44 0\r
45};\r
46\r
91d92e25 47/**\r
48 Transfers control to DxeCore.\r
49\r
50 This function performs a CPU architecture specific operations to execute\r
51 the entry point of DxeCore with the parameters of HobList.\r
48557c65 52 It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.\r
91d92e25 53\r
48557c65 54 @param DxeCoreEntryPoint The entry point of DxeCore.\r
91d92e25 55 @param HobList The start of HobList passed to DxeCore.\r
91d92e25 56\r
57**/\r
95276127 58VOID\r
59HandOffToDxeCore (\r
60 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,\r
9b937a73 61 IN EFI_PEI_HOB_POINTERS HobList\r
95276127 62 )\r
63{\r
64 EFI_STATUS Status;\r
65 EFI_PHYSICAL_ADDRESS BaseOfStack;\r
66 EFI_PHYSICAL_ADDRESS TopOfStack;\r
67 UINTN PageTables;\r
5d582956 68 X64_IDT_GATE_DESCRIPTOR *IdtTable;\r
69 UINTN SizeOfTemplate;\r
70 VOID *TemplateBase;\r
71 EFI_PHYSICAL_ADDRESS VectorAddress;\r
72 UINT32 Index;\r
95276127 73\r
74 Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
75 ASSERT_EFI_ERROR (Status);\r
0cf27ce0 76\r
95276127 77 if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {\r
78 //\r
0cf27ce0 79 // Compute the top of the stack we were allocated, which is used to load X64 dxe core.\r
95276127 80 // Pre-allocate a 32 bytes which confroms to x64 calling convention.\r
81 //\r
0cf27ce0 82 // The first four parameters to a function are passed in rcx, rdx, r8 and r9.\r
83 // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the\r
84 // register parameters is reserved on the stack, in case the called function\r
85 // wants to spill them; this is important if the function is variadic.\r
95276127 86 //\r
87 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;\r
88\r
89 //\r
b98da1b1 90 // x64 Calling Conventions requires that the stack must be aligned to 16 bytes\r
95276127 91 //\r
92 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);\r
93\r
94 //\r
95 // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA\r
0cf27ce0 96 // memory, it may be corrupted when copying FV to high-end memory\r
95276127 97 //\r
98 AsmWriteGdtr (&gGdt);\r
99 //\r
100 // Create page table and save PageMapLevel4 to CR3\r
101 //\r
102 PageTables = CreateIdentityMappingPageTables ();\r
103\r
104 //\r
48557c65 105 // End of PEI phase signal\r
95276127 106 //\r
9b937a73 107 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);\r
95276127 108 ASSERT_EFI_ERROR (Status);\r
0cf27ce0 109\r
95276127 110 AsmWriteCr3 (PageTables);\r
5d582956 111\r
30c8f861 112 //\r
113 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
0cf27ce0 114 //\r
30c8f861 115 UpdateStackHob (BaseOfStack, STACK_SIZE);\r
5d582956 116\r
4bfa7dc4 117 SizeOfTemplate = AsmGetVectorTemplatInfo (&TemplateBase);\r
118\r
119 Status = PeiServicesAllocatePages (\r
0cf27ce0 120 EfiBootServicesData,\r
121 EFI_SIZE_TO_PAGES((SizeOfTemplate + sizeof (X64_IDT_GATE_DESCRIPTOR)) * 32),\r
4bfa7dc4 122 &VectorAddress\r
123 );\r
124 ASSERT_EFI_ERROR (Status);\r
125\r
126 IdtTable = (X64_IDT_GATE_DESCRIPTOR *) (UINTN) (VectorAddress + SizeOfTemplate * 32);\r
127 for (Index = 0; Index < 32; Index++) {\r
128 IdtTable[Index].Ia32IdtEntry.Bits.GateType = 0x8e;\r
129 IdtTable[Index].Ia32IdtEntry.Bits.Reserved_0 = 0;\r
130 IdtTable[Index].Ia32IdtEntry.Bits.Selector = SYS_CODE64_SEL;\r
131\r
132 IdtTable[Index].Ia32IdtEntry.Bits.OffsetLow = (UINT16) VectorAddress;\r
133 IdtTable[Index].Ia32IdtEntry.Bits.OffsetHigh = (UINT16) (RShiftU64 (VectorAddress, 16));\r
134 IdtTable[Index].Offset32To63 = (UINT32) (RShiftU64 (VectorAddress, 32));\r
135 IdtTable[Index].Reserved = 0;\r
136\r
137 CopyMem ((VOID *) (UINTN) VectorAddress, TemplateBase, SizeOfTemplate);\r
138 AsmVectorFixup ((VOID *) (UINTN) VectorAddress, (UINT8) Index);\r
139\r
140 VectorAddress += SizeOfTemplate;\r
5d582956 141 }\r
4bfa7dc4 142\r
143 gLidtDescriptor.Base = (UINTN) IdtTable;\r
0cf27ce0 144\r
4bfa7dc4 145 AsmWriteIdtr (&gLidtDescriptor);\r
146\r
5d582956 147 //\r
b98da1b1 148 // Go to Long Mode and transfer control to DxeCore.\r
149 // Interrupts will not get turned on until the CPU AP is loaded.\r
95276127 150 // Call x64 drivers passing in single argument, a pointer to the HOBs.\r
0cf27ce0 151 //\r
95276127 152 AsmEnablePaging64 (\r
153 SYS_CODE64_SEL,\r
154 DxeCoreEntryPoint,\r
155 (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw),\r
156 0,\r
157 TopOfStack\r
158 );\r
159 } else {\r
160 //\r
161 // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
162 // for safety.\r
163 //\r
164 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;\r
165 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
166\r
167 //\r
48557c65 168 // End of PEI phase signal\r
95276127 169 //\r
9b937a73 170 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);\r
95276127 171 ASSERT_EFI_ERROR (Status);\r
172\r
30c8f861 173 //\r
174 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
0cf27ce0 175 //\r
30c8f861 176 UpdateStackHob (BaseOfStack, STACK_SIZE);\r
0cf27ce0 177\r
b98da1b1 178 //\r
179 // Transfer the control to the entry point of DxeCore.\r
180 //\r
95276127 181 SwitchStack (\r
182 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
183 HobList.Raw,\r
184 NULL,\r
185 (VOID *) (UINTN) TopOfStack\r
186 );\r
0cf27ce0 187 }\r
95276127 188}\r
189\r