]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Fix help command scroll issue. Also add FV space used, and free space to dir command.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
CommitLineData
31f228cf 1/** @file\r
2 DXE Core Main Entry Point\r
3\r
f9876ecf 4Copyright (c) 2006 - 2010, Intel Corporation. <BR>\r
31f228cf 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "DxeMain.h"\r
16\r
17//\r
18// DXE Core Global Variables for Protocols from PEI\r
19//\r
20EFI_HANDLE mDecompressHandle = NULL;\r
21\r
22//\r
23// DXE Core globals for Architecture Protocols\r
24//\r
25EFI_SECURITY_ARCH_PROTOCOL *gSecurity = NULL;\r
26EFI_CPU_ARCH_PROTOCOL *gCpu = NULL;\r
27EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;\r
28EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;\r
29EFI_BDS_ARCH_PROTOCOL *gBds = NULL;\r
30EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;\r
31\r
32//\r
33// DXE Core Global used to update core loaded image protocol handle\r
34//\r
35EFI_GUID *gDxeCoreFileName;\r
36EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;\r
37\r
38//\r
39// DXE Core Module Variables\r
40//\r
41EFI_BOOT_SERVICES mBootServices = {\r
42 {\r
43 EFI_BOOT_SERVICES_SIGNATURE, // Signature\r
44 EFI_BOOT_SERVICES_REVISION, // Revision\r
45 sizeof (EFI_BOOT_SERVICES), // HeaderSize\r
46 0, // CRC32\r
47 0 // Reserved\r
48 },\r
49 (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL\r
50 (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL\r
51 (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages\r
52 (EFI_FREE_PAGES) CoreFreePages, // FreePages\r
53 (EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap\r
54 (EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool\r
55 (EFI_FREE_POOL) CoreFreePool, // FreePool\r
56 (EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent\r
57 (EFI_SET_TIMER) CoreSetTimer, // SetTimer\r
58 (EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent\r
59 (EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent\r
60 (EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent\r
61 (EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent\r
62 (EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface\r
63 (EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface\r
64 (EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface\r
65 (EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol\r
66 (VOID *) NULL, // Reserved\r
67 (EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify\r
68 (EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle\r
69 (EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath\r
70 (EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable\r
71 (EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage\r
72 (EFI_IMAGE_START) CoreStartImage, // StartImage\r
73 (EFI_EXIT) CoreExit, // Exit\r
74 (EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage\r
75 (EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices\r
76 (EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount\r
77 (EFI_STALL) CoreStall, // Stall\r
78 (EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer\r
79 (EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController\r
80 (EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController\r
81 (EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol\r
82 (EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol\r
83 (EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation\r
84 (EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle\r
85 (EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer\r
86 (EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol\r
87 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces\r
88 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces\r
89 (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32\r
90 (EFI_COPY_MEM) CopyMem, // CopyMem\r
91 (EFI_SET_MEM) SetMem, // SetMem\r
92 (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx\r
93};\r
94\r
95EFI_DXE_SERVICES mDxeServices = {\r
96 {\r
97 DXE_SERVICES_SIGNATURE, // Signature\r
98 DXE_SERVICES_REVISION, // Revision\r
99 sizeof (DXE_SERVICES), // HeaderSize\r
100 0, // CRC32\r
101 0 // Reserved\r
102 },\r
103 (EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace\r
104 (EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace\r
105 (EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace\r
106 (EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace\r
107 (EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor\r
108 (EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes\r
109 (EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap\r
110 (EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace\r
111 (EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace\r
112 (EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace\r
113 (EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace\r
114 (EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor\r
115 (EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap\r
116 (EFI_DISPATCH) CoreDispatcher, // Dispatch\r
117 (EFI_SCHEDULE) CoreSchedule, // Schedule\r
118 (EFI_TRUST) CoreTrust, // Trust\r
119 (EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume\r
120};\r
121\r
122EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {\r
123 {\r
124 EFI_SYSTEM_TABLE_SIGNATURE, // Signature\r
125 EFI_SYSTEM_TABLE_REVISION, // Revision\r
126 sizeof (EFI_SYSTEM_TABLE), // HeaderSize\r
127 0, // CRC32\r
128 0 // Reserved\r
129 },\r
130 NULL, // FirmwareVendor\r
131 0, // FirmwareRevision\r
132 NULL, // ConsoleInHandle\r
133 NULL, // ConIn\r
134 NULL, // ConsoleOutHandle\r
135 NULL, // ConOut\r
136 NULL, // StandardErrorHandle\r
137 NULL, // StdErr\r
138 NULL, // RuntimeServices\r
139 &mBootServices, // BootServices\r
140 0, // NumberOfConfigurationTableEntries\r
141 NULL // ConfigurationTable\r
142};\r
143\r
144EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {\r
145 {\r
146 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature\r
147 EFI_RUNTIME_SERVICES_REVISION, // Revision\r
148 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize\r
149 0, // CRC32\r
150 0 // Reserved\r
151 },\r
152 (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime\r
153 (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime\r
154 (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime\r
155 (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime\r
156 (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap\r
157 (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer\r
158 (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable\r
159 (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName\r
160 (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable\r
161 (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount\r
162 (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem\r
163 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule\r
164 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities\r
165 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo\r
166};\r
167\r
168EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
169 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
170 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
171\r
172 //\r
173 // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
174 // prevent people from having pointer math bugs in their code.\r
175 // now you have to use *DescriptorSize to make things work.\r
176 //\r
177 sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r
178 EFI_MEMORY_DESCRIPTOR_VERSION,\r
179 0,\r
180 NULL,\r
181 NULL,\r
182 FALSE,\r
183 FALSE\r
184};\r
185\r
186EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
187\r
188//\r
189// DXE Core Global Variables for the EFI System Table, Boot Services Table,\r
190// DXE Services Table, and Runtime Services Table\r
191//\r
192EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;\r
193EFI_SYSTEM_TABLE *gDxeCoreST = NULL;\r
194\r
195//\r
196// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
197// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
198// a value that will not cause debug infrastructure to crash early on.\r
199//\r
200EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
201EFI_HANDLE gDxeCoreImageHandle = NULL;\r
202\r
203\r
204//\r
205// EFI Decompress Protocol\r
206//\r
207EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {\r
208 DxeMainUefiDecompressGetInfo,\r
209 DxeMainUefiDecompress\r
210};\r
211\r
212//\r
54ea99a7 213// For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load \r
214// Runtime code&boot time code \r
215//\r
ebfb7bb5 216GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = {0, 0};\r
54ea99a7 217\r
31f228cf 218// Main entry point to the DXE Core\r
219//\r
220\r
221/**\r
222 Main entry point to DXE Core.\r
223\r
224 @param HobStart Pointer to the beginning of the HOB List from PEI.\r
225\r
226 @return This function should never return.\r
227\r
228**/\r
229VOID\r
230EFIAPI\r
231DxeMain (\r
232 IN VOID *HobStart\r
233 )\r
234{\r
235 EFI_STATUS Status;\r
236 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
237 UINT64 MemoryLength;\r
238\r
239 //\r
240 // Initialize Memory Services\r
241 //\r
242 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
243\r
244 //\r
245 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
246 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
247 //\r
248 gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
249 ASSERT (gDxeCoreST != NULL);\r
250\r
251 gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
252 ASSERT (gDxeCoreRT != NULL);\r
253\r
254 gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
255\r
256 //\r
257 // Start the Image Services.\r
258 //\r
259 Status = CoreInitializeImageServices (HobStart);\r
260 ASSERT_EFI_ERROR (Status);\r
261\r
262 //\r
263 // Call constructor for all libraries\r
264 //\r
265 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
266 PERF_END (NULL,"PEI", NULL, 0) ;\r
267 PERF_START (NULL,"DXE", NULL, 0) ;\r
268\r
269 //\r
270 // Initialize the Global Coherency Domain Services\r
271 //\r
272 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
273 ASSERT_EFI_ERROR (Status);\r
274\r
275 //\r
276 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
277 //\r
278 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
279 ASSERT_EFI_ERROR (Status);\r
280\r
281 //\r
282 // Install the HOB List into the EFI System Tables's Configuration Table\r
283 //\r
284 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
285 ASSERT_EFI_ERROR (Status);\r
286\r
287 //\r
288 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
289 //\r
290 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
291 ASSERT_EFI_ERROR (Status);\r
54ea99a7 292 \r
293 //\r
294 // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address \r
295 // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI\r
296 // Code and Tseg base to load SMM driver. \r
297 //\r
852081fc 298 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {\r
54ea99a7 299 Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);\r
300 ASSERT_EFI_ERROR (Status);\r
301 }\r
31f228cf 302 //\r
303 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
304 //\r
305 REPORT_STATUS_CODE (\r
306 EFI_PROGRESS_CODE,\r
f9876ecf 307 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)\r
31f228cf 308 );\r
309\r
310 //\r
311 // Create the aligned system table pointer structure that is used by external\r
312 // debuggers to locate the system table... Also, install debug image info\r
313 // configuration table.\r
314 //\r
315 CoreInitializeDebugImageInfoTable ();\r
316 CoreNewDebugImageInfoEntry (\r
317 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
318 gDxeCoreLoadedImage,\r
319 gDxeCoreImageHandle\r
320 );\r
321\r
322 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
323\r
324 DEBUG_CODE_BEGIN ();\r
325 EFI_PEI_HOB_POINTERS Hob;\r
326\r
327 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
328 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
329 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation %08x %0lx - %0lx\n", \\r
bfef82a1 330 Hob.MemoryAllocation->AllocDescriptor.MemoryType, \\r
31f228cf 331 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \\r
bfef82a1 332 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));\r
31f228cf 333 }\r
334 }\r
335 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
336 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {\r
337 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV2 Hob %08x %0lx - %0lx\n", Hob.FirmwareVolume2->BaseAddress, Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1, Hob.ResourceDescriptor->ResourceType));\r
338 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
339 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV Hob %08x %0lx - %0lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume2->Length - 1, Hob.ResourceDescriptor->ResourceType));\r
340 }\r
341 }\r
342 DEBUG_CODE_END ();\r
343\r
344 //\r
345 // Initialize the Event Services\r
346 //\r
347 Status = CoreInitializeEventServices ();\r
348 ASSERT_EFI_ERROR (Status);\r
349\r
350\r
351 //\r
352 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
353 //\r
354 // These Protocols are not architectural. This implementation is sharing code between\r
355 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
356 // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
357 // each time a different CPU is used, a different Decompression algorithm is used, or a\r
358 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
359 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
360 // and from CPU to CPU.\r
361 //\r
362\r
363 //\r
364 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
365 //\r
366 Status = CoreInstallMultipleProtocolInterfaces (\r
367 &mDecompressHandle,\r
368 &gEfiDecompressProtocolGuid, &gEfiDecompress,\r
369 NULL\r
370 );\r
371 ASSERT_EFI_ERROR (Status);\r
372\r
373 //\r
374 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
375 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
376 //\r
377 CoreNotifyOnArchProtocolInstallation ();\r
378\r
379 //\r
380 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
381 //\r
382 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
383 ASSERT_EFI_ERROR (Status);\r
384\r
385 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
386 ASSERT_EFI_ERROR (Status);\r
387\r
388 //\r
389 // Produce the Section Extraction Protocol\r
390 //\r
391 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
392 ASSERT_EFI_ERROR (Status);\r
393\r
394 //\r
395 // Initialize the DXE Dispatcher\r
396 //\r
397 PERF_START (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
398 CoreInitializeDispatcher ();\r
399 PERF_END (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
400\r
401 //\r
402 // Invoke the DXE Dispatcher\r
403 //\r
404 PERF_START (NULL, "CoreDispatcher", "DxeMain", 0);\r
405 CoreDispatcher ();\r
406 PERF_END (NULL, "CoreDispatcher", "DxeMain", 0);\r
407\r
408 //\r
409 // Display Architectural protocols that were not loaded if this is DEBUG build\r
410 //\r
411 DEBUG_CODE_BEGIN ();\r
412 CoreDisplayMissingArchProtocols ();\r
413 DEBUG_CODE_END ();\r
414\r
415 //\r
416 // Display any drivers that were not dispatched because dependency expression\r
417 // evaluated to false if this is a debug build\r
418 //\r
419 DEBUG_CODE_BEGIN ();\r
420 CoreDisplayDiscoveredNotDispatched ();\r
421 DEBUG_CODE_END ();\r
422\r
423 //\r
424 // Assert if the Architectural Protocols are not present.\r
425 //\r
426 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
427\r
428 //\r
429 // Report Status code before transfer control to BDS\r
430 //\r
431 REPORT_STATUS_CODE (\r
432 EFI_PROGRESS_CODE,\r
f9876ecf 433 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)\r
31f228cf 434 );\r
435\r
436 //\r
437 // Transfer control to the BDS Architectural Protocol\r
438 //\r
439 gBds->Entry (gBds);\r
440\r
441 //\r
442 // BDS should never return\r
443 //\r
444 ASSERT (FALSE);\r
445 CpuDeadLoop ();\r
446}\r
447\r
448\r
449\r
450/**\r
451 Place holder function until all the Boot Services and Runtime Services are\r
452 available.\r
453\r
454 @return EFI_NOT_AVAILABLE_YET\r
455\r
456**/\r
457EFI_STATUS\r
458EFIAPI\r
459CoreEfiNotAvailableYetArg0 (\r
460 VOID\r
461 )\r
462{\r
463 //\r
464 // This function should never be executed. If it does, then the architectural protocols\r
465 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
466 // DXE Core and all the Architectural Protocols are complete.\r
467 //\r
468\r
469 return EFI_NOT_AVAILABLE_YET;\r
470}\r
471\r
472\r
473/**\r
474 Place holder function until all the Boot Services and Runtime Services are\r
475 available.\r
476\r
477 @param Arg1 Undefined\r
478\r
479 @return EFI_NOT_AVAILABLE_YET\r
480\r
481**/\r
482EFI_STATUS\r
483EFIAPI\r
484CoreEfiNotAvailableYetArg1 (\r
485 UINTN Arg1\r
486 )\r
487{\r
488 //\r
489 // This function should never be executed. If it does, then the architectural protocols\r
490 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
491 // DXE Core and all the Architectural Protocols are complete.\r
492 //\r
493\r
494 return EFI_NOT_AVAILABLE_YET;\r
495}\r
496\r
497\r
498/**\r
499 Place holder function until all the Boot Services and Runtime Services are available.\r
500\r
501 @param Arg1 Undefined\r
502 @param Arg2 Undefined\r
503\r
504 @return EFI_NOT_AVAILABLE_YET\r
505\r
506**/\r
507EFI_STATUS\r
508EFIAPI\r
509CoreEfiNotAvailableYetArg2 (\r
510 UINTN Arg1,\r
511 UINTN Arg2\r
512 )\r
513{\r
514 //\r
515 // This function should never be executed. If it does, then the architectural protocols\r
516 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
517 // DXE Core and all the Architectural Protocols are complete.\r
518 //\r
519\r
520 return EFI_NOT_AVAILABLE_YET;\r
521}\r
522\r
523\r
524/**\r
525 Place holder function until all the Boot Services and Runtime Services are available.\r
526\r
527 @param Arg1 Undefined\r
528 @param Arg2 Undefined\r
529 @param Arg3 Undefined\r
530\r
531 @return EFI_NOT_AVAILABLE_YET\r
532\r
533**/\r
534EFI_STATUS\r
535EFIAPI\r
536CoreEfiNotAvailableYetArg3 (\r
537 UINTN Arg1,\r
538 UINTN Arg2,\r
539 UINTN Arg3\r
540 )\r
541{\r
542 //\r
543 // This function should never be executed. If it does, then the architectural protocols\r
544 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
545 // DXE Core and all the Architectural Protocols are complete.\r
546 //\r
547\r
548 return EFI_NOT_AVAILABLE_YET;\r
549}\r
550\r
551\r
552/**\r
553 Place holder function until all the Boot Services and Runtime Services are available.\r
554\r
555 @param Arg1 Undefined\r
556 @param Arg2 Undefined\r
557 @param Arg3 Undefined\r
558 @param Arg4 Undefined\r
559\r
560 @return EFI_NOT_AVAILABLE_YET\r
561\r
562**/\r
563EFI_STATUS\r
564EFIAPI\r
565CoreEfiNotAvailableYetArg4 (\r
566 UINTN Arg1,\r
567 UINTN Arg2,\r
568 UINTN Arg3,\r
569 UINTN Arg4\r
570 )\r
571{\r
572 //\r
573 // This function should never be executed. If it does, then the architectural protocols\r
574 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
575 // DXE Core and all the Architectural Protocols are complete.\r
576 //\r
577\r
578 return EFI_NOT_AVAILABLE_YET;\r
579}\r
580\r
581\r
582/**\r
583 Place holder function until all the Boot Services and Runtime Services are available.\r
584\r
585 @param Arg1 Undefined\r
586 @param Arg2 Undefined\r
587 @param Arg3 Undefined\r
588 @param Arg4 Undefined\r
589 @param Arg5 Undefined\r
590\r
591 @return EFI_NOT_AVAILABLE_YET\r
592\r
593**/\r
594EFI_STATUS\r
595EFIAPI\r
596CoreEfiNotAvailableYetArg5 (\r
597 UINTN Arg1,\r
598 UINTN Arg2,\r
599 UINTN Arg3,\r
600 UINTN Arg4,\r
601 UINTN Arg5\r
602 )\r
603{\r
604 //\r
605 // This function should never be executed. If it does, then the architectural protocols\r
606 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
607 // DXE Core and all the Architectural Protocols are complete.\r
608 //\r
609\r
610 return EFI_NOT_AVAILABLE_YET;\r
611}\r
612\r
613\r
614/**\r
615 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
616 gRuntime service.\r
617\r
618 @param Hdr Pointer to an EFI standard header\r
619\r
620**/\r
621VOID\r
622CalculateEfiHdrCrc (\r
623 IN OUT EFI_TABLE_HEADER *Hdr\r
624 )\r
625{\r
626 UINT32 Crc;\r
627\r
628 Hdr->CRC32 = 0;\r
629\r
630 //\r
631 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
632 // Crc will come back as zero if we set it to zero here\r
633 //\r
634 Crc = 0;\r
635 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
636 Hdr->CRC32 = Crc;\r
637}\r
638\r
639\r
640/**\r
641 Terminates all boot services.\r
642\r
643 @param ImageHandle Handle that identifies the exiting image.\r
644 @param MapKey Key to the latest memory map.\r
645\r
646 @retval EFI_SUCCESS Boot Services terminated\r
647 @retval EFI_INVALID_PARAMETER MapKey is incorrect.\r
648\r
649**/\r
650EFI_STATUS\r
651EFIAPI\r
652CoreExitBootServices (\r
653 IN EFI_HANDLE ImageHandle,\r
654 IN UINTN MapKey\r
655 )\r
656{\r
657 EFI_STATUS Status;\r
658\r
659 //\r
660 // Terminate memory services if the MapKey matches\r
661 //\r
662 Status = CoreTerminateMemoryMap (MapKey);\r
663 if (EFI_ERROR (Status)) {\r
664 return Status;\r
665 }\r
666\r
667 //\r
668 // Disable Timer\r
669 //\r
670 gTimer->SetTimerPeriod (gTimer, 0);\r
671\r
672 //\r
673 // Notify other drivers that we are exiting boot services.\r
674 //\r
675 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
676\r
677 //\r
678 // Disable CPU Interrupts\r
679 //\r
680 gCpu->DisableInterrupt (gCpu);\r
681\r
682 //\r
683 // Report that ExitBootServices() has been called\r
684 //\r
685 REPORT_STATUS_CODE (\r
686 EFI_PROGRESS_CODE,\r
f9876ecf 687 (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
31f228cf 688 );\r
689\r
690 //\r
691 // Clear the non-runtime values of the EFI System Table\r
692 //\r
693 gDxeCoreST->BootServices = NULL;\r
694 gDxeCoreST->ConIn = NULL;\r
695 gDxeCoreST->ConsoleInHandle = NULL;\r
696 gDxeCoreST->ConOut = NULL;\r
697 gDxeCoreST->ConsoleOutHandle = NULL;\r
698 gDxeCoreST->StdErr = NULL;\r
699 gDxeCoreST->StandardErrorHandle = NULL;\r
700\r
701 //\r
702 // Recompute the 32-bit CRC of the EFI System Table\r
703 //\r
704 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
705\r
706 //\r
707 // Zero out the Boot Service Table\r
708 //\r
709 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));\r
710 gBS = NULL;\r
711\r
712 //\r
713 // Update the AtRuntime field in Runtiem AP.\r
714 //\r
715 gRuntime->AtRuntime = TRUE;\r
716\r
717 return Status;\r
718}\r
719\r
720\r
721/**\r
722 Given a compressed source buffer, this function retrieves the size of the\r
723 uncompressed buffer and the size of the scratch buffer required to decompress\r
724 the compressed source buffer.\r
725\r
726 The GetInfo() function retrieves the size of the uncompressed buffer and the\r
727 temporary scratch buffer required to decompress the buffer specified by Source\r
728 and SourceSize. If the size of the uncompressed buffer or the size of the\r
729 scratch buffer cannot be determined from the compressed data specified by\r
730 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
731 size of the uncompressed buffer is returned in DestinationSize, the size of\r
732 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
733 The GetInfo() function does not have scratch buffer available to perform a\r
734 thorough checking of the validity of the source data. It just retrieves the\r
735 "Original Size" field from the beginning bytes of the source data and output\r
736 it as DestinationSize. And ScratchSize is specific to the decompression\r
737 implementation.\r
738\r
739 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
740 @param Source The source buffer containing the compressed data.\r
741 @param SourceSize The size, in bytes, of the source buffer.\r
742 @param DestinationSize A pointer to the size, in bytes, of the\r
743 uncompressed buffer that will be generated when the\r
744 compressed buffer specified by Source and\r
745 SourceSize is decompressed.\r
746 @param ScratchSize A pointer to the size, in bytes, of the scratch\r
747 buffer that is required to decompress the\r
748 compressed buffer specified by Source and\r
749 SourceSize.\r
750\r
751 @retval EFI_SUCCESS The size of the uncompressed data was returned in\r
752 DestinationSize and the size of the scratch buffer\r
753 was returned in ScratchSize.\r
754 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
755 the scratch buffer cannot be determined from the\r
756 compressed data specified by Source and\r
757 SourceSize.\r
758\r
759**/\r
760EFI_STATUS\r
761EFIAPI\r
762DxeMainUefiDecompressGetInfo (\r
763 IN EFI_DECOMPRESS_PROTOCOL *This,\r
764 IN VOID *Source,\r
765 IN UINT32 SourceSize,\r
766 OUT UINT32 *DestinationSize,\r
767 OUT UINT32 *ScratchSize\r
768 )\r
769{\r
770 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {\r
771 return EFI_INVALID_PARAMETER;\r
772 }\r
773 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
774}\r
775\r
776\r
777/**\r
778 Decompresses a compressed source buffer.\r
779\r
780 The Decompress() function extracts decompressed data to its original form.\r
781 This protocol is designed so that the decompression algorithm can be\r
782 implemented without using any memory services. As a result, the Decompress()\r
783 Function is not allowed to call AllocatePool() or AllocatePages() in its\r
784 implementation. It is the caller's responsibility to allocate and free the\r
785 Destination and Scratch buffers.\r
786 If the compressed source data specified by Source and SourceSize is\r
787 sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
788 the compressed source data specified by Source and SourceSize is not in a\r
789 valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
790\r
791 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
792 @param Source The source buffer containing the compressed data.\r
793 @param SourceSize SourceSizeThe size of source data.\r
794 @param Destination On output, the destination buffer that contains\r
795 the uncompressed data.\r
796 @param DestinationSize The size of the destination buffer. The size of\r
797 the destination buffer needed is obtained from\r
798 EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
799 @param Scratch A temporary scratch buffer that is used to perform\r
800 the decompression.\r
801 @param ScratchSize The size of scratch buffer. The size of the\r
802 scratch buffer needed is obtained from GetInfo().\r
803\r
804 @retval EFI_SUCCESS Decompression completed successfully, and the\r
805 uncompressed buffer is returned in Destination.\r
806 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and\r
807 SourceSize is corrupted (not in a valid\r
808 compressed format).\r
809\r
810**/\r
811EFI_STATUS\r
812EFIAPI\r
813DxeMainUefiDecompress (\r
814 IN EFI_DECOMPRESS_PROTOCOL *This,\r
815 IN VOID *Source,\r
816 IN UINT32 SourceSize,\r
817 IN OUT VOID *Destination,\r
818 IN UINT32 DestinationSize,\r
819 IN OUT VOID *Scratch,\r
820 IN UINT32 ScratchSize\r
821 )\r
822{\r
823 EFI_STATUS Status;\r
824 UINT32 TestDestinationSize;\r
825 UINT32 TestScratchSize;\r
826\r
827 if (Source == NULL || Destination== NULL || Scratch == NULL) {\r
828 return EFI_INVALID_PARAMETER;\r
829 }\r
830\r
831 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
832 if (EFI_ERROR (Status)) {\r
833 return Status;\r
834 }\r
835\r
836 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
837 return RETURN_INVALID_PARAMETER;\r
838 }\r
839\r
840 return UefiDecompress (Source, Destination, Scratch);\r
841}\r