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