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