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