]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
Replace the original Fat.FFS to fix issue which causes to read some hard-disk slowly.
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / DxeMain / DxeMain.c
CommitLineData
ef99a95a 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DxeMain.c\r
15\r
16Abstract:\r
17\r
18 DXE Core Main Entry Point\r
19\r
20--*/\r
21\r
22#include <DxeMain.h>\r
23\r
24VOID\r
25EFIAPI\r
26DxeMain (\r
27 IN VOID *HobStart\r
28 );\r
29\r
30EFI_STATUS\r
31EFIAPI\r
32CoreEfiNotAvailableYetArg0 (\r
33 VOID\r
34 );\r
35\r
36EFI_STATUS\r
37EFIAPI\r
38CoreEfiNotAvailableYetArg1 (\r
39 UINTN Arg1\r
40 );\r
41\r
42EFI_STATUS\r
43EFIAPI\r
44CoreEfiNotAvailableYetArg2 (\r
45 UINTN Arg1,\r
46 UINTN Arg2\r
47 );\r
48\r
49EFI_STATUS\r
50EFIAPI\r
51CoreEfiNotAvailableYetArg3 (\r
52 UINTN Arg1,\r
53 UINTN Arg2,\r
54 UINTN Arg3\r
55 );\r
56\r
57EFI_STATUS\r
58EFIAPI\r
59CoreEfiNotAvailableYetArg4 (\r
60 UINTN Arg1,\r
61 UINTN Arg2,\r
62 UINTN Arg3,\r
63 UINTN Arg4\r
64 );\r
65\r
66EFI_STATUS\r
67EFIAPI\r
68CoreEfiNotAvailableYetArg5 (\r
69 UINTN Arg1,\r
70 UINTN Arg2,\r
71 UINTN Arg3,\r
72 UINTN Arg4,\r
73 UINTN Arg5\r
74 );\r
75\r
76EFI_STATUS\r
77CoreGetPeiProtocol (\r
78 IN EFI_GUID *ProtocolGuid,\r
79 IN VOID **Interface\r
80 );\r
81 \r
82EFI_STATUS\r
83DxeMainUefiDecompressGetInfo (\r
84 IN EFI_DECOMPRESS_PROTOCOL *This,\r
85 IN VOID *Source,\r
86 IN UINT32 SourceSize,\r
87 OUT UINT32 *DestinationSize,\r
88 OUT UINT32 *ScratchSize\r
89 );\r
90\r
91EFI_STATUS\r
92EFIAPI\r
93DxeMainUefiDecompress (\r
94 IN EFI_DECOMPRESS_PROTOCOL *This,\r
95 IN VOID *Source,\r
96 IN UINT32 SourceSize,\r
97 IN OUT VOID *Destination,\r
98 IN UINT32 DestinationSize,\r
99 IN OUT VOID *Scratch,\r
100 IN UINT32 ScratchSize\r
101 );\r
102\r
103EFI_STATUS\r
104DxeMainTianoDecompressGetInfo (\r
105 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
106 IN VOID *Source,\r
107 IN UINT32 SourceSize,\r
108 OUT UINT32 *DestinationSize,\r
109 OUT UINT32 *ScratchSize\r
110 );\r
111\r
112EFI_STATUS\r
113EFIAPI\r
114DxeMainTianoDecompress (\r
115 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
116 IN VOID *Source,\r
117 IN UINT32 SourceSize,\r
118 IN OUT VOID *Destination,\r
119 IN UINT32 DestinationSize,\r
120 IN OUT VOID *Scratch,\r
121 IN UINT32 ScratchSize\r
122 );\r
123\r
124EFI_STATUS\r
125DxeMainCustomDecompressGetInfo (\r
126 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,\r
127 IN VOID *Source,\r
128 IN UINT32 SourceSize,\r
129 OUT UINT32 *DestinationSize,\r
130 OUT UINT32 *ScratchSize\r
131 );\r
132\r
133EFI_STATUS\r
134EFIAPI\r
135DxeMainCustomDecompress (\r
136 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,\r
137 IN VOID *Source,\r
138 IN UINT32 SourceSize,\r
139 IN OUT VOID *Destination,\r
140 IN UINT32 DestinationSize,\r
141 IN OUT VOID *Scratch,\r
142 IN UINT32 ScratchSize\r
143 );\r
144\r
145//\r
146// DXE Core Global Variables for Protocols from PEI\r
147//\r
148EFI_HANDLE mDecompressHandle = NULL;\r
149EFI_PEI_PE_COFF_LOADER_PROTOCOL *gEfiPeiPeCoffLoader = NULL;\r
150\r
151//\r
152// DXE Core globals for Architecture Protocols\r
153//\r
154EFI_SECURITY_ARCH_PROTOCOL *gSecurity = NULL;\r
155EFI_CPU_ARCH_PROTOCOL *gCpu = NULL;\r
156EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;\r
157EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;\r
158EFI_BDS_ARCH_PROTOCOL *gBds = NULL;\r
159EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;\r
160EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = NULL;\r
161\r
162//\r
163// BugBug: I'n not runtime, but is the PPI?\r
164//\r
165EFI_STATUS_CODE_PROTOCOL gStatusCodeInstance = {\r
166 NULL\r
167};\r
168\r
169EFI_STATUS_CODE_PROTOCOL *gStatusCode = &gStatusCodeInstance;\r
170\r
171\r
172//\r
173// DXE Core Global used to update core loaded image protocol handle\r
174//\r
175EFI_GUID *gDxeCoreFileName;\r
176EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;\r
177\r
178\r
179\r
180//\r
181// DXE Core Module Variables\r
182//\r
183\r
184EFI_BOOT_SERVICES mBootServices = {\r
185 {\r
186 EFI_BOOT_SERVICES_SIGNATURE, // Signature\r
187 EFI_BOOT_SERVICES_REVISION, // Revision\r
188 sizeof (EFI_BOOT_SERVICES), // HeaderSize\r
189 0, // CRC32\r
190 0 // Reserved\r
191 }, \r
192 (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL\r
193 (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL\r
194 (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages\r
195 (EFI_FREE_PAGES) CoreFreePages, // FreePages\r
196 (EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap\r
197 (EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool\r
198 (EFI_FREE_POOL) CoreFreePool, // FreePool\r
199 (EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent\r
200 (EFI_SET_TIMER) CoreSetTimer, // SetTimer\r
201 (EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent\r
202 (EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent\r
203 (EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent\r
204 (EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent\r
205 (EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface\r
206 (EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface\r
207 (EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface\r
208 (EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol\r
209 (VOID *) NULL, // Reserved\r
210 (EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify\r
211 (EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle\r
212 (EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath\r
213 (EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable\r
214 (EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage\r
215 (EFI_IMAGE_START) CoreStartImage, // StartImage\r
216 (EFI_EXIT) CoreExit, // Exit\r
217 (EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage\r
218 (EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices\r
219 (EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount\r
220 (EFI_STALL) CoreStall, // Stall\r
221 (EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer\r
222 (EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController\r
223 (EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController\r
224 (EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol\r
225 (EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol\r
226 (EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation\r
227 (EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle\r
228 (EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer\r
229 (EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol\r
230 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces\r
231 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces\r
232 (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32\r
233 (EFI_COPY_MEM) CopyMem, // CopyMem\r
234 (EFI_SET_MEM) SetMem // SetMem\r
235#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
236 , \r
237 (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx\r
238#endif\r
239};\r
240\r
241EFI_DXE_SERVICES mDxeServices = {\r
242 {\r
243 EFI_DXE_SERVICES_SIGNATURE, // Signature\r
244 EFI_DXE_SERVICES_REVISION, // Revision\r
245 sizeof (EFI_DXE_SERVICES), // HeaderSize\r
246 0, // CRC32\r
247 0 // Reserved\r
248 },\r
249 (EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace\r
250 (EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace\r
251 (EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace\r
252 (EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace\r
253 (EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor\r
254 (EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes\r
255 (EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap\r
256 (EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace\r
257 (EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace\r
258 (EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace\r
259 (EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace\r
260 (EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor\r
261 (EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap\r
262 (EFI_DISPATCH) CoreDispatcher, // Dispatch\r
263 (EFI_SCHEDULE) CoreSchedule, // Schedule\r
264 (EFI_TRUST) CoreTrust, // Trust\r
265 (EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume\r
266};\r
267\r
268EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {\r
269 {\r
270 EFI_SYSTEM_TABLE_SIGNATURE, // Signature\r
271 EFI_SYSTEM_TABLE_REVISION, // Revision\r
272 sizeof (EFI_SYSTEM_TABLE), // HeaderSize\r
273 0, // CRC32\r
274 0 // Reserved\r
275 },\r
276 NULL, // FirmwareVendor\r
277 0, // FirmwareRevision\r
278 NULL, // ConsoleInHandle\r
279 NULL, // ConIn\r
280 NULL, // ConsoleOutHandle\r
281 NULL, // ConOut\r
282 NULL, // StandardErrorHandle\r
283 NULL, // StdErr\r
284 NULL, // RuntimeServices\r
285 &mBootServices, // BootServices\r
286 0, // NumberOfConfigurationTableEntries\r
287 NULL // ConfigurationTable\r
288};\r
289\r
290EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {\r
291 {\r
292 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature\r
293 EFI_RUNTIME_SERVICES_REVISION, // Revision\r
294 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize\r
295 0, // CRC32\r
296 0 // Reserved\r
297 },\r
298 (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime\r
299 (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime\r
300 (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime\r
301 (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime\r
302 (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap\r
303 (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer\r
304 (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable\r
305 (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName\r
306 (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable\r
307 (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount\r
308 (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4 // ResetSystem \r
309#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
a537f148 310 //\r
311 // This Tiano extension was removed when UEFI 2.0 support was added. \r
312 // It's now just a protocol.\r
313 //\r
ef99a95a 314 ,\r
36122070 315 (EFI_REPORT_STATUS_CODE) CoreEfiNotAvailableYetArg5 // ReportStatusCode\r
ef99a95a 316#elif (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
a537f148 317 //\r
318 // New runtime services added by UEFI 2.0\r
319 //\r
ef99a95a 320 ,\r
321 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule\r
322 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities\r
323 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo\r
324#endif\r
325};\r
326\r
327//\r
328// DXE Core Global Variables for the EFI System Table, Boot Services Table, \r
329// DXE Services Table, and Runtime Services Table\r
330//\r
331EFI_BOOT_SERVICES *gBS = &mBootServices;\r
332EFI_DXE_SERVICES *gDS = &mDxeServices;\r
333EFI_SYSTEM_TABLE *gST = NULL;\r
334\r
335//\r
336// For debug initialize gRT to template. gRT must be allocated from RT memory\r
337// but gRT is used for ASSERT () and DEBUG () type macros so lets give it\r
338// a value that will not cause debug infrastructure to crash early on.\r
339//\r
340EFI_RUNTIME_SERVICES *gRT = &mEfiRuntimeServicesTableTemplate;\r
341EFI_HANDLE gDxeCoreImageHandle = NULL;\r
342\r
343VOID *mHobStart;\r
344\r
345//\r
346// EFI Decompress Protocol\r
347//\r
348EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {\r
349 DxeMainUefiDecompressGetInfo,\r
350 DxeMainUefiDecompress\r
351};\r
352\r
353//\r
354// Tiano Decompress Protocol\r
355//\r
356EFI_TIANO_DECOMPRESS_PROTOCOL gEfiTianoDecompress = {\r
357 DxeMainTianoDecompressGetInfo,\r
358 DxeMainTianoDecompress\r
359};\r
360\r
361//\r
362// Customized Decompress Protocol\r
363//\r
364EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL gEfiCustomizedDecompress = {\r
365 DxeMainCustomDecompressGetInfo,\r
366 DxeMainCustomDecompress\r
367};\r
368\r
369//\r
370// Main entry point to the DXE Core\r
371//\r
372VOID\r
373EFIAPI\r
374DxeMain (\r
375 IN VOID *HobStart\r
376 )\r
377/*++\r
378\r
379Routine Description:\r
380\r
381 Main entry point to DXE Core.\r
382\r
383Arguments:\r
384\r
385 HobStart - Pointer to the beginning of the HOB List from PEI\r
386\r
387Returns:\r
388\r
389 This function should never return\r
390\r
391--*/\r
392{\r
393 EFI_STATUS Status;\r
394 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
395 UINT64 MemoryLength;\r
396\r
397#ifdef EFI_DXE_PERFORMANCE\r
398 UINT64 Tick;\r
399\r
400 GetTimerValue (&Tick);\r
401#endif\r
402\r
403 mHobStart = HobStart;\r
404\r
405 //\r
406 // Initialize Memory Services\r
407 //\r
408 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
409\r
410 //\r
411 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
412 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
413 //\r
414 gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
415 ASSERT (gST != NULL);\r
416\r
417 gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
418 ASSERT (gRT != NULL);\r
419\r
420 gST->RuntimeServices = gRT;\r
421 \r
422 //\r
423 // Start the Image Services.\r
424 //\r
425 Status = CoreInitializeImageServices (HobStart);\r
426 ASSERT_EFI_ERROR (Status);\r
427\r
428 //\r
429 // Call constructor for all libraries\r
430 //\r
431 ProcessLibraryConstructorList (gDxeCoreImageHandle, gST);\r
432\r
433 //\r
434 // Initialize the Global Coherency Domain Services\r
435 //\r
436 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
437 ASSERT_EFI_ERROR (Status);\r
438\r
439 //\r
440 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
441 //\r
442 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);\r
443 ASSERT_EFI_ERROR (Status);\r
444\r
445 //\r
446 // Install the HOB List into the EFI System Tables's Configuration Table\r
447 //\r
448 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
449 ASSERT_EFI_ERROR (Status);\r
450\r
451 //\r
452 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
453 //\r
454 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
455 ASSERT_EFI_ERROR (Status);\r
456\r
457 //\r
458 // Initialize the ReportStatusCode with PEI version, if availible\r
459 //\r
460 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);\r
461#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
a537f148 462 //\r
463 // This Tiano extension was removed when UEFI 2.0 support was added. \r
464 // It's now just a protocol.\r
465 //\r
ef99a95a 466 gRT->ReportStatusCode = gStatusCode->ReportStatusCode;\r
467#endif\r
468\r
469 //\r
470 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
471 //\r
472 CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT));\r
473\r
474 //\r
475 // Create the aligned system table pointer structure that is used by external\r
476 // debuggers to locate the system table... Also, install debug image info\r
477 // configuration table.\r
478 //\r
479 CoreInitializeDebugImageInfoTable ();\r
480 CoreNewDebugImageInfoEntry (\r
481 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
482 gDxeCoreLoadedImage,\r
483 gDxeCoreImageHandle\r
484 );\r
485\r
486 DEBUG ((EFI_D_INFO | EFI_D_LOAD, "HOBLIST address in DXE = 0x%08x\n", HobStart));\r
487\r
488 //\r
489 // Initialize the Event Services\r
490 //\r
491 Status = CoreInitializeEventServices ();\r
492 ASSERT_EFI_ERROR (Status);\r
493\r
494 \r
495 //\r
496 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
497 //\r
498 // These Protocols are not architectural. This implementation is sharing code between \r
499 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented \r
500 // as part of the DXE Core. However, that would also require the DXE Core to be ported \r
501 // each time a different CPU is used, a different Decompression algorithm is used, or a \r
502 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains \r
503 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, \r
504 // and from CPU to CPU.\r
505 //\r
506\r
507 //\r
508 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
509 // \r
510 Status = CoreInstallMultipleProtocolInterfaces (\r
511 &mDecompressHandle,\r
512 &gEfiDecompressProtocolGuid, &gEfiDecompress,\r
513 &gEfiTianoDecompressProtocolGuid, &gEfiTianoDecompress,\r
514 &gEfiCustomizedDecompressProtocolGuid, &gEfiCustomizedDecompress,\r
515 NULL\r
516 );\r
517 ASSERT_EFI_ERROR (Status);\r
518\r
519 gEfiPeiPeCoffLoader = GetPeCoffLoaderProtocol ();\r
520 ASSERT (gEfiPeiPeCoffLoader != NULL);\r
521\r
522 //\r
523 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
524 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
525 //\r
526 CoreNotifyOnArchProtocolInstallation ();\r
527\r
528 //\r
529 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
530 //\r
531 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);\r
532 ASSERT_EFI_ERROR (Status);\r
533\r
534 Status = FwVolDriverInit (gDxeCoreImageHandle, gST);\r
535 ASSERT_EFI_ERROR (Status);\r
536\r
537 //\r
538 // Produce the Section Extraction Protocol \r
539 //\r
540 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);\r
541 ASSERT_EFI_ERROR (Status);\r
542\r
543 //\r
544 // Initialize the DXE Dispatcher\r
545 //\r
546 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
547 CoreInitializeDispatcher ();\r
548 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
549\r
550 //\r
551 // Invoke the DXE Dispatcher\r
552 //\r
553 PERF_START (0, "CoreDispatcher", "DxeMain", 0);\r
554 CoreDispatcher ();\r
555 PERF_END (0, "CoreDispatcher", "DxeMain", 0);\r
556\r
557 //\r
558 // Display Architectural protocols that were not loaded if this is DEBUG build\r
559 //\r
560 DEBUG_CODE (\r
561 CoreDisplayMissingArchProtocols ();\r
562 );\r
563 \r
564 //\r
565 // Assert if the Architectural Protocols are not present.\r
566 //\r
567 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
568\r
569 //\r
570 // Report Status code before transfer control to BDS\r
571 //\r
572 CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT));\r
573 //\r
574 // Display any drivers that were not dispatched because dependency expression\r
575 // evaluated to false if this is a debug build\r
576 //\r
577 DEBUG_CODE (\r
578 CoreDisplayDiscoveredNotDispatched ();\r
579 );\r
580\r
581 //\r
582 // Transfer control to the BDS Architectural Protocol\r
583 //\r
584 gBds->Entry (gBds);\r
585 \r
586 //\r
587 // BDS should never return\r
588 //\r
589 ASSERT (FALSE);\r
590 CpuDeadLoop ();\r
591}\r
592\r
593\r
594EFI_STATUS\r
595EFIAPI\r
596CoreEfiNotAvailableYetArg0 (\r
597 VOID\r
598 )\r
599/*++\r
600\r
601Routine Description:\r
602\r
603 Place holder function until all the Boot Services and Runtime Services are available\r
604\r
605Arguments:\r
606\r
607 None\r
608\r
609Returns:\r
610\r
611 EFI_NOT_AVAILABLE_YET\r
612\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
624EFI_STATUS\r
625EFIAPI\r
626CoreEfiNotAvailableYetArg1 (\r
627 UINTN Arg1\r
628 )\r
629/*++\r
630\r
631Routine Description:\r
632\r
633 Place holder function until all the Boot Services and Runtime Services are available\r
634\r
635Arguments:\r
636\r
637 Arg1 - Undefined\r
638\r
639Returns:\r
640\r
641 EFI_NOT_AVAILABLE_YET\r
642\r
643--*/\r
644{\r
645 //\r
646 // This function should never be executed. If it does, then the architectural protocols\r
647 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
648 // DXE Core and all the Architectural Protocols are complete.\r
649 //\r
650\r
651 return EFI_NOT_AVAILABLE_YET;\r
652}\r
653\r
654EFI_STATUS\r
655EFIAPI\r
656CoreEfiNotAvailableYetArg2 (\r
657 UINTN Arg1,\r
658 UINTN Arg2\r
659 )\r
660/*++\r
661\r
662Routine Description:\r
663\r
664 Place holder function until all the Boot Services and Runtime Services are available\r
665\r
666Arguments:\r
667\r
668 Arg1 - Undefined\r
669 \r
670 Arg2 - Undefined\r
671\r
672Returns:\r
673\r
674 EFI_NOT_AVAILABLE_YET\r
675\r
676--*/\r
677{\r
678 //\r
679 // This function should never be executed. If it does, then the architectural protocols\r
680 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
681 // DXE Core and all the Architectural Protocols are complete.\r
682 //\r
683\r
684 return EFI_NOT_AVAILABLE_YET;\r
685}\r
686\r
687EFI_STATUS\r
688EFIAPI\r
689CoreEfiNotAvailableYetArg3 (\r
690 UINTN Arg1,\r
691 UINTN Arg2,\r
692 UINTN Arg3\r
693 )\r
694/*++\r
695\r
696Routine Description:\r
697\r
698 Place holder function until all the Boot Services and Runtime Services are available\r
699\r
700Arguments:\r
701\r
702 Arg1 - Undefined\r
703 \r
704 Arg2 - Undefined\r
705 \r
706 Arg3 - Undefined\r
707\r
708Returns:\r
709\r
710 EFI_NOT_AVAILABLE_YET\r
711\r
712--*/\r
713{\r
714 //\r
715 // This function should never be executed. If it does, then the architectural protocols\r
716 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
717 // DXE Core and all the Architectural Protocols are complete.\r
718 //\r
719\r
720 return EFI_NOT_AVAILABLE_YET;\r
721}\r
722\r
723EFI_STATUS\r
724EFIAPI\r
725CoreEfiNotAvailableYetArg4 (\r
726 UINTN Arg1,\r
727 UINTN Arg2,\r
728 UINTN Arg3,\r
729 UINTN Arg4\r
730 )\r
731/*++\r
732\r
733Routine Description:\r
734\r
735 Place holder function until all the Boot Services and Runtime Services are available\r
736\r
737Arguments:\r
738\r
739 Arg1 - Undefined\r
740 \r
741 Arg2 - Undefined\r
742 \r
743 Arg3 - Undefined\r
744 \r
745 Arg4 - Undefined\r
746\r
747Returns:\r
748\r
749 EFI_NOT_AVAILABLE_YET\r
750\r
751--*/\r
752{\r
753 //\r
754 // This function should never be executed. If it does, then the architectural protocols\r
755 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
756 // DXE Core and all the Architectural Protocols are complete.\r
757 //\r
758\r
759 return EFI_NOT_AVAILABLE_YET;\r
760}\r
761\r
762EFI_STATUS\r
763EFIAPI\r
764CoreEfiNotAvailableYetArg5 (\r
765 UINTN Arg1,\r
766 UINTN Arg2,\r
767 UINTN Arg3,\r
768 UINTN Arg4,\r
769 UINTN Arg5\r
770 )\r
771/*++\r
772\r
773Routine Description:\r
774\r
775 Place holder function until all the Boot Services and Runtime Services are available\r
776\r
777Arguments:\r
778\r
779 Arg1 - Undefined\r
780 \r
781 Arg2 - Undefined\r
782 \r
783 Arg3 - Undefined\r
784 \r
785 Arg4 - Undefined\r
786 \r
787 Arg5 - Undefined\r
788\r
789Returns:\r
790\r
791 EFI_NOT_AVAILABLE_YET\r
792\r
793--*/\r
794{\r
795 //\r
796 // This function should never be executed. If it does, then the architectural protocols\r
797 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
798 // DXE Core and all the Architectural Protocols are complete.\r
799 //\r
800\r
801 return EFI_NOT_AVAILABLE_YET;\r
802}\r
803\r
804\r
805EFI_STATUS\r
806CoreGetPeiProtocol (\r
807 IN EFI_GUID *ProtocolGuid,\r
808 IN VOID **Interface\r
809 )\r
810/*++\r
811\r
812Routine Description:\r
813\r
814 Searches for a Protocol Interface passed from PEI through a HOB\r
815\r
816Arguments:\r
817\r
818 ProtocolGuid - The Protocol GUID to search for in the HOB List\r
819\r
820 Interface - A pointer to the interface for the Protocol GUID\r
821\r
822Returns:\r
823\r
824 EFI_SUCCESS - The Protocol GUID was found and its interface is returned in Interface\r
825\r
826 EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List\r
827\r
828--*/\r
829{\r
830 EFI_HOB_GUID_TYPE *GuidHob;\r
831 VOID *Buffer;\r
832\r
833 GuidHob = GetNextGuidHob (ProtocolGuid, mHobStart);\r
834 if (GuidHob == NULL) {\r
835 return EFI_NOT_FOUND;\r
836 }\r
837 \r
838 Buffer = GET_GUID_HOB_DATA (GuidHob);\r
839 ASSERT (Buffer != NULL);\r
840\r
841 *Interface = (VOID *)(*(UINTN *)(Buffer));\r
842\r
843 return EFI_SUCCESS;\r
844}\r
845\r
846\r
847VOID\r
848CalculateEfiHdrCrc (\r
849 IN OUT EFI_TABLE_HEADER *Hdr\r
850 )\r
851/*++\r
852\r
853Routine Description:\r
854\r
855 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
856 gRuntime service.\r
857\r
858Arguments:\r
859\r
860 Hdr - Pointer to an EFI standard header\r
861\r
862Returns:\r
863\r
864 None\r
865\r
866--*/\r
867{\r
868 UINT32 Crc;\r
869\r
870 Hdr->CRC32 = 0;\r
871 \r
872 //\r
873 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
874 // Crc will come back as zero if we set it to zero here\r
875 //\r
876 Crc = 0;\r
877 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
878 Hdr->CRC32 = Crc; \r
879}\r
880\r
881\r
882\r
883EFI_STATUS\r
884EFIAPI\r
885CoreExitBootServices (\r
886 IN EFI_HANDLE ImageHandle,\r
887 IN UINTN MapKey\r
888 )\r
889/*++\r
890\r
891Routine Description:\r
892\r
893 EFI 1.0 API to terminate Boot Services\r
894\r
895Arguments:\r
896\r
897 ImageHandle - Handle that represents the identity of the calling image\r
898\r
899 MapKey -Key to the latest memory map.\r
900\r
901Returns:\r
902\r
903 EFI_SUCCESS - Boot Services terminated\r
904 EFI_INVALID_PARAMETER - MapKey is incorrect.\r
905\r
906--*/\r
907{\r
908 EFI_STATUS Status;\r
909\r
910 //\r
911 // Terminate memory services if the MapKey matches\r
912 //\r
913 Status = CoreTerminateMemoryMap (MapKey);\r
914 if (EFI_ERROR (Status)) {\r
915 return Status;\r
916 }\r
917\r
918 //\r
919 // Notify other drivers that we are exiting boot services.\r
920 //\r
921 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
922\r
923 //\r
924 // Disable Timer\r
925 //\r
926 gTimer->SetTimerPeriod (gTimer, 0);\r
927\r
928 //\r
929 // Disable CPU Interrupts\r
930 //\r
931 gCpu->DisableInterrupt (gCpu);\r
932\r
933 //\r
934 // Register Runtime events with the Runtime Architectural Protocol\r
935 //\r
936 CoreShutdownEventServices ();\r
937\r
938 //\r
939 // Register Runtime images with the Runtime Architectural Protocol\r
940 //\r
941 CoreShutdownImageServices ();\r
942\r
943 //\r
944 // Report that ExitBootServices() has been called\r
945 //\r
946 // We are using gEfiDxeServicesTableGuid as the caller ID for Dxe Core\r
947 //\r
948 CoreReportProgressCode ((EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES));\r
949\r
950 //\r
951 // Clear the non-runtime values of the EFI System Table\r
952 //\r
953 gST->BootServices = NULL;\r
954 gST->ConIn = NULL;\r
955 gST->ConsoleInHandle = NULL;\r
956 gST->ConOut = NULL;\r
957 gST->ConsoleOutHandle = NULL;\r
958 gST->StdErr = NULL;\r
959 gST->StandardErrorHandle = NULL;\r
960\r
961 //\r
962 // Recompute the 32-bit CRC of the EFI System Table\r
963 //\r
964 CalculateEfiHdrCrc (&gST->Hdr);\r
965\r
966 //\r
967 // Zero out the Boot Service Table\r
968 //\r
969 SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);\r
970 gBS = NULL;\r
971\r
972 return Status;\r
973}\r
974\r
975EFI_STATUS\r
976DxeMainUefiDecompressGetInfo (\r
977 IN EFI_DECOMPRESS_PROTOCOL *This,\r
978 IN VOID *Source,\r
979 IN UINT32 SourceSize,\r
980 OUT UINT32 *DestinationSize,\r
981 OUT UINT32 *ScratchSize\r
982 )\r
983{\r
984 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
985}\r
986\r
987EFI_STATUS\r
988EFIAPI\r
989DxeMainUefiDecompress (\r
990 IN EFI_DECOMPRESS_PROTOCOL *This,\r
991 IN VOID *Source,\r
992 IN UINT32 SourceSize,\r
993 IN OUT VOID *Destination,\r
994 IN UINT32 DestinationSize,\r
995 IN OUT VOID *Scratch,\r
996 IN UINT32 ScratchSize\r
997 )\r
998{\r
999 EFI_STATUS Status;\r
1000 UINT32 TestDestinationSize;\r
1001 UINT32 TestScratchSize;\r
1002\r
1003 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
1004 if (EFI_ERROR (Status)) {\r
1005 return Status;\r
1006 }\r
1007\r
1008 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
1009 return RETURN_INVALID_PARAMETER;\r
1010 }\r
1011\r
1012 return UefiDecompress (Source, Destination, Scratch);\r
1013}\r
1014\r
1015EFI_STATUS\r
1016DxeMainTianoDecompressGetInfo (\r
1017 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
1018 IN VOID *Source,\r
1019 IN UINT32 SourceSize,\r
1020 OUT UINT32 *DestinationSize,\r
1021 OUT UINT32 *ScratchSize\r
1022 )\r
1023{\r
1024 return TianoDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
1025}\r
1026\r
1027EFI_STATUS\r
1028EFIAPI\r
1029DxeMainTianoDecompress (\r
1030 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
1031 IN VOID *Source,\r
1032 IN UINT32 SourceSize,\r
1033 IN OUT VOID *Destination,\r
1034 IN UINT32 DestinationSize,\r
1035 IN OUT VOID *Scratch,\r
1036 IN UINT32 ScratchSize\r
1037 )\r
1038{\r
1039 EFI_STATUS Status;\r
1040 UINT32 TestDestinationSize;\r
1041 UINT32 TestScratchSize;\r
1042\r
1043 Status = TianoDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
1044 if (EFI_ERROR (Status)) {\r
1045 return Status;\r
1046 }\r
1047\r
1048 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
1049 return RETURN_INVALID_PARAMETER;\r
1050 }\r
1051\r
1052 return TianoDecompress (Source, Destination, Scratch);\r
1053}\r
1054\r
1055EFI_STATUS\r
1056DxeMainCustomDecompressGetInfo (\r
1057 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,\r
1058 IN VOID *Source,\r
1059 IN UINT32 SourceSize,\r
1060 OUT UINT32 *DestinationSize,\r
1061 OUT UINT32 *ScratchSize\r
1062 )\r
1063{\r
1064 return CustomDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
1065}\r
1066\r
1067EFI_STATUS\r
1068EFIAPI\r
1069DxeMainCustomDecompress (\r
1070 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,\r
1071 IN VOID *Source,\r
1072 IN UINT32 SourceSize,\r
1073 IN OUT VOID *Destination,\r
1074 IN UINT32 DestinationSize,\r
1075 IN OUT VOID *Scratch,\r
1076 IN UINT32 ScratchSize\r
1077 )\r
1078{\r
1079 EFI_STATUS Status;\r
1080 UINT32 TestDestinationSize;\r
1081 UINT32 TestScratchSize;\r
1082\r
1083 Status = CustomDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
1084 if (EFI_ERROR (Status)) {\r
1085 return Status;\r
1086 }\r
1087\r
1088 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
1089 return RETURN_INVALID_PARAMETER;\r
1090 }\r
1091\r
1092 return CustomDecompress (Source, Destination, Scratch);\r
1093}\r
1094\r