2 DXE Core Main Entry Point
4 Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // DXE Core Global Variables for Protocols from PEI
14 EFI_HANDLE mDecompressHandle
= NULL
;
17 // DXE Core globals for Architecture Protocols
19 EFI_SECURITY_ARCH_PROTOCOL
*gSecurity
= NULL
;
20 EFI_SECURITY2_ARCH_PROTOCOL
*gSecurity2
= NULL
;
21 EFI_CPU_ARCH_PROTOCOL
*gCpu
= NULL
;
22 EFI_METRONOME_ARCH_PROTOCOL
*gMetronome
= NULL
;
23 EFI_TIMER_ARCH_PROTOCOL
*gTimer
= NULL
;
24 EFI_BDS_ARCH_PROTOCOL
*gBds
= NULL
;
25 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL
*gWatchdogTimer
= NULL
;
28 // DXE Core globals for optional protocol dependencies
30 EFI_SMM_BASE2_PROTOCOL
*gSmmBase2
= NULL
;
33 // DXE Core Global used to update core loaded image protocol handle
35 EFI_GUID
*gDxeCoreFileName
;
36 EFI_LOADED_IMAGE_PROTOCOL
*gDxeCoreLoadedImage
;
39 // DXE Core Module Variables
41 EFI_BOOT_SERVICES mBootServices
= {
43 EFI_BOOT_SERVICES_SIGNATURE
, // Signature
44 EFI_BOOT_SERVICES_REVISION
, // Revision
45 sizeof (EFI_BOOT_SERVICES
), // HeaderSize
49 (EFI_RAISE_TPL
)CoreRaiseTpl
, // RaiseTPL
50 (EFI_RESTORE_TPL
)CoreRestoreTpl
, // RestoreTPL
51 (EFI_ALLOCATE_PAGES
)CoreAllocatePages
, // AllocatePages
52 (EFI_FREE_PAGES
)CoreFreePages
, // FreePages
53 (EFI_GET_MEMORY_MAP
)CoreGetMemoryMap
, // GetMemoryMap
54 (EFI_ALLOCATE_POOL
)CoreAllocatePool
, // AllocatePool
55 (EFI_FREE_POOL
)CoreFreePool
, // FreePool
56 (EFI_CREATE_EVENT
)CoreCreateEvent
, // CreateEvent
57 (EFI_SET_TIMER
)CoreSetTimer
, // SetTimer
58 (EFI_WAIT_FOR_EVENT
)CoreWaitForEvent
, // WaitForEvent
59 (EFI_SIGNAL_EVENT
)CoreSignalEvent
, // SignalEvent
60 (EFI_CLOSE_EVENT
)CoreCloseEvent
, // CloseEvent
61 (EFI_CHECK_EVENT
)CoreCheckEvent
, // CheckEvent
62 (EFI_INSTALL_PROTOCOL_INTERFACE
)CoreInstallProtocolInterface
, // InstallProtocolInterface
63 (EFI_REINSTALL_PROTOCOL_INTERFACE
)CoreReinstallProtocolInterface
, // ReinstallProtocolInterface
64 (EFI_UNINSTALL_PROTOCOL_INTERFACE
)CoreUninstallProtocolInterface
, // UninstallProtocolInterface
65 (EFI_HANDLE_PROTOCOL
)CoreHandleProtocol
, // HandleProtocol
66 (VOID
*)NULL
, // Reserved
67 (EFI_REGISTER_PROTOCOL_NOTIFY
)CoreRegisterProtocolNotify
, // RegisterProtocolNotify
68 (EFI_LOCATE_HANDLE
)CoreLocateHandle
, // LocateHandle
69 (EFI_LOCATE_DEVICE_PATH
)CoreLocateDevicePath
, // LocateDevicePath
70 (EFI_INSTALL_CONFIGURATION_TABLE
)CoreInstallConfigurationTable
, // InstallConfigurationTable
71 (EFI_IMAGE_LOAD
)CoreLoadImage
, // LoadImage
72 (EFI_IMAGE_START
)CoreStartImage
, // StartImage
73 (EFI_EXIT
)CoreExit
, // Exit
74 (EFI_IMAGE_UNLOAD
)CoreUnloadImage
, // UnloadImage
75 (EFI_EXIT_BOOT_SERVICES
)CoreExitBootServices
, // ExitBootServices
76 (EFI_GET_NEXT_MONOTONIC_COUNT
)CoreEfiNotAvailableYetArg1
, // GetNextMonotonicCount
77 (EFI_STALL
)CoreStall
, // Stall
78 (EFI_SET_WATCHDOG_TIMER
)CoreSetWatchdogTimer
, // SetWatchdogTimer
79 (EFI_CONNECT_CONTROLLER
)CoreConnectController
, // ConnectController
80 (EFI_DISCONNECT_CONTROLLER
)CoreDisconnectController
, // DisconnectController
81 (EFI_OPEN_PROTOCOL
)CoreOpenProtocol
, // OpenProtocol
82 (EFI_CLOSE_PROTOCOL
)CoreCloseProtocol
, // CloseProtocol
83 (EFI_OPEN_PROTOCOL_INFORMATION
)CoreOpenProtocolInformation
, // OpenProtocolInformation
84 (EFI_PROTOCOLS_PER_HANDLE
)CoreProtocolsPerHandle
, // ProtocolsPerHandle
85 (EFI_LOCATE_HANDLE_BUFFER
)CoreLocateHandleBuffer
, // LocateHandleBuffer
86 (EFI_LOCATE_PROTOCOL
)CoreLocateProtocol
, // LocateProtocol
87 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES
)CoreInstallMultipleProtocolInterfaces
, // InstallMultipleProtocolInterfaces
88 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
)CoreUninstallMultipleProtocolInterfaces
, // UninstallMultipleProtocolInterfaces
89 (EFI_CALCULATE_CRC32
)CoreEfiNotAvailableYetArg3
, // CalculateCrc32
90 (EFI_COPY_MEM
)CopyMem
, // CopyMem
91 (EFI_SET_MEM
)SetMem
, // SetMem
92 (EFI_CREATE_EVENT_EX
)CoreCreateEventEx
// CreateEventEx
95 EFI_DXE_SERVICES mDxeServices
= {
97 DXE_SERVICES_SIGNATURE
, // Signature
98 DXE_SERVICES_REVISION
, // Revision
99 sizeof (DXE_SERVICES
), // HeaderSize
103 (EFI_ADD_MEMORY_SPACE
)CoreAddMemorySpace
, // AddMemorySpace
104 (EFI_ALLOCATE_MEMORY_SPACE
)CoreAllocateMemorySpace
, // AllocateMemorySpace
105 (EFI_FREE_MEMORY_SPACE
)CoreFreeMemorySpace
, // FreeMemorySpace
106 (EFI_REMOVE_MEMORY_SPACE
)CoreRemoveMemorySpace
, // RemoveMemorySpace
107 (EFI_GET_MEMORY_SPACE_DESCRIPTOR
)CoreGetMemorySpaceDescriptor
, // GetMemorySpaceDescriptor
108 (EFI_SET_MEMORY_SPACE_ATTRIBUTES
)CoreSetMemorySpaceAttributes
, // SetMemorySpaceAttributes
109 (EFI_GET_MEMORY_SPACE_MAP
)CoreGetMemorySpaceMap
, // GetMemorySpaceMap
110 (EFI_ADD_IO_SPACE
)CoreAddIoSpace
, // AddIoSpace
111 (EFI_ALLOCATE_IO_SPACE
)CoreAllocateIoSpace
, // AllocateIoSpace
112 (EFI_FREE_IO_SPACE
)CoreFreeIoSpace
, // FreeIoSpace
113 (EFI_REMOVE_IO_SPACE
)CoreRemoveIoSpace
, // RemoveIoSpace
114 (EFI_GET_IO_SPACE_DESCRIPTOR
)CoreGetIoSpaceDescriptor
, // GetIoSpaceDescriptor
115 (EFI_GET_IO_SPACE_MAP
)CoreGetIoSpaceMap
, // GetIoSpaceMap
116 (EFI_DISPATCH
)CoreDispatcher
, // Dispatch
117 (EFI_SCHEDULE
)CoreSchedule
, // Schedule
118 (EFI_TRUST
)CoreTrust
, // Trust
119 (EFI_PROCESS_FIRMWARE_VOLUME
)CoreProcessFirmwareVolume
, // ProcessFirmwareVolume
120 (EFI_SET_MEMORY_SPACE_CAPABILITIES
)CoreSetMemorySpaceCapabilities
, // SetMemorySpaceCapabilities
123 EFI_SYSTEM_TABLE mEfiSystemTableTemplate
= {
125 EFI_SYSTEM_TABLE_SIGNATURE
, // Signature
126 EFI_SYSTEM_TABLE_REVISION
, // Revision
127 sizeof (EFI_SYSTEM_TABLE
), // HeaderSize
131 NULL
, // FirmwareVendor
132 0, // FirmwareRevision
133 NULL
, // ConsoleInHandle
135 NULL
, // ConsoleOutHandle
137 NULL
, // StandardErrorHandle
139 NULL
, // RuntimeServices
140 &mBootServices
, // BootServices
141 0, // NumberOfConfigurationTableEntries
142 NULL
// ConfigurationTable
145 EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate
= {
147 EFI_RUNTIME_SERVICES_SIGNATURE
, // Signature
148 EFI_RUNTIME_SERVICES_REVISION
, // Revision
149 sizeof (EFI_RUNTIME_SERVICES
), // HeaderSize
153 (EFI_GET_TIME
)CoreEfiNotAvailableYetArg2
, // GetTime
154 (EFI_SET_TIME
)CoreEfiNotAvailableYetArg1
, // SetTime
155 (EFI_GET_WAKEUP_TIME
)CoreEfiNotAvailableYetArg3
, // GetWakeupTime
156 (EFI_SET_WAKEUP_TIME
)CoreEfiNotAvailableYetArg2
, // SetWakeupTime
157 (EFI_SET_VIRTUAL_ADDRESS_MAP
)CoreEfiNotAvailableYetArg4
, // SetVirtualAddressMap
158 (EFI_CONVERT_POINTER
)CoreEfiNotAvailableYetArg2
, // ConvertPointer
159 (EFI_GET_VARIABLE
)CoreEfiNotAvailableYetArg5
, // GetVariable
160 (EFI_GET_NEXT_VARIABLE_NAME
)CoreEfiNotAvailableYetArg3
, // GetNextVariableName
161 (EFI_SET_VARIABLE
)CoreEfiNotAvailableYetArg5
, // SetVariable
162 (EFI_GET_NEXT_HIGH_MONO_COUNT
)CoreEfiNotAvailableYetArg1
, // GetNextHighMonotonicCount
163 (EFI_RESET_SYSTEM
)CoreEfiNotAvailableYetArg4
, // ResetSystem
164 (EFI_UPDATE_CAPSULE
)CoreEfiNotAvailableYetArg3
, // UpdateCapsule
165 (EFI_QUERY_CAPSULE_CAPABILITIES
)CoreEfiNotAvailableYetArg4
, // QueryCapsuleCapabilities
166 (EFI_QUERY_VARIABLE_INFO
)CoreEfiNotAvailableYetArg4
// QueryVariableInfo
169 EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate
= {
170 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate
.ImageHead
),
171 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate
.EventHead
),
174 // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will
175 // prevent people from having pointer math bugs in their code.
176 // now you have to use *DescriptorSize to make things work.
178 sizeof (EFI_MEMORY_DESCRIPTOR
) + sizeof (UINT64
) - (sizeof (EFI_MEMORY_DESCRIPTOR
) % sizeof (UINT64
)),
179 EFI_MEMORY_DESCRIPTOR_VERSION
,
187 EFI_RUNTIME_ARCH_PROTOCOL
*gRuntime
= &gRuntimeTemplate
;
190 // DXE Core Global Variables for the EFI System Table, Boot Services Table,
191 // DXE Services Table, and Runtime Services Table
193 EFI_DXE_SERVICES
*gDxeCoreDS
= &mDxeServices
;
194 EFI_SYSTEM_TABLE
*gDxeCoreST
= NULL
;
197 // For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
198 // but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
199 // a value that will not cause debug infrastructure to crash early on.
201 EFI_RUNTIME_SERVICES
*gDxeCoreRT
= &mEfiRuntimeServicesTableTemplate
;
202 EFI_HANDLE gDxeCoreImageHandle
= NULL
;
204 BOOLEAN gMemoryMapTerminated
= FALSE
;
207 // EFI Decompress Protocol
209 EFI_DECOMPRESS_PROTOCOL gEfiDecompress
= {
210 DxeMainUefiDecompressGetInfo
,
211 DxeMainUefiDecompress
215 // For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load
216 // Runtime code&boot time code
218 GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable
= { 0, 0 };
220 // Main entry point to the DXE Core
224 Main entry point to DXE Core.
226 @param HobStart Pointer to the beginning of the HOB List from PEI.
228 @return This function should never return.
238 EFI_PHYSICAL_ADDRESS MemoryBaseAddress
;
240 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
242 EFI_HOB_GUID_TYPE
*GuidHob
;
243 EFI_VECTOR_HANDOFF_INFO
*VectorInfoList
;
244 EFI_VECTOR_HANDOFF_INFO
*VectorInfo
;
248 // Setup the default exception handlers
250 VectorInfoList
= NULL
;
251 GuidHob
= GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid
, HobStart
);
252 if (GuidHob
!= NULL
) {
253 VectorInfoList
= (EFI_VECTOR_HANDOFF_INFO
*)(GET_GUID_HOB_DATA (GuidHob
));
256 Status
= InitializeCpuExceptionHandlers (VectorInfoList
);
257 ASSERT_EFI_ERROR (Status
);
262 if (PcdGetBool (PcdCpuStackGuard
)) {
263 Status
= InitializeSeparateExceptionStacks (NULL
, NULL
);
264 ASSERT_EFI_ERROR (Status
);
268 // Initialize Debug Agent to support source level debug in DXE phase
270 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE
, HobStart
, NULL
);
273 // Initialize Memory Services
275 CoreInitializeMemoryServices (&HobStart
, &MemoryBaseAddress
, &MemoryLength
);
277 MemoryProfileInit (HobStart
);
280 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
281 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
283 gDxeCoreST
= AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE
), &mEfiSystemTableTemplate
);
284 ASSERT (gDxeCoreST
!= NULL
);
286 gDxeCoreRT
= AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES
), &mEfiRuntimeServicesTableTemplate
);
287 ASSERT (gDxeCoreRT
!= NULL
);
289 gDxeCoreST
->RuntimeServices
= gDxeCoreRT
;
292 // Start the Image Services.
294 Status
= CoreInitializeImageServices (HobStart
);
295 ASSERT_EFI_ERROR (Status
);
298 // Initialize the Global Coherency Domain Services
300 Status
= CoreInitializeGcdServices (&HobStart
, MemoryBaseAddress
, MemoryLength
);
301 ASSERT_EFI_ERROR (Status
);
304 // Call constructor for all libraries
306 ProcessLibraryConstructorList (gDxeCoreImageHandle
, gDxeCoreST
);
307 PERF_CROSSMODULE_END ("PEI");
308 PERF_CROSSMODULE_BEGIN ("DXE");
311 // Log MemoryBaseAddress and MemoryLength again (from
312 // CoreInitializeMemoryServices()), now that library constructors have
317 "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
324 // Report DXE Core image information to the PE/COFF Extra Action Library
326 ZeroMem (&ImageContext
, sizeof (ImageContext
));
327 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)gDxeCoreLoadedImage
->ImageBase
;
328 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*)(UINTN
)ImageContext
.ImageAddress
);
329 ImageContext
.SizeOfHeaders
= PeCoffGetSizeOfHeaders ((VOID
*)(UINTN
)ImageContext
.ImageAddress
);
330 Status
= PeCoffLoaderGetEntryPoint ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, &EntryPoint
);
331 if (Status
== EFI_SUCCESS
) {
332 ImageContext
.EntryPoint
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)EntryPoint
;
335 ImageContext
.Handle
= (VOID
*)(UINTN
)gDxeCoreLoadedImage
->ImageBase
;
336 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
337 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
340 // Install the DXE Services Table into the EFI System Tables's Configuration Table
342 Status
= CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid
, gDxeCoreDS
);
343 ASSERT_EFI_ERROR (Status
);
346 // Install the HOB List into the EFI System Tables's Configuration Table
348 Status
= CoreInstallConfigurationTable (&gEfiHobListGuid
, HobStart
);
349 ASSERT_EFI_ERROR (Status
);
352 // Install Memory Type Information Table into the EFI System Tables's Configuration Table
354 Status
= CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid
, &gMemoryTypeInformation
);
355 ASSERT_EFI_ERROR (Status
);
358 // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address
359 // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI
360 // Code and Tseg base to load SMM driver.
362 if (PcdGet64 (PcdLoadModuleAtFixAddressEnable
) != 0) {
363 Status
= CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid
, &gLoadModuleAtFixAddressConfigurationTable
);
364 ASSERT_EFI_ERROR (Status
);
368 // Report Status Code here for DXE_ENTRY_POINT once it is available
372 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_DXE_CORE_PC_ENTRY_POINT
)
376 // Create the aligned system table pointer structure that is used by external
377 // debuggers to locate the system table... Also, install debug image info
378 // configuration table.
380 CoreInitializeDebugImageInfoTable ();
381 CoreNewDebugImageInfoEntry (
382 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL
,
387 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "HOBLIST address in DXE = 0x%p\n", HobStart
));
390 EFI_PEI_HOB_POINTERS Hob
;
392 for (Hob
.Raw
= HobStart
; !END_OF_HOB_LIST (Hob
); Hob
.Raw
= GET_NEXT_HOB (Hob
)) {
393 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
395 DEBUG_INFO
| DEBUG_LOAD
,
396 "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
397 Hob
.MemoryAllocation
->AllocDescriptor
.MemoryType
, \
398 Hob
.MemoryAllocation
->AllocDescriptor
.MemoryBaseAddress
, \
399 Hob
.MemoryAllocation
->AllocDescriptor
.MemoryBaseAddress
+ Hob
.MemoryAllocation
->AllocDescriptor
.MemoryLength
- 1
404 for (Hob
.Raw
= HobStart
; !END_OF_HOB_LIST (Hob
); Hob
.Raw
= GET_NEXT_HOB (Hob
)) {
405 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_FV
) {
407 DEBUG_INFO
| DEBUG_LOAD
,
408 "FV Hob 0x%0lx - 0x%0lx\n",
409 Hob
.FirmwareVolume
->BaseAddress
,
410 Hob
.FirmwareVolume
->BaseAddress
+ Hob
.FirmwareVolume
->Length
- 1
412 } else if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_FV2
) {
414 DEBUG_INFO
| DEBUG_LOAD
,
415 "FV2 Hob 0x%0lx - 0x%0lx\n",
416 Hob
.FirmwareVolume2
->BaseAddress
,
417 Hob
.FirmwareVolume2
->BaseAddress
+ Hob
.FirmwareVolume2
->Length
- 1
420 DEBUG_INFO
| DEBUG_LOAD
,
422 &Hob
.FirmwareVolume2
->FvName
,
423 &Hob
.FirmwareVolume2
->FileName
425 } else if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_FV3
) {
427 DEBUG_INFO
| DEBUG_LOAD
,
428 "FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",
429 Hob
.FirmwareVolume3
->BaseAddress
,
430 Hob
.FirmwareVolume3
->BaseAddress
+ Hob
.FirmwareVolume3
->Length
- 1,
431 Hob
.FirmwareVolume3
->AuthenticationStatus
,
432 Hob
.FirmwareVolume3
->ExtractedFv
434 if (Hob
.FirmwareVolume3
->ExtractedFv
) {
436 DEBUG_INFO
| DEBUG_LOAD
,
438 &Hob
.FirmwareVolume3
->FvName
,
439 &Hob
.FirmwareVolume3
->FileName
448 // Initialize the Event Services
450 Status
= CoreInitializeEventServices ();
451 ASSERT_EFI_ERROR (Status
);
453 MemoryProfileInstallProtocol ();
455 CoreInitializeMemoryAttributesTable ();
456 CoreInitializeMemoryProtection ();
459 // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,
460 // and install configuration table
462 GuidHob
= GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid
, HobStart
);
463 if (GuidHob
!= NULL
) {
464 VectorInfoList
= (EFI_VECTOR_HANDOFF_INFO
*)(GET_GUID_HOB_DATA (GuidHob
));
465 VectorInfo
= VectorInfoList
;
467 while (VectorInfo
->Attribute
!= EFI_VECTOR_HANDOFF_LAST_ENTRY
) {
472 VectorInfo
= AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO
) * Index
, (VOID
*)VectorInfoList
);
473 ASSERT (VectorInfo
!= NULL
);
474 Status
= CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid
, (VOID
*)VectorInfo
);
475 ASSERT_EFI_ERROR (Status
);
479 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
481 // These Protocols are not architectural. This implementation is sharing code between
482 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented
483 // as part of the DXE Core. However, that would also require the DXE Core to be ported
484 // each time a different CPU is used, a different Decompression algorithm is used, or a
485 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains
486 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,
487 // and from CPU to CPU.
491 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components
493 Status
= CoreInstallMultipleProtocolInterfaces (
495 &gEfiDecompressProtocolGuid
,
499 ASSERT_EFI_ERROR (Status
);
502 // Register for the GUIDs of the Architectural Protocols, so the rest of the
503 // EFI Boot Services and EFI Runtime Services tables can be filled in.
504 // Also register for the GUIDs of optional protocols.
506 CoreNotifyOnProtocolInstallation ();
509 // Produce Firmware Volume Protocols, one for each FV in the HOB list.
511 Status
= FwVolBlockDriverInit (gDxeCoreImageHandle
, gDxeCoreST
);
512 ASSERT_EFI_ERROR (Status
);
514 Status
= FwVolDriverInit (gDxeCoreImageHandle
, gDxeCoreST
);
515 ASSERT_EFI_ERROR (Status
);
518 // Produce the Section Extraction Protocol
520 Status
= InitializeSectionExtraction (gDxeCoreImageHandle
, gDxeCoreST
);
521 ASSERT_EFI_ERROR (Status
);
524 // Initialize the DXE Dispatcher
526 CoreInitializeDispatcher ();
529 // Invoke the DXE Dispatcher
534 // Display Architectural protocols that were not loaded if this is DEBUG build
537 CoreDisplayMissingArchProtocols ();
541 // Display any drivers that were not dispatched because dependency expression
542 // evaluated to false if this is a debug build
545 CoreDisplayDiscoveredNotDispatched ();
549 // Assert if the Architectural Protocols are not present.
551 Status
= CoreAllEfiServicesAvailable ();
552 if (EFI_ERROR (Status
)) {
554 // Report Status code that some Architectural Protocols are not present.
557 EFI_ERROR_CODE
| EFI_ERROR_MAJOR
,
558 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_DXE_CORE_EC_NO_ARCH
)
562 ASSERT_EFI_ERROR (Status
);
565 // Report Status code before transfer control to BDS
569 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT
)
573 // Transfer control to the BDS Architectural Protocol
578 // BDS should never return
587 Place holder function until all the Boot Services and Runtime Services are
590 @param Arg1 Undefined
592 @return EFI_NOT_AVAILABLE_YET
597 CoreEfiNotAvailableYetArg1 (
602 // This function should never be executed. If it does, then the architectural protocols
603 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
604 // DXE Core and all the Architectural Protocols are complete.
607 return EFI_NOT_AVAILABLE_YET
;
611 Place holder function until all the Boot Services and Runtime Services are available.
613 @param Arg1 Undefined
614 @param Arg2 Undefined
616 @return EFI_NOT_AVAILABLE_YET
621 CoreEfiNotAvailableYetArg2 (
627 // This function should never be executed. If it does, then the architectural protocols
628 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
629 // DXE Core and all the Architectural Protocols are complete.
632 return EFI_NOT_AVAILABLE_YET
;
636 Place holder function until all the Boot Services and Runtime Services are available.
638 @param Arg1 Undefined
639 @param Arg2 Undefined
640 @param Arg3 Undefined
642 @return EFI_NOT_AVAILABLE_YET
647 CoreEfiNotAvailableYetArg3 (
654 // This function should never be executed. If it does, then the architectural protocols
655 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
656 // DXE Core and all the Architectural Protocols are complete.
659 return EFI_NOT_AVAILABLE_YET
;
663 Place holder function until all the Boot Services and Runtime Services are available.
665 @param Arg1 Undefined
666 @param Arg2 Undefined
667 @param Arg3 Undefined
668 @param Arg4 Undefined
670 @return EFI_NOT_AVAILABLE_YET
675 CoreEfiNotAvailableYetArg4 (
683 // This function should never be executed. If it does, then the architectural protocols
684 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
685 // DXE Core and all the Architectural Protocols are complete.
688 return EFI_NOT_AVAILABLE_YET
;
692 Place holder function until all the Boot Services and Runtime Services are available.
694 @param Arg1 Undefined
695 @param Arg2 Undefined
696 @param Arg3 Undefined
697 @param Arg4 Undefined
698 @param Arg5 Undefined
700 @return EFI_NOT_AVAILABLE_YET
705 CoreEfiNotAvailableYetArg5 (
714 // This function should never be executed. If it does, then the architectural protocols
715 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
716 // DXE Core and all the Architectural Protocols are complete.
719 return EFI_NOT_AVAILABLE_YET
;
723 Calcualte the 32-bit CRC in a EFI table using the service provided by the
726 @param Hdr Pointer to an EFI standard header
731 IN OUT EFI_TABLE_HEADER
*Hdr
739 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
740 // Crc will come back as zero if we set it to zero here
743 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
748 Terminates all boot services.
750 @param ImageHandle Handle that identifies the exiting image.
751 @param MapKey Key to the latest memory map.
753 @retval EFI_SUCCESS Boot Services terminated
754 @retval EFI_INVALID_PARAMETER MapKey is incorrect.
759 CoreExitBootServices (
760 IN EFI_HANDLE ImageHandle
,
767 // Notify other drivers of their last chance to use boot services
768 // before the memory map is terminated.
770 CoreNotifySignalList (&gEfiEventBeforeExitBootServicesGuid
);
775 gTimer
->SetTimerPeriod (gTimer
, 0);
778 // Terminate memory services if the MapKey matches
780 Status
= CoreTerminateMemoryMap (MapKey
);
781 if (EFI_ERROR (Status
)) {
783 // Notify other drivers that ExitBootServices fail
785 CoreNotifySignalList (&gEventExitBootServicesFailedGuid
);
789 gMemoryMapTerminated
= TRUE
;
792 // Notify other drivers that we are exiting boot services.
794 CoreNotifySignalList (&gEfiEventExitBootServicesGuid
);
797 // Report that ExitBootServices() has been called
801 (EFI_SOFTWARE_EFI_BOOT_SERVICE
| EFI_SW_BS_PC_EXIT_BOOT_SERVICES
)
804 MemoryProtectionExitBootServicesCallback ();
807 // Disable interrupt of Debug timer.
809 SaveAndSetDebugTimerInterrupt (FALSE
);
812 // Disable CPU Interrupts
814 gCpu
->DisableInterrupt (gCpu
);
817 // Clear the non-runtime values of the EFI System Table
819 gDxeCoreST
->BootServices
= NULL
;
820 gDxeCoreST
->ConIn
= NULL
;
821 gDxeCoreST
->ConsoleInHandle
= NULL
;
822 gDxeCoreST
->ConOut
= NULL
;
823 gDxeCoreST
->ConsoleOutHandle
= NULL
;
824 gDxeCoreST
->StdErr
= NULL
;
825 gDxeCoreST
->StandardErrorHandle
= NULL
;
828 // Recompute the 32-bit CRC of the EFI System Table
830 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
833 // Zero out the Boot Service Table
835 ZeroMem (gBS
, sizeof (EFI_BOOT_SERVICES
));
839 // Update the AtRuntime field in Runtiem AP.
841 gRuntime
->AtRuntime
= TRUE
;
847 Given a compressed source buffer, this function retrieves the size of the
848 uncompressed buffer and the size of the scratch buffer required to decompress
849 the compressed source buffer.
851 The GetInfo() function retrieves the size of the uncompressed buffer and the
852 temporary scratch buffer required to decompress the buffer specified by Source
853 and SourceSize. If the size of the uncompressed buffer or the size of the
854 scratch buffer cannot be determined from the compressed data specified by
855 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the
856 size of the uncompressed buffer is returned in DestinationSize, the size of
857 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
858 The GetInfo() function does not have scratch buffer available to perform a
859 thorough checking of the validity of the source data. It just retrieves the
860 "Original Size" field from the beginning bytes of the source data and output
861 it as DestinationSize. And ScratchSize is specific to the decompression
864 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
865 @param Source The source buffer containing the compressed data.
866 @param SourceSize The size, in bytes, of the source buffer.
867 @param DestinationSize A pointer to the size, in bytes, of the
868 uncompressed buffer that will be generated when the
869 compressed buffer specified by Source and
870 SourceSize is decompressed.
871 @param ScratchSize A pointer to the size, in bytes, of the scratch
872 buffer that is required to decompress the
873 compressed buffer specified by Source and
876 @retval EFI_SUCCESS The size of the uncompressed data was returned in
877 DestinationSize and the size of the scratch buffer
878 was returned in ScratchSize.
879 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of
880 the scratch buffer cannot be determined from the
881 compressed data specified by Source and
887 DxeMainUefiDecompressGetInfo (
888 IN EFI_DECOMPRESS_PROTOCOL
*This
,
890 IN UINT32 SourceSize
,
891 OUT UINT32
*DestinationSize
,
892 OUT UINT32
*ScratchSize
895 if ((Source
== NULL
) || (DestinationSize
== NULL
) || (ScratchSize
== NULL
)) {
896 return EFI_INVALID_PARAMETER
;
899 return UefiDecompressGetInfo (Source
, SourceSize
, DestinationSize
, ScratchSize
);
903 Decompresses a compressed source buffer.
905 The Decompress() function extracts decompressed data to its original form.
906 This protocol is designed so that the decompression algorithm can be
907 implemented without using any memory services. As a result, the Decompress()
908 Function is not allowed to call AllocatePool() or AllocatePages() in its
909 implementation. It is the caller's responsibility to allocate and free the
910 Destination and Scratch buffers.
911 If the compressed source data specified by Source and SourceSize is
912 successfully decompressed into Destination, then EFI_SUCCESS is returned. If
913 the compressed source data specified by Source and SourceSize is not in a
914 valid compressed data format, then EFI_INVALID_PARAMETER is returned.
916 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
917 @param Source The source buffer containing the compressed data.
918 @param SourceSize SourceSizeThe size of source data.
919 @param Destination On output, the destination buffer that contains
920 the uncompressed data.
921 @param DestinationSize The size of the destination buffer. The size of
922 the destination buffer needed is obtained from
923 EFI_DECOMPRESS_PROTOCOL.GetInfo().
924 @param Scratch A temporary scratch buffer that is used to perform
926 @param ScratchSize The size of scratch buffer. The size of the
927 scratch buffer needed is obtained from GetInfo().
929 @retval EFI_SUCCESS Decompression completed successfully, and the
930 uncompressed buffer is returned in Destination.
931 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and
932 SourceSize is corrupted (not in a valid
938 DxeMainUefiDecompress (
939 IN EFI_DECOMPRESS_PROTOCOL
*This
,
941 IN UINT32 SourceSize
,
942 IN OUT VOID
*Destination
,
943 IN UINT32 DestinationSize
,
944 IN OUT VOID
*Scratch
,
945 IN UINT32 ScratchSize
949 UINT32 TestDestinationSize
;
950 UINT32 TestScratchSize
;
952 if ((Source
== NULL
) || (Destination
== NULL
) || (Scratch
== NULL
)) {
953 return EFI_INVALID_PARAMETER
;
956 Status
= UefiDecompressGetInfo (Source
, SourceSize
, &TestDestinationSize
, &TestScratchSize
);
957 if (EFI_ERROR (Status
)) {
961 if ((ScratchSize
< TestScratchSize
) || (DestinationSize
< TestDestinationSize
)) {
962 return RETURN_INVALID_PARAMETER
;
965 return UefiDecompress (Source
, Destination
, Scratch
);