]>
Commit | Line | Data |
---|---|---|
18b84857 | 1 | /** @file\r |
ca162103 | 2 | \r |
3 | Copyright (c) 2006 - 2007, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | DxeInit.c\r | |
14 | \r | |
15 | Abstract:\r | |
16 | \r | |
17 | Revision 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 | |
32 | 0x0\r | |
33 | IVT\r | |
34 | 0x400\r | |
35 | BDA\r | |
36 | 0x500\r | |
37 | \r | |
38 | 0x7C00\r | |
39 | BootSector\r | |
40 | 0x10000\r | |
41 | EfiLdr (relocate by efiXX.COM)\r | |
42 | 0x15000\r | |
43 | Efivar.bin (Load by StartXX.COM)\r | |
44 | 0x20000\r | |
45 | StartXX.COM (E820 table, Temporary GDT, Temporary IDT)\r | |
46 | 0x21000\r | |
47 | EfiXX.COM (Temporary Interrupt Handler)\r | |
48 | 0x22000\r | |
49 | EfiLdr.efi + DxeIpl.Z + DxeMain.Z + BFV.Z\r | |
50 | 0x86000\r | |
51 | MemoryFreeUnder1M (For legacy driver DMA)\r | |
52 | 0x90000\r | |
53 | Temporary 4G PageTable for X64 (6 page)\r | |
54 | 0x9F800\r | |
55 | EBDA\r | |
56 | 0xA0000\r | |
57 | VGA\r | |
58 | 0xC0000\r | |
59 | OPROM\r | |
60 | 0xE0000\r | |
61 | FIRMEWARE\r | |
62 | 0x100000 (1M)\r | |
63 | Temporary Stack (1M)\r | |
64 | 0x200000\r | |
65 | \r | |
66 | MemoryAbove1MB.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 | |
96 | 0x100000000 (4G)\r | |
97 | \r | |
98 | MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+\r | |
99 | |\r | |
100 | |\r | |
101 | MemoryFreeAbove4GB.ResourceLength\r | |
102 | |\r | |
103 | |\r | |
104 | <--------------------------------------------------+\r | |
105 | */\r | |
106 | \r | |
107 | VOID\r | |
108 | EnterDxeMain (\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 | |
115 | VOID\r | |
116 | DxeInit (\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 | |
125 | Arguments:\r | |
126 | \r | |
127 | \r | |
128 | Returns:\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 | |
eb16e240 | 140 | CHAR8 PrintBuffer[256];\r |
df166ce5 | 141 | \r |
142 | ClearScreen();\r | |
ff514e29 | 143 | PrintString("Enter DxeIpl ...\n");\r |
e25803f0 | 144 | \r |
ca162103 | 145 | /*\r |
146 | ClearScreen();\r | |
147 | PrintString("handoff:\n");\r | |
148 | PrintString("Handoff.BfvBase = "); \r | |
149 | PrintValue64((UINT64)(UINTN)Handoff->BfvBase);\r | |
150 | PrintString(", "); \r | |
151 | PrintString("BfvLength = "); \r | |
152 | PrintValue64(Handoff->BfvSize);\r | |
153 | PrintString("\n"); \r | |
154 | PrintString("Handoff.DxeIplImageBase = "); \r | |
155 | PrintValue64((UINT64)(UINTN)Handoff->DxeIplImageBase);\r | |
156 | PrintString(", "); \r | |
157 | PrintString("DxeIplImageSize = "); \r | |
158 | PrintValue64(Handoff->DxeIplImageSize);\r | |
159 | PrintString("\n"); \r | |
160 | PrintString("Handoff.DxeCoreImageBase = "); \r | |
161 | PrintValue64((UINT64)(UINTN)Handoff->DxeCoreImageBase);\r | |
162 | PrintString(", "); \r | |
163 | PrintString("DxeCoreImageSize = "); \r | |
164 | PrintValue64(Handoff->DxeCoreImageSize);\r | |
165 | PrintString("\n"); \r | |
166 | */\r | |
167 | //\r | |
168 | // Hob Generation Guild line:\r | |
169 | // * Don't report FV as physical memory\r | |
170 | // * MemoryAllocation Hob should only cover physical memory\r | |
171 | // * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped\r | |
e25803f0 | 172 | PrintString("Prepare Cpu HOB information ...\n");\r |
ca162103 | 173 | PrepareHobCpu ();\r |
e25803f0 | 174 | \r |
ca162103 | 175 | //\r |
176 | // 1. BFV\r | |
177 | //\r | |
e25803f0 | 178 | PrintString("Prepare BFV HOB information ...\n");\r |
ca162103 | 179 | PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);\r |
180 | \r | |
181 | //\r | |
182 | // 2. Updates Memory information, and get the top free address under 4GB\r | |
183 | //\r | |
e25803f0 | 184 | PrintString("Prepare Memory HOB information ...\n");\r |
ca162103 | 185 | MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);\r |
e25803f0 | 186 | \r |
ca162103 | 187 | //\r |
188 | // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]\r | |
189 | //\r | |
190 | \r | |
191 | // 3.1 NV data\r | |
e25803f0 | 192 | PrintString("Prepare NV Storage information ...\n");\r |
ca162103 | 193 | NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);\r |
eb16e240 | 194 | AsciiSPrint (PrintBuffer, 256, "NV Storage Base=0x%x\n", (UINTN)NvStorageBase);\r |
195 | PrintString (PrintBuffer);\r | |
e25803f0 | 196 | \r |
ca162103 | 197 | // 3.2 Stack\r |
198 | StackTop = NvStorageBase;\r | |
199 | StackBottom = PrepareHobStack (StackTop);\r | |
eb16e240 | 200 | AsciiSPrint (PrintBuffer, 256, "Stack Top=0x%x, Stack Bottom=0x%x\n", \r |
201 | (UINTN)StackTop, (UINTN)StackBottom);\r | |
202 | PrintString (PrintBuffer);\r | |
ca162103 | 203 | // 3.3 Page Table\r |
204 | PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);\r | |
205 | // 3.4 MemDesc (will be used in PlatformBds)\r | |
206 | MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);\r | |
207 | // 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob\r | |
208 | PrepareHobPhit (StackTop, MemoryDescriptor);\r | |
209 | \r | |
210 | //\r | |
211 | // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore\r | |
212 | //\r | |
e25803f0 | 213 | PrintString("Prepare DxeCore memory Hob ...\n");\r |
ca162103 | 214 | PrepareHobDxeCore (\r |
215 | Handoff->DxeCoreEntryPoint,\r | |
216 | (EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,\r | |
217 | (UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase\r | |
218 | );\r | |
219 | \r | |
220 | PrepareHobLegacyTable (gHob);\r | |
e25803f0 | 221 | \r |
ca162103 | 222 | PreparePpisNeededByDxeCore (gHob);\r |
223 | \r | |
224 | CompleteHobGeneration ();\r | |
225 | \r | |
eb16e240 | 226 | AsciiSPrint (PrintBuffer, 256, "HobStart=0x%x\n", (UINTN)gHob);\r |
227 | PrintString (PrintBuffer);\r | |
228 | \r | |
229 | AsciiSPrint (PrintBuffer, 256, "Memory Top=0x%x, Bottom=0x%x\n", \r | |
230 | (UINTN)gHob->Phit.EfiMemoryTop, (UINTN)gHob->Phit.EfiMemoryBottom);\r | |
231 | PrintString (PrintBuffer);\r | |
232 | \r | |
233 | AsciiSPrint (PrintBuffer, 256, "Free Memory Top=0x%x, Bottom=0x%x\n", \r | |
234 | (UINTN)gHob->Phit.EfiFreeMemoryTop, (UINTN)gHob->Phit.EfiFreeMemoryBottom);\r | |
235 | PrintString (PrintBuffer);\r | |
236 | \r | |
237 | AsciiSPrint (PrintBuffer, 256, "Nv Base=0x%x, Length=0x%x\n", \r | |
238 | (UINTN)gHob->NvStorageFvb.FvbInfo.Entries[0].Base, \r | |
239 | (UINTN)gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r | |
240 | PrintString (PrintBuffer);\r | |
ca162103 | 241 | /*\r |
242 | //\r | |
243 | // Print Hob Info\r | |
244 | //\r | |
245 | ClearScreen();\r | |
246 | PrintString("Hob Info\n");\r | |
247 | PrintString("Phit.EfiMemoryTop = "); \r | |
248 | PrintValue64(gHob->Phit.EfiMemoryTop);\r | |
249 | PrintString(" Phit.EfiMemoryBottom = "); \r | |
250 | PrintValue64(gHob->Phit.EfiMemoryBottom);\r | |
251 | PrintString("\n"); \r | |
252 | PrintString("Phit.EfiFreeMemoryTop = "); \r | |
253 | PrintValue64(gHob->Phit.EfiFreeMemoryTop);\r | |
254 | PrintString(" Phit.EfiFreeMemoryBottom = "); \r | |
255 | PrintValue64(gHob->Phit.EfiFreeMemoryBottom);\r | |
256 | PrintString("\n"); \r | |
257 | PrintString("Bfv = "); \r | |
258 | PrintValue64(gHob->Bfv.BaseAddress);\r | |
259 | PrintString(" BfvLength = "); \r | |
260 | PrintValue64(gHob->Bfv.Length);\r | |
261 | PrintString("\n");\r | |
262 | PrintString("NvStorageFvb = ");\r | |
263 | PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Base);\r | |
264 | PrintString(" Length = ");\r | |
265 | PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Length);\r | |
266 | PrintString("\n");\r | |
267 | PrintString("NvFtwFvb = ");\r | |
268 | PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Base);\r | |
269 | PrintString(" Length = ");\r | |
270 | PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r | |
271 | PrintString("\n");\r | |
d569cbb0 | 272 | PrintString("BfvResource = ");\r |
273 | PrintValue64(gHob->BfvResource.PhysicalStart);\r | |
274 | PrintString(" Length = ");\r | |
275 | PrintValue64(gHob->BfvResource.ResourceLength);\r | |
276 | PrintString("\n");\r | |
277 | PrintString("NvStorageFvResource = ");\r | |
278 | PrintValue64(gHob->NvStorageFvResource.PhysicalStart);\r | |
279 | PrintString(" Length = ");\r | |
280 | PrintValue64(gHob->NvStorageFvResource.ResourceLength);\r | |
281 | PrintString("\n");\r | |
282 | PrintString("NvStorage = ");\r | |
283 | PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Base);\r | |
284 | PrintString(" Length = ");\r | |
285 | PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Length);\r | |
286 | PrintString("\n");\r | |
287 | PrintString("NvFtwFvResource = ");\r | |
288 | PrintValue64(gHob->NvFtwFvResource.PhysicalStart);\r | |
289 | PrintString(" Length = ");\r | |
290 | PrintValue64(gHob->NvFtwFvResource.ResourceLength);\r | |
291 | PrintString("\n");\r | |
292 | PrintString("NvFtwWorking = ");\r | |
293 | PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Base);\r | |
294 | PrintString(" Length = ");\r | |
295 | PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Length);\r | |
296 | PrintString("\n");\r | |
297 | PrintString("NvFtwSpare = ");\r | |
298 | PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Base);\r | |
299 | PrintString(" Length = ");\r | |
300 | PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Length);\r | |
301 | PrintString("\n");\r | |
ca162103 | 302 | PrintString("Stack = "); \r |
303 | PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);\r | |
304 | PrintString(" StackLength = "); \r | |
305 | PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);\r | |
306 | PrintString("\n"); \r | |
d569cbb0 | 307 | PrintString("PageTable = "); \r |
308 | PrintValue64((UINTN)PageTableBase);\r | |
309 | PrintString("\n"); \r | |
ca162103 | 310 | PrintString("MemoryFreeUnder1MB = "); \r |
311 | PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);\r | |
312 | PrintString(" MemoryFreeUnder1MBLength = "); \r | |
313 | PrintValue64(gHob->MemoryFreeUnder1MB.ResourceLength);\r | |
314 | PrintString("\n"); \r | |
315 | PrintString("MemoryAbove1MB = "); \r | |
316 | PrintValue64(gHob->MemoryAbove1MB.PhysicalStart);\r | |
317 | PrintString(" MemoryAbove1MBLength = "); \r | |
318 | PrintValue64(gHob->MemoryAbove1MB.ResourceLength);\r | |
319 | PrintString("\n"); \r | |
320 | PrintString("MemoryAbove4GB = "); \r | |
321 | PrintValue64(gHob->MemoryAbove4GB.PhysicalStart);\r | |
322 | PrintString(" MemoryAbove4GBLength = "); \r | |
323 | PrintValue64(gHob->MemoryAbove4GB.ResourceLength);\r | |
324 | PrintString("\n"); \r | |
325 | PrintString("DxeCore = "); \r | |
326 | PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress);\r | |
327 | PrintString(" DxeCoreLength = "); \r | |
328 | PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryLength);\r | |
329 | PrintString("\n"); \r | |
330 | PrintString("MemoryAllocation = "); \r | |
331 | PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress);\r | |
332 | PrintString(" MemoryLength = "); \r | |
333 | PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryLength);\r | |
334 | PrintString("\n"); \r | |
335 | EFI_DEADLOOP();\r | |
336 | */\r | |
a4f31daf | 337 | \r |
ca162103 | 338 | ClearScreen();\r |
339 | PrintString("\n\n\n\n\n\n\n\n\n\n");\r | |
340 | PrintString(" WELCOME TO EFI WORLD!\n");\r | |
e25803f0 | 341 | \r |
ca162103 | 342 | EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);\r |
9008db4a | 343 | \r |
e25803f0 | 344 | PrintString("Fail to enter DXE main!\n");\r |
ca162103 | 345 | //\r |
346 | // Should never get here\r | |
347 | //\r | |
348 | CpuDeadLoop ();\r | |
349 | }\r | |
350 | \r | |
df166ce5 | 351 | EFI_STATUS\r |
352 | EFIAPI\r | |
353 | _ModuleEntryPoint (\r | |
354 | IN EFILDRHANDOFF *Handoff\r | |
355 | )\r | |
356 | {\r | |
357 | DxeInit(Handoff);\r | |
358 | return EFI_SUCCESS;\r | |
359 | }\r |