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