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
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.
23 #include "LegacyTable.h"
24 #include "HobGeneration.h"
25 #include "PpisNeededByDxeCore.h"
29 --------------------------------------------------------
30 Memory Map: (XX=32,64)
31 --------------------------------------------------------
41 EfiLdr (relocate by efiXX.COM)
43 Efivar.bin (Load by StartXX.COM)
45 StartXX.COM (E820 table, Temporary GDT, Temporary IDT)
47 EfiXX.COM (Temporary Interrupt Handler)
49 EfiLdr.efi + DxeIpl.Z + DxeMain.Z + BFV.Z
51 MemoryFreeUnder1M (For legacy driver DMA)
53 Temporary 4G PageTable for X64 (6 page)
66 MemoryAbove1MB.PhysicalStart <-----------------------------------------------------+
69 <- Phit.EfiMemoryBottom -------------------+ |
71 <- Phit.EfiFreeMemoryBottom | |
72 | MemoryFreeAbove1MB.ResourceLength
73 <- Phit.EfiFreeMemoryTop ------+ | |
74 MemoryDescriptor (For ACPINVS, ACPIReclaim) | 4M = CONSUMED_MEMORY |
76 Permament 4G PageTable for IA32 or MemoryAllocation | |
77 Permament 64G PageTable for X64 | | |
78 <------------------------------+ | |
79 Permament Stack (0x20 Pages = 128K) | |
80 <- Phit.EfiMemoryTop ----------+-----------+---------------+
84 <----------------------------------------------------------+<---------+
87 DxeIpl | Allocated in EfiLdr
88 <----------------------------------------------------------+ |
90 <- Top of Free Memory reported by E820 --------------------+<---------+
94 <- Memory Top on RealMemory
98 MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+
101 MemoryFreeAbove4GB.ResourceLength
104 <--------------------------------------------------+
110 IN VOID
*DxeCoreEntryPoint
,
117 IN EFILDRHANDOFF
*Handoff
123 This is the entry point after this code has been loaded into memory.
130 Calls into EFI Firmware
137 VOID
*MemoryTopOnDescriptor
;
138 VOID
*MemoryDescriptor
;
140 CHAR8 PrintBuffer
[256];
141 EFILDRHANDOFF HandoffCopy
;
143 CopyMem ((VOID
*) &HandoffCopy
, (VOID
*) Handoff
, sizeof (EFILDRHANDOFF
));
144 Handoff
= &HandoffCopy
;
147 PrintString("Enter DxeIpl ...\n");
151 PrintString("handoff:\n");
152 PrintString("Handoff.BfvBase = ");
153 PrintValue64((UINT64)(UINTN)Handoff->BfvBase);
155 PrintString("BfvLength = ");
156 PrintValue64(Handoff->BfvSize);
158 PrintString("Handoff.DxeIplImageBase = ");
159 PrintValue64((UINT64)(UINTN)Handoff->DxeIplImageBase);
161 PrintString("DxeIplImageSize = ");
162 PrintValue64(Handoff->DxeIplImageSize);
164 PrintString("Handoff.DxeCoreImageBase = ");
165 PrintValue64((UINT64)(UINTN)Handoff->DxeCoreImageBase);
167 PrintString("DxeCoreImageSize = ");
168 PrintValue64(Handoff->DxeCoreImageSize);
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");
182 PrintString("Prepare BFV HOB information ...\n");
183 PrepareHobBfv (Handoff
->BfvBase
, Handoff
->BfvSize
);
186 // 2. Updates Memory information, and get the top free address under 4GB
188 PrintString("Prepare Memory HOB information ...\n");
189 MemoryTopOnDescriptor
= PrepareHobMemory (Handoff
->MemDescCount
, Handoff
->MemDesc
);
192 // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]
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
);
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
);
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
);
215 // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore
217 PrintString("Prepare DxeCore memory Hob ...\n");
219 Handoff
->DxeCoreEntryPoint
,
220 (EFI_PHYSICAL_ADDRESS
)(UINTN
)Handoff
->DxeCoreImageBase
,
221 (UINTN
)Handoff
->DxeIplImageBase
+ (UINTN
)Handoff
->DxeIplImageSize
- (UINTN
)Handoff
->DxeCoreImageBase
224 PrepareHobLegacyTable (gHob
);
226 PreparePpisNeededByDxeCore (gHob
);
228 CompleteHobGeneration ();
230 AsciiSPrint (PrintBuffer
, 256, "HobStart=0x%x\n", (UINTN
)gHob
);
231 PrintString (PrintBuffer
);
233 AsciiSPrint (PrintBuffer
, 256, "Memory Top=0x%x, Bottom=0x%x\n",
234 (UINTN
)gHob
->Phit
.EfiMemoryTop
, (UINTN
)gHob
->Phit
.EfiMemoryBottom
);
235 PrintString (PrintBuffer
);
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
);
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
);
250 PrintString("Hob Info\n");
251 PrintString("Phit.EfiMemoryTop = ");
252 PrintValue64(gHob->Phit.EfiMemoryTop);
253 PrintString(" Phit.EfiMemoryBottom = ");
254 PrintValue64(gHob->Phit.EfiMemoryBottom);
256 PrintString("Phit.EfiFreeMemoryTop = ");
257 PrintValue64(gHob->Phit.EfiFreeMemoryTop);
258 PrintString(" Phit.EfiFreeMemoryBottom = ");
259 PrintValue64(gHob->Phit.EfiFreeMemoryBottom);
261 PrintString("Bfv = ");
262 PrintValue64(gHob->Bfv.BaseAddress);
263 PrintString(" BfvLength = ");
264 PrintValue64(gHob->Bfv.Length);
266 PrintString("NvStorageFvb = ");
267 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Base);
268 PrintString(" Length = ");
269 PrintValue64(gHob->NvStorageFvb.FvbInfo.Entries[0].Length);
271 PrintString("NvFtwFvb = ");
272 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Base);
273 PrintString(" Length = ");
274 PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);
276 PrintString("BfvResource = ");
277 PrintValue64(gHob->BfvResource.PhysicalStart);
278 PrintString(" Length = ");
279 PrintValue64(gHob->BfvResource.ResourceLength);
281 PrintString("NvStorageFvResource = ");
282 PrintValue64(gHob->NvStorageFvResource.PhysicalStart);
283 PrintString(" Length = ");
284 PrintValue64(gHob->NvStorageFvResource.ResourceLength);
286 PrintString("NvStorage = ");
287 PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Base);
288 PrintString(" Length = ");
289 PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Length);
291 PrintString("NvFtwFvResource = ");
292 PrintValue64(gHob->NvFtwFvResource.PhysicalStart);
293 PrintString(" Length = ");
294 PrintValue64(gHob->NvFtwFvResource.ResourceLength);
296 PrintString("NvFtwWorking = ");
297 PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Base);
298 PrintString(" Length = ");
299 PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Length);
301 PrintString("NvFtwSpare = ");
302 PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Base);
303 PrintString(" Length = ");
304 PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Length);
306 PrintString("Stack = ");
307 PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);
308 PrintString(" StackLength = ");
309 PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);
311 PrintString("PageTable = ");
312 PrintValue64((UINTN)PageTableBase);
314 PrintString("MemoryFreeUnder1MB = ");
315 PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);
316 PrintString(" MemoryFreeUnder1MBLength = ");
317 PrintValue64(gHob->MemoryFreeUnder1MB.ResourceLength);
319 PrintString("MemoryAbove1MB = ");
320 PrintValue64(gHob->MemoryAbove1MB.PhysicalStart);
321 PrintString(" MemoryAbove1MBLength = ");
322 PrintValue64(gHob->MemoryAbove1MB.ResourceLength);
324 PrintString("MemoryAbove4GB = ");
325 PrintValue64(gHob->MemoryAbove4GB.PhysicalStart);
326 PrintString(" MemoryAbove4GBLength = ");
327 PrintValue64(gHob->MemoryAbove4GB.ResourceLength);
329 PrintString("DxeCore = ");
330 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress);
331 PrintString(" DxeCoreLength = ");
332 PrintValue64(gHob->DxeCore.MemoryAllocationHeader.MemoryLength);
334 PrintString("MemoryAllocation = ");
335 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress);
336 PrintString(" MemoryLength = ");
337 PrintValue64(gHob->MemoryAllocation.AllocDescriptor.MemoryLength);
343 PrintString("\n\n\n\n\n\n\n\n\n\n");
344 PrintString(" WELCOME TO EFI WORLD!\n");
346 EnterDxeMain (StackTop
, Handoff
->DxeCoreEntryPoint
, gHob
, PageTableBase
);
348 PrintString("Fail to enter DXE main!\n");
350 // Should never get here
358 IN EFILDRHANDOFF
*Handoff