]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/DxeIpl/DxeInit.c
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmbase" with PatchInstructionX86()
[mirror_edk2.git] / DuetPkg / DxeIpl / DxeInit.c
CommitLineData
18b84857 1/** @file\r
ca162103 2\r
b68b78e6 3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
b1f700a8 4This program and the accompanying materials \r
ca162103 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
11\r
12Module Name:\r
13 DxeInit.c\r
14\r
15Abstract:\r
16\r
17Revision History:\r
18\r
18b84857 19**/\r
ca162103 20\r
21#include "DxeIpl.h"\r
22\r
23#include "LegacyTable.h"\r
24#include "HobGeneration.h"\r
25#include "PpisNeededByDxeCore.h"\r
26#include "Debug.h"\r
27\r
28/*\r
29--------------------------------------------------------\r
30 Memory Map: (XX=32,64)\r
31--------------------------------------------------------\r
320x0\r
33 IVT\r
340x400\r
35 BDA\r
360x500\r
37\r
380x7C00\r
39 BootSector\r
400x10000\r
41 EfiLdr (relocate by efiXX.COM)\r
420x15000\r
43 Efivar.bin (Load by StartXX.COM)\r
440x20000\r
45 StartXX.COM (E820 table, Temporary GDT, Temporary IDT)\r
460x21000\r
47 EfiXX.COM (Temporary Interrupt Handler)\r
480x22000\r
49 EfiLdr.efi + DxeIpl.Z + DxeMain.Z + BFV.Z\r
500x86000\r
51 MemoryFreeUnder1M (For legacy driver DMA)\r
520x90000\r
53 Temporary 4G PageTable for X64 (6 page)\r
540x9F800\r
55 EBDA\r
560xA0000\r
57 VGA\r
580xC0000\r
59 OPROM\r
600xE0000\r
61 FIRMEWARE\r
620x100000 (1M)\r
63 Temporary Stack (1M)\r
640x200000\r
65\r
66MemoryAbove1MB.PhysicalStart <-----------------------------------------------------+\r
67 ... |\r
68 ... |\r
69 <- Phit.EfiMemoryBottom -------------------+ |\r
70 HOB | |\r
71 <- Phit.EfiFreeMemoryBottom | |\r
72 | MemoryFreeAbove1MB.ResourceLength\r
73 <- Phit.EfiFreeMemoryTop ------+ | |\r
74 MemoryDescriptor (For ACPINVS, ACPIReclaim) | 4M = CONSUMED_MEMORY |\r
75 | | |\r
76 Permament 4G PageTable for IA32 or MemoryAllocation | |\r
77 Permament 64G PageTable for X64 | | |\r
78 <------------------------------+ | |\r
79 Permament Stack (0x20 Pages = 128K) | |\r
80 <- Phit.EfiMemoryTop ----------+-----------+---------------+\r
d569cbb0 81 NvFV (64K) |\r
ca162103 82 MMIO\r
d569cbb0 83 FtwFV (128K) | \r
84 <----------------------------------------------------------+<---------+\r
85 DxeCore | |\r
86 DxeCore |\r
87 DxeIpl | Allocated in EfiLdr\r
88 <----------------------------------------------------------+ |\r
89 BFV MMIO |\r
90 <- Top of Free Memory reported by E820 --------------------+<---------+\r
ca162103 91 ACPINVS or\r
92 ACPIReclaim or\r
93 Reserved\r
94 <- Memory Top on RealMemory\r
95\r
960x100000000 (4G)\r
97\r
98MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+\r
99 |\r
100 |\r
101 MemoryFreeAbove4GB.ResourceLength\r
102 |\r
103 |\r
104 <--------------------------------------------------+\r
105*/\r
106\r
107VOID\r
108EnterDxeMain (\r
109 IN VOID *StackTop,\r
110 IN VOID *DxeCoreEntryPoint,\r
111 IN VOID *Hob,\r
112 IN VOID *PageTable\r
113 );\r
114\r
115VOID\r
116DxeInit (\r
117 IN EFILDRHANDOFF *Handoff\r
118 )\r
119/*++\r
120\r
121 Routine Description:\r
122\r
123 This is the entry point after this code has been loaded into memory. \r
124\r
125Arguments:\r
126\r
127\r
128Returns:\r
129\r
130 Calls into EFI Firmware\r
131\r
132--*/\r
133{\r
134 VOID *StackTop;\r
135 VOID *StackBottom;\r
136 VOID *PageTableBase;\r
137 VOID *MemoryTopOnDescriptor;\r
138 VOID *MemoryDescriptor;\r
139 VOID *NvStorageBase;\r
dcb428da 140 EFILDRHANDOFF HandoffCopy;\r
141\r
142 CopyMem ((VOID*) &HandoffCopy, (VOID*) Handoff, sizeof (EFILDRHANDOFF));\r
143 Handoff = &HandoffCopy;\r
144\r
df166ce5 145 ClearScreen();\r
b68b78e6
RN
146\r
147 PrintString (\r
148 "Enter DxeIpl ...\n"\r
149 "Handoff:\n"\r
150 "Handoff.BfvBase = %p, BfvLength = %x\n"\r
151 "Handoff.DxeIplImageBase = %p, DxeIplImageSize = %x\n"\r
152 "Handoff.DxeCoreImageBase = %p, DxeCoreImageSize = %x\n",\r
153 Handoff->BfvBase, Handoff->BfvSize,\r
154 Handoff->DxeIplImageBase, Handoff->DxeIplImageSize,\r
155 Handoff->DxeCoreImageBase, Handoff->DxeCoreImageSize\r
156 );\r
157\r
ca162103 158 //\r
159 // Hob Generation Guild line:\r
160 // * Don't report FV as physical memory\r
161 // * MemoryAllocation Hob should only cover physical memory\r
162 // * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped\r
b68b78e6 163 PrintString ("Prepare Cpu HOB information ...\n");\r
ca162103 164 PrepareHobCpu ();\r
e25803f0 165\r
ca162103 166 //\r
167 // 1. BFV\r
168 //\r
b68b78e6 169 PrintString ("Prepare BFV HOB information ...\n");\r
ca162103 170 PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);\r
171\r
172 //\r
173 // 2. Updates Memory information, and get the top free address under 4GB\r
174 //\r
b68b78e6 175 PrintString ("Prepare Memory HOB information ...\n");\r
ca162103 176 MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);\r
e25803f0 177 \r
ca162103 178 //\r
179 // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]\r
180 //\r
181 \r
182 // 3.1 NV data\r
b68b78e6 183 PrintString ("Prepare NV Storage information ...\n");\r
ca162103 184 NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);\r
b68b78e6 185 PrintString ("NV Storage Base = %p\n", NvStorageBase);\r
ca162103 186 // 3.2 Stack\r
187 StackTop = NvStorageBase;\r
188 StackBottom = PrepareHobStack (StackTop);\r
b68b78e6 189 PrintString ("Stack Top=0x%x, Stack Bottom=0x%x\n", StackTop, StackBottom);\r
ca162103 190 // 3.3 Page Table\r
191 PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);\r
192 // 3.4 MemDesc (will be used in PlatformBds)\r
193 MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);\r
194 // 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob\r
195 PrepareHobPhit (StackTop, MemoryDescriptor);\r
196\r
197 //\r
198 // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore\r
199 //\r
b68b78e6 200 PrintString ("Prepare DxeCore memory Hob ...\n");\r
ca162103 201 PrepareHobDxeCore (\r
202 Handoff->DxeCoreEntryPoint,\r
203 (EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,\r
204 (UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase\r
205 );\r
206\r
207 PrepareHobLegacyTable (gHob);\r
e25803f0 208 \r
ca162103 209 PreparePpisNeededByDxeCore (gHob);\r
210\r
211 CompleteHobGeneration ();\r
212\r
ca162103 213 //\r
214 // Print Hob Info\r
215 //\r
216 ClearScreen();\r
b68b78e6
RN
217 PrintString (\r
218 "HobStart = %p\n"\r
219 "Memory Top = %lx, Bottom = %lx\n"\r
220 "Free Memory Top = %lx, Bottom = %lx\n"\r
cec6685c 221 "NvStorageFvb = %lx, Length = %lx\n"\r
b68b78e6
RN
222 "BfvResource = %lx, Length = %lx\n"\r
223 "NvStorageFvResource = %lx, Length = %lx\n"\r
224 "NvStorage = %lx, Length = %lx\n"\r
225 "NvFtwFvResource = %lx, Length = %lx\n"\r
226 "NvFtwWorking = %lx, Length = %lx\n"\r
227 "NvFtwSpare = %lx, Length = %lx\n"\r
228 "Stack = %lx, StackLength = %lx\n"\r
229 "PageTable = %p\n"\r
230 "MemoryFreeUnder1MB = %lx, MemoryFreeUnder1MBLength = %lx\n"\r
231 "MemoryAbove1MB = %lx, MemoryAbove1MBLength = %lx\n"\r
232 "MemoryAbove4GB = %lx, MemoryAbove4GBLength = %lx\n"\r
233 "DxeCore = %lx, DxeCoreLength = %lx\n"\r
234 "MemoryAllocation = %lx, MemoryLength = %lx\n"\r
235 "$",\r
236 gHob,\r
237 gHob->Phit.EfiMemoryTop, gHob->Phit.EfiMemoryBottom,\r
238 gHob->Phit.EfiFreeMemoryTop, gHob->Phit.EfiFreeMemoryBottom,\r
cec6685c 239 gHob->NvStorageFvb.FvbInfo.Entries[0].Base, gHob->NvFtwFvb.FvbInfo.Entries[0].Length,\r
b68b78e6
RN
240 gHob->BfvResource.PhysicalStart, gHob->BfvResource.ResourceLength,\r
241 gHob->NvStorageFvResource.PhysicalStart, gHob->NvStorageFvResource.ResourceLength,\r
242 gHob->NvStorage.FvbInfo.Entries[0].Base, gHob->NvStorage.FvbInfo.Entries[0].Length,\r
243 gHob->NvFtwFvResource.PhysicalStart, gHob->NvFtwFvResource.ResourceLength,\r
244 gHob->NvFtwWorking.FvbInfo.Entries[0].Base, gHob->NvFtwWorking.FvbInfo.Entries[0].Length,\r
245 gHob->NvFtwSpare.FvbInfo.Entries[0].Base, gHob->NvFtwSpare.FvbInfo.Entries[0].Length,\r
246 gHob->Stack.AllocDescriptor.MemoryBaseAddress, gHob->Stack.AllocDescriptor.MemoryLength,\r
247 PageTableBase,\r
248 gHob->MemoryFreeUnder1MB.PhysicalStart, gHob->MemoryFreeUnder1MB.ResourceLength,\r
249 gHob->MemoryAbove1MB.PhysicalStart, gHob->MemoryAbove1MB.ResourceLength,\r
250 gHob->MemoryAbove4GB.PhysicalStart, gHob->MemoryAbove4GB.ResourceLength,\r
251 gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress, gHob->DxeCore.MemoryAllocationHeader.MemoryLength,\r
252 gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress, gHob->MemoryAllocation.AllocDescriptor.MemoryLength\r
253 );\r
a4f31daf 254\r
ca162103 255 ClearScreen();\r
b68b78e6
RN
256 PrintString (\r
257 "\n\n\n\n\n\n\n\n\n\n"\r
258 " WELCOME TO EFI WORLD!\n"\r
259 );\r
e25803f0 260 \r
ca162103 261 EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);\r
b68b78e6 262 PrintString ("Fail to enter DXE main!\n");\r
9008db4a 263 \r
ca162103 264 //\r
265 // Should never get here\r
266 //\r
267 CpuDeadLoop ();\r
268}\r
269\r
df166ce5 270EFI_STATUS\r
271EFIAPI\r
272_ModuleEntryPoint (\r
273 IN EFILDRHANDOFF *Handoff\r
274 )\r
275{\r
276 DxeInit(Handoff);\r
277 return EFI_SUCCESS;\r
278}\r