]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
MdeModulePkg/Core/Dxe: log memory base and length, after lib ctors again
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
CommitLineData
31f228cf 1/** @file\r
2 DXE Core Main Entry Point\r
3\r
bce776a5 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
31f228cf 6\r
7**/\r
8\r
9#include "DxeMain.h"\r
10\r
11//\r
12// DXE Core Global Variables for Protocols from PEI\r
13//\r
14EFI_HANDLE mDecompressHandle = NULL;\r
15\r
16//\r
17// DXE Core globals for Architecture Protocols\r
18//\r
19EFI_SECURITY_ARCH_PROTOCOL *gSecurity = NULL;\r
bc2dfdbc 20EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2 = NULL;\r
31f228cf 21EFI_CPU_ARCH_PROTOCOL *gCpu = NULL;\r
22EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;\r
23EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;\r
24EFI_BDS_ARCH_PROTOCOL *gBds = NULL;\r
25EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;\r
26\r
0803854b 27//\r
28// DXE Core globals for optional protocol dependencies\r
29//\r
30EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;\r
31\r
31f228cf 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
771ee501 120 (EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities, // SetMemorySpaceCapabilities\r
31f228cf 121};\r
122\r
123EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {\r
124 {\r
125 EFI_SYSTEM_TABLE_SIGNATURE, // Signature\r
126 EFI_SYSTEM_TABLE_REVISION, // Revision\r
127 sizeof (EFI_SYSTEM_TABLE), // HeaderSize\r
128 0, // CRC32\r
129 0 // Reserved\r
130 },\r
131 NULL, // FirmwareVendor\r
132 0, // FirmwareRevision\r
133 NULL, // ConsoleInHandle\r
134 NULL, // ConIn\r
135 NULL, // ConsoleOutHandle\r
136 NULL, // ConOut\r
137 NULL, // StandardErrorHandle\r
138 NULL, // StdErr\r
139 NULL, // RuntimeServices\r
140 &mBootServices, // BootServices\r
141 0, // NumberOfConfigurationTableEntries\r
142 NULL // ConfigurationTable\r
143};\r
144\r
145EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {\r
146 {\r
147 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature\r
148 EFI_RUNTIME_SERVICES_REVISION, // Revision\r
149 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize\r
150 0, // CRC32\r
151 0 // Reserved\r
152 },\r
153 (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime\r
154 (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime\r
155 (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime\r
156 (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime\r
157 (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap\r
158 (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer\r
159 (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable\r
160 (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName\r
161 (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable\r
162 (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount\r
163 (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem\r
164 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule\r
165 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities\r
166 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo\r
167};\r
168\r
169EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
170 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
171 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
172\r
173 //\r
174 // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
175 // prevent people from having pointer math bugs in their code.\r
176 // now you have to use *DescriptorSize to make things work.\r
177 //\r
178 sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r
179 EFI_MEMORY_DESCRIPTOR_VERSION,\r
180 0,\r
181 NULL,\r
182 NULL,\r
183 FALSE,\r
184 FALSE\r
185};\r
186\r
187EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
188\r
189//\r
190// DXE Core Global Variables for the EFI System Table, Boot Services Table,\r
191// DXE Services Table, and Runtime Services Table\r
192//\r
193EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;\r
194EFI_SYSTEM_TABLE *gDxeCoreST = NULL;\r
195\r
196//\r
197// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
198// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
199// a value that will not cause debug infrastructure to crash early on.\r
200//\r
201EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
202EFI_HANDLE gDxeCoreImageHandle = NULL;\r
203\r
74a88770 204BOOLEAN gMemoryMapTerminated = FALSE;\r
31f228cf 205\r
206//\r
207// EFI Decompress Protocol\r
208//\r
209EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {\r
210 DxeMainUefiDecompressGetInfo,\r
211 DxeMainUefiDecompress\r
212};\r
213\r
214//\r
e7af83ae 215// For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load\r
216// Runtime code&boot time code\r
54ea99a7 217//\r
ebfb7bb5 218GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = {0, 0};\r
54ea99a7 219\r
31f228cf 220// Main entry point to the DXE Core\r
221//\r
222\r
223/**\r
224 Main entry point to DXE Core.\r
225\r
226 @param HobStart Pointer to the beginning of the HOB List from PEI.\r
227\r
228 @return This function should never return.\r
229\r
230**/\r
231VOID\r
232EFIAPI\r
233DxeMain (\r
234 IN VOID *HobStart\r
235 )\r
236{\r
d0d41b52 237 EFI_STATUS Status;\r
238 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
239 UINT64 MemoryLength;\r
240 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
57f360f2
JF
241 UINTN Index;\r
242 EFI_HOB_GUID_TYPE *GuidHob;\r
243 EFI_VECTOR_HANDOFF_INFO *VectorInfoList;\r
244 EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r
1cf4e933 245 VOID *EntryPoint;\r
31f228cf 246\r
1e172d6b 247 //\r
248 // Setup the default exception handlers\r
249 //\r
57f360f2
JF
250 VectorInfoList = NULL;\r
251 GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
252 if (GuidHob != NULL) {\r
253 VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));\r
254 }\r
a8ab14d3 255 Status = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);\r
57f360f2 256 ASSERT_EFI_ERROR (Status);\r
d1102dba 257\r
e7af83ae 258 //\r
259 // Initialize Debug Agent to support source level debug in DXE phase\r
260 //\r
4cf7e038 261 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE, HobStart, NULL);\r
e7af83ae 262\r
31f228cf 263 //\r
264 // Initialize Memory Services\r
265 //\r
266 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
267\r
84edd20b
SZ
268 MemoryProfileInit (HobStart);\r
269\r
31f228cf 270 //\r
271 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
272 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
273 //\r
274 gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
275 ASSERT (gDxeCoreST != NULL);\r
276\r
277 gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
278 ASSERT (gDxeCoreRT != NULL);\r
279\r
280 gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
281\r
282 //\r
283 // Start the Image Services.\r
284 //\r
285 Status = CoreInitializeImageServices (HobStart);\r
286 ASSERT_EFI_ERROR (Status);\r
287\r
31f228cf 288 //\r
289 // Initialize the Global Coherency Domain Services\r
290 //\r
291 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
292 ASSERT_EFI_ERROR (Status);\r
293\r
c5d53799
SZ
294 //\r
295 // Call constructor for all libraries\r
296 //\r
297 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
67e9ab84
BD
298 PERF_CROSSMODULE_END ("PEI");\r
299 PERF_CROSSMODULE_BEGIN ("DXE");\r
c5d53799 300\r
1366cd58
LE
301 //\r
302 // Log MemoryBaseAddress and MemoryLength again (from\r
303 // CoreInitializeMemoryServices()), now that library constructors have\r
304 // executed.\r
305 //\r
306 DEBUG ((DEBUG_INFO, "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",\r
307 __FUNCTION__, MemoryBaseAddress, MemoryLength));\r
308\r
31ffa077
SZ
309 //\r
310 // Report DXE Core image information to the PE/COFF Extra Action Library\r
311 //\r
312 ZeroMem (&ImageContext, sizeof (ImageContext));\r
313 ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
314 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress);\r
315 ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress);\r
316 Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint);\r
317 if (Status == EFI_SUCCESS) {\r
318 ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r
319 }\r
dfbc039f
AB
320 ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
321 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
31ffa077
SZ
322 PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
323\r
31f228cf 324 //\r
325 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
326 //\r
327 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
328 ASSERT_EFI_ERROR (Status);\r
329\r
330 //\r
331 // Install the HOB List into the EFI System Tables's Configuration Table\r
332 //\r
333 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
334 ASSERT_EFI_ERROR (Status);\r
335\r
336 //\r
337 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
338 //\r
339 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
340 ASSERT_EFI_ERROR (Status);\r
e7af83ae 341\r
54ea99a7 342 //\r
e7af83ae 343 // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address\r
54ea99a7 344 // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI\r
e7af83ae 345 // Code and Tseg base to load SMM driver.\r
54ea99a7 346 //\r
852081fc 347 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {\r
54ea99a7 348 Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);\r
349 ASSERT_EFI_ERROR (Status);\r
350 }\r
31f228cf 351 //\r
352 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
353 //\r
354 REPORT_STATUS_CODE (\r
355 EFI_PROGRESS_CODE,\r
f9876ecf 356 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)\r
31f228cf 357 );\r
358\r
359 //\r
360 // Create the aligned system table pointer structure that is used by external\r
361 // debuggers to locate the system table... Also, install debug image info\r
362 // configuration table.\r
363 //\r
364 CoreInitializeDebugImageInfoTable ();\r
365 CoreNewDebugImageInfoEntry (\r
366 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
367 gDxeCoreLoadedImage,\r
368 gDxeCoreImageHandle\r
369 );\r
370\r
371 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
372\r
373 DEBUG_CODE_BEGIN ();\r
374 EFI_PEI_HOB_POINTERS Hob;\r
375\r
376 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
377 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
8e90dd6b 378 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \\r
bfef82a1 379 Hob.MemoryAllocation->AllocDescriptor.MemoryType, \\r
31f228cf 380 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \\r
bfef82a1 381 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));\r
31f228cf 382 }\r
383 }\r
384 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
c6037045
SZ
385 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
386 DEBUG ((\r
387 DEBUG_INFO | DEBUG_LOAD,\r
388 "FV Hob 0x%0lx - 0x%0lx\n",\r
389 Hob.FirmwareVolume->BaseAddress,\r
390 Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1\r
391 ));\r
392 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {\r
393 DEBUG ((\r
394 DEBUG_INFO | DEBUG_LOAD,\r
395 "FV2 Hob 0x%0lx - 0x%0lx\n",\r
396 Hob.FirmwareVolume2->BaseAddress,\r
397 Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1\r
398 ));\r
399 DEBUG ((\r
400 DEBUG_INFO | DEBUG_LOAD,\r
401 " %g - %g\n",\r
402 &Hob.FirmwareVolume2->FvName,\r
403 &Hob.FirmwareVolume2->FileName\r
404 ));\r
405 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {\r
406 DEBUG ((\r
407 DEBUG_INFO | DEBUG_LOAD,\r
408 "FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",\r
409 Hob.FirmwareVolume3->BaseAddress,\r
410 Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,\r
411 Hob.FirmwareVolume3->AuthenticationStatus,\r
412 Hob.FirmwareVolume3->ExtractedFv\r
413 ));\r
414 if (Hob.FirmwareVolume3->ExtractedFv) {\r
415 DEBUG ((\r
416 DEBUG_INFO | DEBUG_LOAD,\r
417 " %g - %g\n",\r
418 &Hob.FirmwareVolume3->FvName,\r
419 &Hob.FirmwareVolume3->FileName\r
420 ));\r
421 }\r
31f228cf 422 }\r
423 }\r
424 DEBUG_CODE_END ();\r
425\r
426 //\r
427 // Initialize the Event Services\r
428 //\r
429 Status = CoreInitializeEventServices ();\r
430 ASSERT_EFI_ERROR (Status);\r
431\r
84edd20b
SZ
432 MemoryProfileInstallProtocol ();\r
433\r
a94d51bd 434 CoreInitializeMemoryAttributesTable ();\r
d0e92aad 435 CoreInitializeMemoryProtection ();\r
03d486b2 436\r
57f360f2
JF
437 //\r
438 // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,\r
439 // and install configuration table\r
440 //\r
441 GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
442 if (GuidHob != NULL) {\r
443 VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));\r
444 VectorInfo = VectorInfoList;\r
445 Index = 1;\r
446 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
447 VectorInfo ++;\r
448 Index ++;\r
449 }\r
450 VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList);\r
451 ASSERT (VectorInfo != NULL);\r
452 Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo);\r
453 ASSERT_EFI_ERROR (Status);\r
454 }\r
31f228cf 455\r
456 //\r
457 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
458 //\r
459 // These Protocols are not architectural. This implementation is sharing code between\r
460 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
461 // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
462 // each time a different CPU is used, a different Decompression algorithm is used, or a\r
463 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
464 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
465 // and from CPU to CPU.\r
466 //\r
467\r
468 //\r
469 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
470 //\r
471 Status = CoreInstallMultipleProtocolInterfaces (\r
472 &mDecompressHandle,\r
473 &gEfiDecompressProtocolGuid, &gEfiDecompress,\r
474 NULL\r
475 );\r
476 ASSERT_EFI_ERROR (Status);\r
477\r
478 //\r
479 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
480 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
74e44290 481 // Also register for the GUIDs of optional protocols.\r
31f228cf 482 //\r
74e44290 483 CoreNotifyOnProtocolInstallation ();\r
31f228cf 484\r
485 //\r
486 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
487 //\r
488 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
489 ASSERT_EFI_ERROR (Status);\r
490\r
491 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
492 ASSERT_EFI_ERROR (Status);\r
493\r
494 //\r
495 // Produce the Section Extraction Protocol\r
496 //\r
497 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
498 ASSERT_EFI_ERROR (Status);\r
499\r
500 //\r
501 // Initialize the DXE Dispatcher\r
502 //\r
31f228cf 503 CoreInitializeDispatcher ();\r
31f228cf 504\r
505 //\r
506 // Invoke the DXE Dispatcher\r
507 //\r
31f228cf 508 CoreDispatcher ();\r
31f228cf 509\r
510 //\r
511 // Display Architectural protocols that were not loaded if this is DEBUG build\r
512 //\r
513 DEBUG_CODE_BEGIN ();\r
514 CoreDisplayMissingArchProtocols ();\r
515 DEBUG_CODE_END ();\r
516\r
517 //\r
518 // Display any drivers that were not dispatched because dependency expression\r
519 // evaluated to false if this is a debug build\r
520 //\r
521 DEBUG_CODE_BEGIN ();\r
522 CoreDisplayDiscoveredNotDispatched ();\r
523 DEBUG_CODE_END ();\r
524\r
525 //\r
526 // Assert if the Architectural Protocols are not present.\r
527 //\r
37623a5c 528 Status = CoreAllEfiServicesAvailable ();\r
529 if (EFI_ERROR(Status)) {\r
530 //\r
531 // Report Status code that some Architectural Protocols are not present.\r
532 //\r
533 REPORT_STATUS_CODE (\r
534 EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
535 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)\r
d1102dba 536 );\r
37623a5c 537 }\r
538 ASSERT_EFI_ERROR (Status);\r
31f228cf 539\r
540 //\r
541 // Report Status code before transfer control to BDS\r
542 //\r
543 REPORT_STATUS_CODE (\r
544 EFI_PROGRESS_CODE,\r
f9876ecf 545 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)\r
31f228cf 546 );\r
547\r
548 //\r
549 // Transfer control to the BDS Architectural Protocol\r
550 //\r
551 gBds->Entry (gBds);\r
552\r
553 //\r
554 // BDS should never return\r
555 //\r
556 ASSERT (FALSE);\r
557 CpuDeadLoop ();\r
3a7daf9e
MH
558\r
559 UNREACHABLE ();\r
31f228cf 560}\r
561\r
562\r
563\r
31f228cf 564\r
565/**\r
566 Place holder function until all the Boot Services and Runtime Services are\r
567 available.\r
568\r
569 @param Arg1 Undefined\r
570\r
571 @return EFI_NOT_AVAILABLE_YET\r
572\r
573**/\r
574EFI_STATUS\r
575EFIAPI\r
576CoreEfiNotAvailableYetArg1 (\r
577 UINTN Arg1\r
578 )\r
579{\r
580 //\r
581 // This function should never be executed. If it does, then the architectural protocols\r
582 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
583 // DXE Core and all the Architectural Protocols are complete.\r
584 //\r
585\r
586 return EFI_NOT_AVAILABLE_YET;\r
587}\r
588\r
589\r
590/**\r
591 Place holder function until all the Boot Services and Runtime Services are available.\r
592\r
593 @param Arg1 Undefined\r
594 @param Arg2 Undefined\r
595\r
596 @return EFI_NOT_AVAILABLE_YET\r
597\r
598**/\r
599EFI_STATUS\r
600EFIAPI\r
601CoreEfiNotAvailableYetArg2 (\r
602 UINTN Arg1,\r
603 UINTN Arg2\r
604 )\r
605{\r
606 //\r
607 // This function should never be executed. If it does, then the architectural protocols\r
608 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
609 // DXE Core and all the Architectural Protocols are complete.\r
610 //\r
611\r
612 return EFI_NOT_AVAILABLE_YET;\r
613}\r
614\r
615\r
616/**\r
617 Place holder function until all the Boot Services and Runtime Services are available.\r
618\r
619 @param Arg1 Undefined\r
620 @param Arg2 Undefined\r
621 @param Arg3 Undefined\r
622\r
623 @return EFI_NOT_AVAILABLE_YET\r
624\r
625**/\r
626EFI_STATUS\r
627EFIAPI\r
628CoreEfiNotAvailableYetArg3 (\r
629 UINTN Arg1,\r
630 UINTN Arg2,\r
631 UINTN Arg3\r
632 )\r
633{\r
634 //\r
635 // This function should never be executed. If it does, then the architectural protocols\r
636 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
637 // DXE Core and all the Architectural Protocols are complete.\r
638 //\r
639\r
640 return EFI_NOT_AVAILABLE_YET;\r
641}\r
642\r
643\r
644/**\r
645 Place holder function until all the Boot Services and Runtime Services are available.\r
646\r
647 @param Arg1 Undefined\r
648 @param Arg2 Undefined\r
649 @param Arg3 Undefined\r
650 @param Arg4 Undefined\r
651\r
652 @return EFI_NOT_AVAILABLE_YET\r
653\r
654**/\r
655EFI_STATUS\r
656EFIAPI\r
657CoreEfiNotAvailableYetArg4 (\r
658 UINTN Arg1,\r
659 UINTN Arg2,\r
660 UINTN Arg3,\r
661 UINTN Arg4\r
662 )\r
663{\r
664 //\r
665 // This function should never be executed. If it does, then the architectural protocols\r
666 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
667 // DXE Core and all the Architectural Protocols are complete.\r
668 //\r
669\r
670 return EFI_NOT_AVAILABLE_YET;\r
671}\r
672\r
673\r
674/**\r
675 Place holder function until all the Boot Services and Runtime Services are available.\r
676\r
677 @param Arg1 Undefined\r
678 @param Arg2 Undefined\r
679 @param Arg3 Undefined\r
680 @param Arg4 Undefined\r
681 @param Arg5 Undefined\r
682\r
683 @return EFI_NOT_AVAILABLE_YET\r
684\r
685**/\r
686EFI_STATUS\r
687EFIAPI\r
688CoreEfiNotAvailableYetArg5 (\r
689 UINTN Arg1,\r
690 UINTN Arg2,\r
691 UINTN Arg3,\r
692 UINTN Arg4,\r
693 UINTN Arg5\r
694 )\r
695{\r
696 //\r
697 // This function should never be executed. If it does, then the architectural protocols\r
698 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
699 // DXE Core and all the Architectural Protocols are complete.\r
700 //\r
701\r
702 return EFI_NOT_AVAILABLE_YET;\r
703}\r
704\r
705\r
706/**\r
707 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
708 gRuntime service.\r
709\r
710 @param Hdr Pointer to an EFI standard header\r
711\r
712**/\r
713VOID\r
714CalculateEfiHdrCrc (\r
715 IN OUT EFI_TABLE_HEADER *Hdr\r
716 )\r
717{\r
718 UINT32 Crc;\r
719\r
720 Hdr->CRC32 = 0;\r
721\r
722 //\r
723 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
724 // Crc will come back as zero if we set it to zero here\r
725 //\r
726 Crc = 0;\r
727 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
728 Hdr->CRC32 = Crc;\r
729}\r
730\r
731\r
732/**\r
733 Terminates all boot services.\r
734\r
735 @param ImageHandle Handle that identifies the exiting image.\r
736 @param MapKey Key to the latest memory map.\r
737\r
738 @retval EFI_SUCCESS Boot Services terminated\r
739 @retval EFI_INVALID_PARAMETER MapKey is incorrect.\r
740\r
741**/\r
742EFI_STATUS\r
743EFIAPI\r
744CoreExitBootServices (\r
745 IN EFI_HANDLE ImageHandle,\r
746 IN UINTN MapKey\r
747 )\r
748{\r
749 EFI_STATUS Status;\r
750\r
785b5f5a 751 //\r
752 // Disable Timer\r
753 //\r
754 gTimer->SetTimerPeriod (gTimer, 0);\r
755\r
31f228cf 756 //\r
757 // Terminate memory services if the MapKey matches\r
758 //\r
759 Status = CoreTerminateMemoryMap (MapKey);\r
760 if (EFI_ERROR (Status)) {\r
044824d9 761 //\r
d1102dba 762 // Notify other drivers that ExitBootServices fail\r
044824d9 763 //\r
764 CoreNotifySignalList (&gEventExitBootServicesFailedGuid);\r
31f228cf 765 return Status;\r
766 }\r
767\r
74a88770
SZ
768 gMemoryMapTerminated = TRUE;\r
769\r
31f228cf 770 //\r
771 // Notify other drivers that we are exiting boot services.\r
772 //\r
773 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
774\r
e4c83a4f
LG
775 //\r
776 // Report that ExitBootServices() has been called\r
777 //\r
778 REPORT_STATUS_CODE (\r
779 EFI_PROGRESS_CODE,\r
780 (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
781 );\r
782\r
bce776a5
HW
783 MemoryProtectionExitBootServicesCallback();\r
784\r
213fecef 785 //\r
786 // Disable interrupt of Debug timer.\r
787 //\r
788 SaveAndSetDebugTimerInterrupt (FALSE);\r
789\r
31f228cf 790 //\r
791 // Disable CPU Interrupts\r
792 //\r
793 gCpu->DisableInterrupt (gCpu);\r
794\r
31f228cf 795 //\r
796 // Clear the non-runtime values of the EFI System Table\r
797 //\r
798 gDxeCoreST->BootServices = NULL;\r
799 gDxeCoreST->ConIn = NULL;\r
800 gDxeCoreST->ConsoleInHandle = NULL;\r
801 gDxeCoreST->ConOut = NULL;\r
802 gDxeCoreST->ConsoleOutHandle = NULL;\r
803 gDxeCoreST->StdErr = NULL;\r
804 gDxeCoreST->StandardErrorHandle = NULL;\r
805\r
806 //\r
807 // Recompute the 32-bit CRC of the EFI System Table\r
808 //\r
809 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
810\r
811 //\r
812 // Zero out the Boot Service Table\r
813 //\r
814 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));\r
815 gBS = NULL;\r
816\r
817 //\r
818 // Update the AtRuntime field in Runtiem AP.\r
819 //\r
820 gRuntime->AtRuntime = TRUE;\r
821\r
822 return Status;\r
823}\r
824\r
825\r
826/**\r
827 Given a compressed source buffer, this function retrieves the size of the\r
828 uncompressed buffer and the size of the scratch buffer required to decompress\r
829 the compressed source buffer.\r
830\r
831 The GetInfo() function retrieves the size of the uncompressed buffer and the\r
832 temporary scratch buffer required to decompress the buffer specified by Source\r
833 and SourceSize. If the size of the uncompressed buffer or the size of the\r
834 scratch buffer cannot be determined from the compressed data specified by\r
835 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
836 size of the uncompressed buffer is returned in DestinationSize, the size of\r
837 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
838 The GetInfo() function does not have scratch buffer available to perform a\r
839 thorough checking of the validity of the source data. It just retrieves the\r
840 "Original Size" field from the beginning bytes of the source data and output\r
841 it as DestinationSize. And ScratchSize is specific to the decompression\r
842 implementation.\r
843\r
844 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
845 @param Source The source buffer containing the compressed data.\r
846 @param SourceSize The size, in bytes, of the source buffer.\r
847 @param DestinationSize A pointer to the size, in bytes, of the\r
848 uncompressed buffer that will be generated when the\r
849 compressed buffer specified by Source and\r
850 SourceSize is decompressed.\r
851 @param ScratchSize A pointer to the size, in bytes, of the scratch\r
852 buffer that is required to decompress the\r
853 compressed buffer specified by Source and\r
854 SourceSize.\r
855\r
856 @retval EFI_SUCCESS The size of the uncompressed data was returned in\r
857 DestinationSize and the size of the scratch buffer\r
858 was returned in ScratchSize.\r
859 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
860 the scratch buffer cannot be determined from the\r
861 compressed data specified by Source and\r
862 SourceSize.\r
863\r
864**/\r
865EFI_STATUS\r
866EFIAPI\r
867DxeMainUefiDecompressGetInfo (\r
868 IN EFI_DECOMPRESS_PROTOCOL *This,\r
869 IN VOID *Source,\r
870 IN UINT32 SourceSize,\r
871 OUT UINT32 *DestinationSize,\r
872 OUT UINT32 *ScratchSize\r
873 )\r
874{\r
875 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {\r
876 return EFI_INVALID_PARAMETER;\r
877 }\r
878 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
879}\r
880\r
881\r
882/**\r
883 Decompresses a compressed source buffer.\r
884\r
885 The Decompress() function extracts decompressed data to its original form.\r
886 This protocol is designed so that the decompression algorithm can be\r
887 implemented without using any memory services. As a result, the Decompress()\r
888 Function is not allowed to call AllocatePool() or AllocatePages() in its\r
889 implementation. It is the caller's responsibility to allocate and free the\r
890 Destination and Scratch buffers.\r
891 If the compressed source data specified by Source and SourceSize is\r
93e8d03c 892 successfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
31f228cf 893 the compressed source data specified by Source and SourceSize is not in a\r
894 valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
895\r
896 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
897 @param Source The source buffer containing the compressed data.\r
898 @param SourceSize SourceSizeThe size of source data.\r
899 @param Destination On output, the destination buffer that contains\r
900 the uncompressed data.\r
901 @param DestinationSize The size of the destination buffer. The size of\r
902 the destination buffer needed is obtained from\r
903 EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
904 @param Scratch A temporary scratch buffer that is used to perform\r
905 the decompression.\r
906 @param ScratchSize The size of scratch buffer. The size of the\r
907 scratch buffer needed is obtained from GetInfo().\r
908\r
909 @retval EFI_SUCCESS Decompression completed successfully, and the\r
910 uncompressed buffer is returned in Destination.\r
911 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and\r
912 SourceSize is corrupted (not in a valid\r
913 compressed format).\r
914\r
915**/\r
916EFI_STATUS\r
917EFIAPI\r
918DxeMainUefiDecompress (\r
919 IN EFI_DECOMPRESS_PROTOCOL *This,\r
920 IN VOID *Source,\r
921 IN UINT32 SourceSize,\r
922 IN OUT VOID *Destination,\r
923 IN UINT32 DestinationSize,\r
924 IN OUT VOID *Scratch,\r
925 IN UINT32 ScratchSize\r
926 )\r
927{\r
928 EFI_STATUS Status;\r
929 UINT32 TestDestinationSize;\r
930 UINT32 TestScratchSize;\r
931\r
932 if (Source == NULL || Destination== NULL || Scratch == NULL) {\r
933 return EFI_INVALID_PARAMETER;\r
934 }\r
935\r
936 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
937 if (EFI_ERROR (Status)) {\r
938 return Status;\r
939 }\r
940\r
941 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
942 return RETURN_INVALID_PARAMETER;\r
943 }\r
944\r
945 return UefiDecompress (Source, Destination, Scratch);\r
946}\r