]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/DxeIpl/DxeInit.c
Clean up DataHubGenDxe:
[mirror_edk2.git] / DuetPkg / DxeIpl / DxeInit.c
CommitLineData
18b84857 1/** @file\r
ca162103 2\r
3Copyright (c) 2006 - 2007, 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
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
81 DxeCore |\r
82 DxeCore\r
83 DxeIpl |\r
84 <----------------------------------------------------------+\r
85 NvFV + FtwFV |\r
86 MMIO\r
87 BFV |\r
88 <- Top of Free Memory reported by E820 --------------------+\r
89 ACPINVS or\r
90 ACPIReclaim or\r
91 Reserved\r
92 <- Memory Top on RealMemory\r
93\r
940x100000000 (4G)\r
95\r
96MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+\r
97 |\r
98 |\r
99 MemoryFreeAbove4GB.ResourceLength\r
100 |\r
101 |\r
102 <--------------------------------------------------+\r
103*/\r
104\r
105VOID\r
106EnterDxeMain (\r
107 IN VOID *StackTop,\r
108 IN VOID *DxeCoreEntryPoint,\r
109 IN VOID *Hob,\r
110 IN VOID *PageTable\r
111 );\r
112\r
113VOID\r
114DxeInit (\r
115 IN EFILDRHANDOFF *Handoff\r
116 )\r
117/*++\r
118\r
119 Routine Description:\r
120\r
121 This is the entry point after this code has been loaded into memory. \r
122\r
123Arguments:\r
124\r
125\r
126Returns:\r
127\r
128 Calls into EFI Firmware\r
129\r
130--*/\r
131{\r
132 VOID *StackTop;\r
133 VOID *StackBottom;\r
134 VOID *PageTableBase;\r
135 VOID *MemoryTopOnDescriptor;\r
136 VOID *MemoryDescriptor;\r
137 VOID *NvStorageBase;\r
eb16e240 138 CHAR8 PrintBuffer[256];\r
df166ce5 139 \r
140 ClearScreen();\r
ff514e29 141 PrintString("Enter DxeIpl ...\n");\r
e25803f0 142 \r
ca162103 143/*\r
144 ClearScreen();\r
145 PrintString("handoff:\n");\r
146 PrintString("Handoff.BfvBase = "); \r
147 PrintValue64((UINT64)(UINTN)Handoff->BfvBase);\r
148 PrintString(", "); \r
149 PrintString("BfvLength = "); \r
150 PrintValue64(Handoff->BfvSize);\r
151 PrintString("\n"); \r
152 PrintString("Handoff.DxeIplImageBase = "); \r
153 PrintValue64((UINT64)(UINTN)Handoff->DxeIplImageBase);\r
154 PrintString(", "); \r
155 PrintString("DxeIplImageSize = "); \r
156 PrintValue64(Handoff->DxeIplImageSize);\r
157 PrintString("\n"); \r
158 PrintString("Handoff.DxeCoreImageBase = "); \r
159 PrintValue64((UINT64)(UINTN)Handoff->DxeCoreImageBase);\r
160 PrintString(", "); \r
161 PrintString("DxeCoreImageSize = "); \r
162 PrintValue64(Handoff->DxeCoreImageSize);\r
163 PrintString("\n"); \r
164*/\r
165 //\r
166 // Hob Generation Guild line:\r
167 // * Don't report FV as physical memory\r
168 // * MemoryAllocation Hob should only cover physical memory\r
169 // * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped\r
e25803f0 170 PrintString("Prepare Cpu HOB information ...\n");\r
ca162103 171 PrepareHobCpu ();\r
e25803f0 172\r
ca162103 173 //\r
174 // 1. BFV\r
175 //\r
e25803f0 176 PrintString("Prepare BFV HOB information ...\n");\r
ca162103 177 PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);\r
178\r
179 //\r
180 // 2. Updates Memory information, and get the top free address under 4GB\r
181 //\r
e25803f0 182 PrintString("Prepare Memory HOB information ...\n");\r
ca162103 183 MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);\r
e25803f0 184 \r
ca162103 185 //\r
186 // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]\r
187 //\r
188 \r
189 // 3.1 NV data\r
e25803f0 190 PrintString("Prepare NV Storage information ...\n");\r
ca162103 191 NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);\r
eb16e240 192 AsciiSPrint (PrintBuffer, 256, "NV Storage Base=0x%x\n", (UINTN)NvStorageBase);\r
193 PrintString (PrintBuffer);\r
e25803f0 194 \r
ca162103 195 // 3.2 Stack\r
196 StackTop = NvStorageBase;\r
197 StackBottom = PrepareHobStack (StackTop);\r
eb16e240 198 AsciiSPrint (PrintBuffer, 256, "Stack Top=0x%x, Stack Bottom=0x%x\n", \r
199 (UINTN)StackTop, (UINTN)StackBottom);\r
200 PrintString (PrintBuffer);\r
ca162103 201 // 3.3 Page Table\r
202 PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);\r
203 // 3.4 MemDesc (will be used in PlatformBds)\r
204 MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);\r
205 // 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob\r
206 PrepareHobPhit (StackTop, MemoryDescriptor);\r
207\r
208 //\r
209 // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore\r
210 //\r
e25803f0 211 PrintString("Prepare DxeCore memory Hob ...\n");\r
ca162103 212 PrepareHobDxeCore (\r
213 Handoff->DxeCoreEntryPoint,\r
214 (EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,\r
215 (UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase\r
216 );\r
217\r
218 PrepareHobLegacyTable (gHob);\r
e25803f0 219 \r
ca162103 220 PreparePpisNeededByDxeCore (gHob);\r
221\r
222 CompleteHobGeneration ();\r
223\r
eb16e240 224 AsciiSPrint (PrintBuffer, 256, "HobStart=0x%x\n", (UINTN)gHob);\r
225 PrintString (PrintBuffer);\r
226\r
227 AsciiSPrint (PrintBuffer, 256, "Memory Top=0x%x, Bottom=0x%x\n", \r
228 (UINTN)gHob->Phit.EfiMemoryTop, (UINTN)gHob->Phit.EfiMemoryBottom);\r
229 PrintString (PrintBuffer);\r
230\r
231 AsciiSPrint (PrintBuffer, 256, "Free Memory Top=0x%x, Bottom=0x%x\n", \r
232 (UINTN)gHob->Phit.EfiFreeMemoryTop, (UINTN)gHob->Phit.EfiFreeMemoryBottom);\r
233 PrintString (PrintBuffer);\r
234\r
235 AsciiSPrint (PrintBuffer, 256, "Nv Base=0x%x, Length=0x%x\n", \r
236 (UINTN)gHob->NvStorageFvb.FvbInfo.Entries[0].Base, \r
237 (UINTN)gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r
238 PrintString (PrintBuffer);\r
ca162103 239/*\r
240 //\r
241 // Print Hob Info\r
242 //\r
243 ClearScreen();\r
244 PrintString("Hob Info\n");\r
245 PrintString("Phit.EfiMemoryTop = "); \r
246 PrintValue64(gHob->Phit.EfiMemoryTop);\r
247 PrintString(" Phit.EfiMemoryBottom = "); \r
248 PrintValue64(gHob->Phit.EfiMemoryBottom);\r
249 PrintString("\n"); \r
250 PrintString("Phit.EfiFreeMemoryTop = "); \r
251 PrintValue64(gHob->Phit.EfiFreeMemoryTop);\r
252 PrintString(" Phit.EfiFreeMemoryBottom = "); \r
253 PrintValue64(gHob->Phit.EfiFreeMemoryBottom);\r
254 PrintString("\n"); \r
255 PrintString("Bfv = "); \r
256 PrintValue64(gHob->Bfv.BaseAddress);\r
257 PrintString(" BfvLength = "); \r
258 PrintValue64(gHob->Bfv.Length);\r
259 PrintString("\n");\r
260 PrintString("NvStorageFvb = ");\r
261 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Base);\r
262 PrintString(" Length = ");\r
263 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Length);\r
264 PrintString("\n");\r
265 PrintString("NvFtwFvb = ");\r
266 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Base);\r
267 PrintString(" Length = ");\r
268 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r
269 PrintString("\n");\r
270 PrintString("Stack = "); \r
271 PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);\r
272 PrintString(" StackLength = "); \r
273 PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);\r
274 PrintString("\n"); \r
275 PrintString("MemoryFreeUnder1MB = "); \r
276 PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);\r
277 PrintString(" MemoryFreeUnder1MBLength = "); \r
278 PrintValue64(gHob->MemoryFreeUnder1MB.ResourceLength);\r
279 PrintString("\n"); \r
280 PrintString("MemoryAbove1MB = "); \r
281 PrintValue64(gHob->MemoryAbove1MB.PhysicalStart);\r
282 PrintString(" MemoryAbove1MBLength = "); \r
283 PrintValue64(gHob->MemoryAbove1MB.ResourceLength);\r
284 PrintString("\n"); \r
285 PrintString("MemoryAbove4GB = "); \r
286 PrintValue64(gHob->MemoryAbove4GB.PhysicalStart);\r
287 PrintString(" MemoryAbove4GBLength = "); \r
288 PrintValue64(gHob->MemoryAbove4GB.ResourceLength);\r
289 PrintString("\n"); \r
290 PrintString("DxeCore = "); \r
291 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress);\r
292 PrintString(" DxeCoreLength = "); \r
293 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryLength);\r
294 PrintString("\n"); \r
295 PrintString("MemoryAllocation = "); \r
296 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress);\r
297 PrintString(" MemoryLength = "); \r
298 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryLength);\r
299 PrintString("\n"); \r
300 EFI_DEADLOOP();\r
301*/\r
a4f31daf 302\r
ca162103 303 ClearScreen();\r
304 PrintString("\n\n\n\n\n\n\n\n\n\n");\r
305 PrintString(" WELCOME TO EFI WORLD!\n");\r
e25803f0 306 \r
ca162103 307 EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);\r
e25803f0 308 \r
309 PrintString("Fail to enter DXE main!\n");\r
ca162103 310 //\r
311 // Should never get here\r
312 //\r
313 CpuDeadLoop ();\r
314}\r
315\r
df166ce5 316EFI_STATUS\r
317EFIAPI\r
318_ModuleEntryPoint (\r
319 IN EFILDRHANDOFF *Handoff\r
320 )\r
321{\r
322 DxeInit(Handoff);\r
323 return EFI_SUCCESS;\r
324}\r