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