]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/DxeIpl/DxeInit.c
sync comments, fix function header, rename variable name to follow coding style.
[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
ca162103 142/*\r
143 ClearScreen();\r
144 PrintString("handoff:\n");\r
145 PrintString("Handoff.BfvBase = "); \r
146 PrintValue64((UINT64)(UINTN)Handoff->BfvBase);\r
147 PrintString(", "); \r
148 PrintString("BfvLength = "); \r
149 PrintValue64(Handoff->BfvSize);\r
150 PrintString("\n"); \r
151 PrintString("Handoff.DxeIplImageBase = "); \r
152 PrintValue64((UINT64)(UINTN)Handoff->DxeIplImageBase);\r
153 PrintString(", "); \r
154 PrintString("DxeIplImageSize = "); \r
155 PrintValue64(Handoff->DxeIplImageSize);\r
156 PrintString("\n"); \r
157 PrintString("Handoff.DxeCoreImageBase = "); \r
158 PrintValue64((UINT64)(UINTN)Handoff->DxeCoreImageBase);\r
159 PrintString(", "); \r
160 PrintString("DxeCoreImageSize = "); \r
161 PrintValue64(Handoff->DxeCoreImageSize);\r
162 PrintString("\n"); \r
163*/\r
164 //\r
165 // Hob Generation Guild line:\r
166 // * Don't report FV as physical memory\r
167 // * MemoryAllocation Hob should only cover physical memory\r
168 // * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped\r
169 \r
170 PrepareHobCpu ();\r
171 //\r
172 // 1. BFV\r
173 //\r
174 PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);\r
175\r
176 //\r
177 // 2. Updates Memory information, and get the top free address under 4GB\r
178 //\r
179 MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);\r
180\r
181 //\r
182 // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]\r
183 //\r
184 \r
185 // 3.1 NV data\r
186 NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);\r
eb16e240 187 AsciiSPrint (PrintBuffer, 256, "NV Storage Base=0x%x\n", (UINTN)NvStorageBase);\r
188 PrintString (PrintBuffer);\r
189\r
ca162103 190 // 3.2 Stack\r
191 StackTop = NvStorageBase;\r
192 StackBottom = PrepareHobStack (StackTop);\r
eb16e240 193 AsciiSPrint (PrintBuffer, 256, "Stack Top=0x%x, Stack Bottom=0x%x\n", \r
194 (UINTN)StackTop, (UINTN)StackBottom);\r
195 PrintString (PrintBuffer);\r
ca162103 196 // 3.3 Page Table\r
197 PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);\r
198 // 3.4 MemDesc (will be used in PlatformBds)\r
199 MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);\r
200 // 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob\r
201 PrepareHobPhit (StackTop, MemoryDescriptor);\r
202\r
203 //\r
204 // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore\r
205 //\r
206 PrepareHobDxeCore (\r
207 Handoff->DxeCoreEntryPoint,\r
208 (EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,\r
209 (UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase\r
210 );\r
211\r
212 PrepareHobLegacyTable (gHob);\r
213 PreparePpisNeededByDxeCore (gHob);\r
214\r
215 CompleteHobGeneration ();\r
216\r
eb16e240 217 AsciiSPrint (PrintBuffer, 256, "HobStart=0x%x\n", (UINTN)gHob);\r
218 PrintString (PrintBuffer);\r
219\r
220 AsciiSPrint (PrintBuffer, 256, "Memory Top=0x%x, Bottom=0x%x\n", \r
221 (UINTN)gHob->Phit.EfiMemoryTop, (UINTN)gHob->Phit.EfiMemoryBottom);\r
222 PrintString (PrintBuffer);\r
223\r
224 AsciiSPrint (PrintBuffer, 256, "Free Memory Top=0x%x, Bottom=0x%x\n", \r
225 (UINTN)gHob->Phit.EfiFreeMemoryTop, (UINTN)gHob->Phit.EfiFreeMemoryBottom);\r
226 PrintString (PrintBuffer);\r
227\r
228 AsciiSPrint (PrintBuffer, 256, "Nv Base=0x%x, Length=0x%x\n", \r
229 (UINTN)gHob->NvStorageFvb.FvbInfo.Entries[0].Base, \r
230 (UINTN)gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r
231 PrintString (PrintBuffer);\r
ca162103 232/*\r
233 //\r
234 // Print Hob Info\r
235 //\r
236 ClearScreen();\r
237 PrintString("Hob Info\n");\r
238 PrintString("Phit.EfiMemoryTop = "); \r
239 PrintValue64(gHob->Phit.EfiMemoryTop);\r
240 PrintString(" Phit.EfiMemoryBottom = "); \r
241 PrintValue64(gHob->Phit.EfiMemoryBottom);\r
242 PrintString("\n"); \r
243 PrintString("Phit.EfiFreeMemoryTop = "); \r
244 PrintValue64(gHob->Phit.EfiFreeMemoryTop);\r
245 PrintString(" Phit.EfiFreeMemoryBottom = "); \r
246 PrintValue64(gHob->Phit.EfiFreeMemoryBottom);\r
247 PrintString("\n"); \r
248 PrintString("Bfv = "); \r
249 PrintValue64(gHob->Bfv.BaseAddress);\r
250 PrintString(" BfvLength = "); \r
251 PrintValue64(gHob->Bfv.Length);\r
252 PrintString("\n");\r
253 PrintString("NvStorageFvb = ");\r
254 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Base);\r
255 PrintString(" Length = ");\r
256 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Length);\r
257 PrintString("\n");\r
258 PrintString("NvFtwFvb = ");\r
259 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Base);\r
260 PrintString(" Length = ");\r
261 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r
262 PrintString("\n");\r
263 PrintString("Stack = "); \r
264 PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);\r
265 PrintString(" StackLength = "); \r
266 PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);\r
267 PrintString("\n"); \r
268 PrintString("MemoryFreeUnder1MB = "); \r
269 PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);\r
270 PrintString(" MemoryFreeUnder1MBLength = "); \r
271 PrintValue64(gHob->MemoryFreeUnder1MB.ResourceLength);\r
272 PrintString("\n"); \r
273 PrintString("MemoryAbove1MB = "); \r
274 PrintValue64(gHob->MemoryAbove1MB.PhysicalStart);\r
275 PrintString(" MemoryAbove1MBLength = "); \r
276 PrintValue64(gHob->MemoryAbove1MB.ResourceLength);\r
277 PrintString("\n"); \r
278 PrintString("MemoryAbove4GB = "); \r
279 PrintValue64(gHob->MemoryAbove4GB.PhysicalStart);\r
280 PrintString(" MemoryAbove4GBLength = "); \r
281 PrintValue64(gHob->MemoryAbove4GB.ResourceLength);\r
282 PrintString("\n"); \r
283 PrintString("DxeCore = "); \r
284 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress);\r
285 PrintString(" DxeCoreLength = "); \r
286 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryLength);\r
287 PrintString("\n"); \r
288 PrintString("MemoryAllocation = "); \r
289 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress);\r
290 PrintString(" MemoryLength = "); \r
291 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryLength);\r
292 PrintString("\n"); \r
293 EFI_DEADLOOP();\r
294*/\r
ca162103 295 ClearScreen();\r
296 PrintString("\n\n\n\n\n\n\n\n\n\n");\r
297 PrintString(" WELCOME TO EFI WORLD!\n");\r
298\r
299 EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);\r
300\r
301 //\r
302 // Should never get here\r
303 //\r
304 CpuDeadLoop ();\r
305}\r
306\r
df166ce5 307EFI_STATUS\r
308EFIAPI\r
309_ModuleEntryPoint (\r
310 IN EFILDRHANDOFF *Handoff\r
311 )\r
312{\r
313 DxeInit(Handoff);\r
314 return EFI_SUCCESS;\r
315}\r