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