]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
UefiCpuPkg: Simplify InitializeSeparateExceptionStacks
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
... / ...
CommitLineData
1/** @file\r
2 DXE Core Main Entry Point\r
3\r
4Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
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
20EFI_SECURITY2_ARCH_PROTOCOL *gSecurity2 = NULL;\r
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
27//\r
28// DXE Core globals for optional protocol dependencies\r
29//\r
30EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;\r
31\r
32//\r
33// DXE Core Global used to update core loaded image protocol handle\r
34//\r
35EFI_GUID *gDxeCoreFileName;\r
36EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;\r
37\r
38//\r
39// DXE Core Module Variables\r
40//\r
41EFI_BOOT_SERVICES mBootServices = {\r
42 {\r
43 EFI_BOOT_SERVICES_SIGNATURE, // Signature\r
44 EFI_BOOT_SERVICES_REVISION, // Revision\r
45 sizeof (EFI_BOOT_SERVICES), // HeaderSize\r
46 0, // CRC32\r
47 0 // Reserved\r
48 },\r
49 (EFI_RAISE_TPL)CoreRaiseTpl, // RaiseTPL\r
50 (EFI_RESTORE_TPL)CoreRestoreTpl, // RestoreTPL\r
51 (EFI_ALLOCATE_PAGES)CoreAllocatePages, // AllocatePages\r
52 (EFI_FREE_PAGES)CoreFreePages, // FreePages\r
53 (EFI_GET_MEMORY_MAP)CoreGetMemoryMap, // GetMemoryMap\r
54 (EFI_ALLOCATE_POOL)CoreAllocatePool, // AllocatePool\r
55 (EFI_FREE_POOL)CoreFreePool, // FreePool\r
56 (EFI_CREATE_EVENT)CoreCreateEvent, // CreateEvent\r
57 (EFI_SET_TIMER)CoreSetTimer, // SetTimer\r
58 (EFI_WAIT_FOR_EVENT)CoreWaitForEvent, // WaitForEvent\r
59 (EFI_SIGNAL_EVENT)CoreSignalEvent, // SignalEvent\r
60 (EFI_CLOSE_EVENT)CoreCloseEvent, // CloseEvent\r
61 (EFI_CHECK_EVENT)CoreCheckEvent, // CheckEvent\r
62 (EFI_INSTALL_PROTOCOL_INTERFACE)CoreInstallProtocolInterface, // InstallProtocolInterface\r
63 (EFI_REINSTALL_PROTOCOL_INTERFACE)CoreReinstallProtocolInterface, // ReinstallProtocolInterface\r
64 (EFI_UNINSTALL_PROTOCOL_INTERFACE)CoreUninstallProtocolInterface, // UninstallProtocolInterface\r
65 (EFI_HANDLE_PROTOCOL)CoreHandleProtocol, // HandleProtocol\r
66 (VOID *)NULL, // Reserved\r
67 (EFI_REGISTER_PROTOCOL_NOTIFY)CoreRegisterProtocolNotify, // RegisterProtocolNotify\r
68 (EFI_LOCATE_HANDLE)CoreLocateHandle, // LocateHandle\r
69 (EFI_LOCATE_DEVICE_PATH)CoreLocateDevicePath, // LocateDevicePath\r
70 (EFI_INSTALL_CONFIGURATION_TABLE)CoreInstallConfigurationTable, // InstallConfigurationTable\r
71 (EFI_IMAGE_LOAD)CoreLoadImage, // LoadImage\r
72 (EFI_IMAGE_START)CoreStartImage, // StartImage\r
73 (EFI_EXIT)CoreExit, // Exit\r
74 (EFI_IMAGE_UNLOAD)CoreUnloadImage, // UnloadImage\r
75 (EFI_EXIT_BOOT_SERVICES)CoreExitBootServices, // ExitBootServices\r
76 (EFI_GET_NEXT_MONOTONIC_COUNT)CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount\r
77 (EFI_STALL)CoreStall, // Stall\r
78 (EFI_SET_WATCHDOG_TIMER)CoreSetWatchdogTimer, // SetWatchdogTimer\r
79 (EFI_CONNECT_CONTROLLER)CoreConnectController, // ConnectController\r
80 (EFI_DISCONNECT_CONTROLLER)CoreDisconnectController, // DisconnectController\r
81 (EFI_OPEN_PROTOCOL)CoreOpenProtocol, // OpenProtocol\r
82 (EFI_CLOSE_PROTOCOL)CoreCloseProtocol, // CloseProtocol\r
83 (EFI_OPEN_PROTOCOL_INFORMATION)CoreOpenProtocolInformation, // OpenProtocolInformation\r
84 (EFI_PROTOCOLS_PER_HANDLE)CoreProtocolsPerHandle, // ProtocolsPerHandle\r
85 (EFI_LOCATE_HANDLE_BUFFER)CoreLocateHandleBuffer, // LocateHandleBuffer\r
86 (EFI_LOCATE_PROTOCOL)CoreLocateProtocol, // LocateProtocol\r
87 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces\r
88 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces\r
89 (EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3, // CalculateCrc32\r
90 (EFI_COPY_MEM)CopyMem, // CopyMem\r
91 (EFI_SET_MEM)SetMem, // SetMem\r
92 (EFI_CREATE_EVENT_EX)CoreCreateEventEx // CreateEventEx\r
93};\r
94\r
95EFI_DXE_SERVICES mDxeServices = {\r
96 {\r
97 DXE_SERVICES_SIGNATURE, // Signature\r
98 DXE_SERVICES_REVISION, // Revision\r
99 sizeof (DXE_SERVICES), // HeaderSize\r
100 0, // CRC32\r
101 0 // Reserved\r
102 },\r
103 (EFI_ADD_MEMORY_SPACE)CoreAddMemorySpace, // AddMemorySpace\r
104 (EFI_ALLOCATE_MEMORY_SPACE)CoreAllocateMemorySpace, // AllocateMemorySpace\r
105 (EFI_FREE_MEMORY_SPACE)CoreFreeMemorySpace, // FreeMemorySpace\r
106 (EFI_REMOVE_MEMORY_SPACE)CoreRemoveMemorySpace, // RemoveMemorySpace\r
107 (EFI_GET_MEMORY_SPACE_DESCRIPTOR)CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor\r
108 (EFI_SET_MEMORY_SPACE_ATTRIBUTES)CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes\r
109 (EFI_GET_MEMORY_SPACE_MAP)CoreGetMemorySpaceMap, // GetMemorySpaceMap\r
110 (EFI_ADD_IO_SPACE)CoreAddIoSpace, // AddIoSpace\r
111 (EFI_ALLOCATE_IO_SPACE)CoreAllocateIoSpace, // AllocateIoSpace\r
112 (EFI_FREE_IO_SPACE)CoreFreeIoSpace, // FreeIoSpace\r
113 (EFI_REMOVE_IO_SPACE)CoreRemoveIoSpace, // RemoveIoSpace\r
114 (EFI_GET_IO_SPACE_DESCRIPTOR)CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor\r
115 (EFI_GET_IO_SPACE_MAP)CoreGetIoSpaceMap, // GetIoSpaceMap\r
116 (EFI_DISPATCH)CoreDispatcher, // Dispatch\r
117 (EFI_SCHEDULE)CoreSchedule, // Schedule\r
118 (EFI_TRUST)CoreTrust, // Trust\r
119 (EFI_PROCESS_FIRMWARE_VOLUME)CoreProcessFirmwareVolume, // ProcessFirmwareVolume\r
120 (EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities, // SetMemorySpaceCapabilities\r
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
204BOOLEAN gMemoryMapTerminated = FALSE;\r
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
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
217//\r
218GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = { 0, 0 };\r
219\r
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
237 EFI_STATUS Status;\r
238 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
239 UINT64 MemoryLength;\r
240 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
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
245 VOID *EntryPoint;\r
246\r
247 //\r
248 // Setup the default exception handlers\r
249 //\r
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
255\r
256 Status = InitializeCpuExceptionHandlers (VectorInfoList);\r
257 ASSERT_EFI_ERROR (Status);\r
258\r
259 //\r
260 // Setup Stack Guard\r
261 //\r
262 if (PcdGetBool (PcdCpuStackGuard)) {\r
263 Status = InitializeSeparateExceptionStacks (NULL, NULL);\r
264 ASSERT_EFI_ERROR (Status);\r
265 }\r
266\r
267 //\r
268 // Initialize Debug Agent to support source level debug in DXE phase\r
269 //\r
270 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE, HobStart, NULL);\r
271\r
272 //\r
273 // Initialize Memory Services\r
274 //\r
275 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
276\r
277 MemoryProfileInit (HobStart);\r
278\r
279 //\r
280 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
281 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
282 //\r
283 gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
284 ASSERT (gDxeCoreST != NULL);\r
285\r
286 gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
287 ASSERT (gDxeCoreRT != NULL);\r
288\r
289 gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
290\r
291 //\r
292 // Start the Image Services.\r
293 //\r
294 Status = CoreInitializeImageServices (HobStart);\r
295 ASSERT_EFI_ERROR (Status);\r
296\r
297 //\r
298 // Initialize the Global Coherency Domain Services\r
299 //\r
300 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
301 ASSERT_EFI_ERROR (Status);\r
302\r
303 //\r
304 // Call constructor for all libraries\r
305 //\r
306 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
307 PERF_CROSSMODULE_END ("PEI");\r
308 PERF_CROSSMODULE_BEGIN ("DXE");\r
309\r
310 //\r
311 // Log MemoryBaseAddress and MemoryLength again (from\r
312 // CoreInitializeMemoryServices()), now that library constructors have\r
313 // executed.\r
314 //\r
315 DEBUG ((\r
316 DEBUG_INFO,\r
317 "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",\r
318 __FUNCTION__,\r
319 MemoryBaseAddress,\r
320 MemoryLength\r
321 ));\r
322\r
323 //\r
324 // Report DXE Core image information to the PE/COFF Extra Action Library\r
325 //\r
326 ZeroMem (&ImageContext, sizeof (ImageContext));\r
327 ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
328 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);\r
329 ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageContext.ImageAddress);\r
330 Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageContext.ImageAddress, &EntryPoint);\r
331 if (Status == EFI_SUCCESS) {\r
332 ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r
333 }\r
334\r
335 ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
336 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
337 PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
338\r
339 //\r
340 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
341 //\r
342 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
343 ASSERT_EFI_ERROR (Status);\r
344\r
345 //\r
346 // Install the HOB List into the EFI System Tables's Configuration Table\r
347 //\r
348 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
349 ASSERT_EFI_ERROR (Status);\r
350\r
351 //\r
352 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
353 //\r
354 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
355 ASSERT_EFI_ERROR (Status);\r
356\r
357 //\r
358 // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address\r
359 // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI\r
360 // Code and Tseg base to load SMM driver.\r
361 //\r
362 if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {\r
363 Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);\r
364 ASSERT_EFI_ERROR (Status);\r
365 }\r
366\r
367 //\r
368 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
369 //\r
370 REPORT_STATUS_CODE (\r
371 EFI_PROGRESS_CODE,\r
372 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)\r
373 );\r
374\r
375 //\r
376 // Create the aligned system table pointer structure that is used by external\r
377 // debuggers to locate the system table... Also, install debug image info\r
378 // configuration table.\r
379 //\r
380 CoreInitializeDebugImageInfoTable ();\r
381 CoreNewDebugImageInfoEntry (\r
382 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
383 gDxeCoreLoadedImage,\r
384 gDxeCoreImageHandle\r
385 );\r
386\r
387 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
388\r
389 DEBUG_CODE_BEGIN ();\r
390 EFI_PEI_HOB_POINTERS Hob;\r
391\r
392 for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
393 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
394 DEBUG ((\r
395 DEBUG_INFO | DEBUG_LOAD,\r
396 "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \\r
397 Hob.MemoryAllocation->AllocDescriptor.MemoryType, \\r
398 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \\r
399 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1\r
400 ));\r
401 }\r
402 }\r
403\r
404 for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
405 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
406 DEBUG ((\r
407 DEBUG_INFO | DEBUG_LOAD,\r
408 "FV Hob 0x%0lx - 0x%0lx\n",\r
409 Hob.FirmwareVolume->BaseAddress,\r
410 Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1\r
411 ));\r
412 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {\r
413 DEBUG ((\r
414 DEBUG_INFO | DEBUG_LOAD,\r
415 "FV2 Hob 0x%0lx - 0x%0lx\n",\r
416 Hob.FirmwareVolume2->BaseAddress,\r
417 Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1\r
418 ));\r
419 DEBUG ((\r
420 DEBUG_INFO | DEBUG_LOAD,\r
421 " %g - %g\n",\r
422 &Hob.FirmwareVolume2->FvName,\r
423 &Hob.FirmwareVolume2->FileName\r
424 ));\r
425 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {\r
426 DEBUG ((\r
427 DEBUG_INFO | DEBUG_LOAD,\r
428 "FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",\r
429 Hob.FirmwareVolume3->BaseAddress,\r
430 Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,\r
431 Hob.FirmwareVolume3->AuthenticationStatus,\r
432 Hob.FirmwareVolume3->ExtractedFv\r
433 ));\r
434 if (Hob.FirmwareVolume3->ExtractedFv) {\r
435 DEBUG ((\r
436 DEBUG_INFO | DEBUG_LOAD,\r
437 " %g - %g\n",\r
438 &Hob.FirmwareVolume3->FvName,\r
439 &Hob.FirmwareVolume3->FileName\r
440 ));\r
441 }\r
442 }\r
443 }\r
444\r
445 DEBUG_CODE_END ();\r
446\r
447 //\r
448 // Initialize the Event Services\r
449 //\r
450 Status = CoreInitializeEventServices ();\r
451 ASSERT_EFI_ERROR (Status);\r
452\r
453 MemoryProfileInstallProtocol ();\r
454\r
455 CoreInitializeMemoryAttributesTable ();\r
456 CoreInitializeMemoryProtection ();\r
457\r
458 //\r
459 // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,\r
460 // and install configuration table\r
461 //\r
462 GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
463 if (GuidHob != NULL) {\r
464 VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));\r
465 VectorInfo = VectorInfoList;\r
466 Index = 1;\r
467 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
468 VectorInfo++;\r
469 Index++;\r
470 }\r
471\r
472 VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *)VectorInfoList);\r
473 ASSERT (VectorInfo != NULL);\r
474 Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)VectorInfo);\r
475 ASSERT_EFI_ERROR (Status);\r
476 }\r
477\r
478 //\r
479 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
480 //\r
481 // These Protocols are not architectural. This implementation is sharing code between\r
482 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
483 // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
484 // each time a different CPU is used, a different Decompression algorithm is used, or a\r
485 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
486 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
487 // and from CPU to CPU.\r
488 //\r
489\r
490 //\r
491 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
492 //\r
493 Status = CoreInstallMultipleProtocolInterfaces (\r
494 &mDecompressHandle,\r
495 &gEfiDecompressProtocolGuid,\r
496 &gEfiDecompress,\r
497 NULL\r
498 );\r
499 ASSERT_EFI_ERROR (Status);\r
500\r
501 //\r
502 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
503 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
504 // Also register for the GUIDs of optional protocols.\r
505 //\r
506 CoreNotifyOnProtocolInstallation ();\r
507\r
508 //\r
509 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
510 //\r
511 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
512 ASSERT_EFI_ERROR (Status);\r
513\r
514 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
515 ASSERT_EFI_ERROR (Status);\r
516\r
517 //\r
518 // Produce the Section Extraction Protocol\r
519 //\r
520 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
521 ASSERT_EFI_ERROR (Status);\r
522\r
523 //\r
524 // Initialize the DXE Dispatcher\r
525 //\r
526 CoreInitializeDispatcher ();\r
527\r
528 //\r
529 // Invoke the DXE Dispatcher\r
530 //\r
531 CoreDispatcher ();\r
532\r
533 //\r
534 // Display Architectural protocols that were not loaded if this is DEBUG build\r
535 //\r
536 DEBUG_CODE_BEGIN ();\r
537 CoreDisplayMissingArchProtocols ();\r
538 DEBUG_CODE_END ();\r
539\r
540 //\r
541 // Display any drivers that were not dispatched because dependency expression\r
542 // evaluated to false if this is a debug build\r
543 //\r
544 DEBUG_CODE_BEGIN ();\r
545 CoreDisplayDiscoveredNotDispatched ();\r
546 DEBUG_CODE_END ();\r
547\r
548 //\r
549 // Assert if the Architectural Protocols are not present.\r
550 //\r
551 Status = CoreAllEfiServicesAvailable ();\r
552 if (EFI_ERROR (Status)) {\r
553 //\r
554 // Report Status code that some Architectural Protocols are not present.\r
555 //\r
556 REPORT_STATUS_CODE (\r
557 EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
558 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)\r
559 );\r
560 }\r
561\r
562 ASSERT_EFI_ERROR (Status);\r
563\r
564 //\r
565 // Report Status code before transfer control to BDS\r
566 //\r
567 REPORT_STATUS_CODE (\r
568 EFI_PROGRESS_CODE,\r
569 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)\r
570 );\r
571\r
572 //\r
573 // Transfer control to the BDS Architectural Protocol\r
574 //\r
575 gBds->Entry (gBds);\r
576\r
577 //\r
578 // BDS should never return\r
579 //\r
580 ASSERT (FALSE);\r
581 CpuDeadLoop ();\r
582\r
583 UNREACHABLE ();\r
584}\r
585\r
586/**\r
587 Place holder function until all the Boot Services and Runtime Services are\r
588 available.\r
589\r
590 @param Arg1 Undefined\r
591\r
592 @return EFI_NOT_AVAILABLE_YET\r
593\r
594**/\r
595EFI_STATUS\r
596EFIAPI\r
597CoreEfiNotAvailableYetArg1 (\r
598 UINTN Arg1\r
599 )\r
600{\r
601 //\r
602 // This function should never be executed. If it does, then the architectural protocols\r
603 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
604 // DXE Core and all the Architectural Protocols are complete.\r
605 //\r
606\r
607 return EFI_NOT_AVAILABLE_YET;\r
608}\r
609\r
610/**\r
611 Place holder function until all the Boot Services and Runtime Services are available.\r
612\r
613 @param Arg1 Undefined\r
614 @param Arg2 Undefined\r
615\r
616 @return EFI_NOT_AVAILABLE_YET\r
617\r
618**/\r
619EFI_STATUS\r
620EFIAPI\r
621CoreEfiNotAvailableYetArg2 (\r
622 UINTN Arg1,\r
623 UINTN Arg2\r
624 )\r
625{\r
626 //\r
627 // This function should never be executed. If it does, then the architectural protocols\r
628 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
629 // DXE Core and all the Architectural Protocols are complete.\r
630 //\r
631\r
632 return EFI_NOT_AVAILABLE_YET;\r
633}\r
634\r
635/**\r
636 Place holder function until all the Boot Services and Runtime Services are available.\r
637\r
638 @param Arg1 Undefined\r
639 @param Arg2 Undefined\r
640 @param Arg3 Undefined\r
641\r
642 @return EFI_NOT_AVAILABLE_YET\r
643\r
644**/\r
645EFI_STATUS\r
646EFIAPI\r
647CoreEfiNotAvailableYetArg3 (\r
648 UINTN Arg1,\r
649 UINTN Arg2,\r
650 UINTN Arg3\r
651 )\r
652{\r
653 //\r
654 // This function should never be executed. If it does, then the architectural protocols\r
655 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
656 // DXE Core and all the Architectural Protocols are complete.\r
657 //\r
658\r
659 return EFI_NOT_AVAILABLE_YET;\r
660}\r
661\r
662/**\r
663 Place holder function until all the Boot Services and Runtime Services are available.\r
664\r
665 @param Arg1 Undefined\r
666 @param Arg2 Undefined\r
667 @param Arg3 Undefined\r
668 @param Arg4 Undefined\r
669\r
670 @return EFI_NOT_AVAILABLE_YET\r
671\r
672**/\r
673EFI_STATUS\r
674EFIAPI\r
675CoreEfiNotAvailableYetArg4 (\r
676 UINTN Arg1,\r
677 UINTN Arg2,\r
678 UINTN Arg3,\r
679 UINTN Arg4\r
680 )\r
681{\r
682 //\r
683 // This function should never be executed. If it does, then the architectural protocols\r
684 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
685 // DXE Core and all the Architectural Protocols are complete.\r
686 //\r
687\r
688 return EFI_NOT_AVAILABLE_YET;\r
689}\r
690\r
691/**\r
692 Place holder function until all the Boot Services and Runtime Services are available.\r
693\r
694 @param Arg1 Undefined\r
695 @param Arg2 Undefined\r
696 @param Arg3 Undefined\r
697 @param Arg4 Undefined\r
698 @param Arg5 Undefined\r
699\r
700 @return EFI_NOT_AVAILABLE_YET\r
701\r
702**/\r
703EFI_STATUS\r
704EFIAPI\r
705CoreEfiNotAvailableYetArg5 (\r
706 UINTN Arg1,\r
707 UINTN Arg2,\r
708 UINTN Arg3,\r
709 UINTN Arg4,\r
710 UINTN Arg5\r
711 )\r
712{\r
713 //\r
714 // This function should never be executed. If it does, then the architectural protocols\r
715 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
716 // DXE Core and all the Architectural Protocols are complete.\r
717 //\r
718\r
719 return EFI_NOT_AVAILABLE_YET;\r
720}\r
721\r
722/**\r
723 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
724 gRuntime service.\r
725\r
726 @param Hdr Pointer to an EFI standard header\r
727\r
728**/\r
729VOID\r
730CalculateEfiHdrCrc (\r
731 IN OUT EFI_TABLE_HEADER *Hdr\r
732 )\r
733{\r
734 UINT32 Crc;\r
735\r
736 Hdr->CRC32 = 0;\r
737\r
738 //\r
739 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
740 // Crc will come back as zero if we set it to zero here\r
741 //\r
742 Crc = 0;\r
743 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
744 Hdr->CRC32 = Crc;\r
745}\r
746\r
747/**\r
748 Terminates all boot services.\r
749\r
750 @param ImageHandle Handle that identifies the exiting image.\r
751 @param MapKey Key to the latest memory map.\r
752\r
753 @retval EFI_SUCCESS Boot Services terminated\r
754 @retval EFI_INVALID_PARAMETER MapKey is incorrect.\r
755\r
756**/\r
757EFI_STATUS\r
758EFIAPI\r
759CoreExitBootServices (\r
760 IN EFI_HANDLE ImageHandle,\r
761 IN UINTN MapKey\r
762 )\r
763{\r
764 EFI_STATUS Status;\r
765\r
766 //\r
767 // Disable Timer\r
768 //\r
769 gTimer->SetTimerPeriod (gTimer, 0);\r
770\r
771 //\r
772 // Terminate memory services if the MapKey matches\r
773 //\r
774 Status = CoreTerminateMemoryMap (MapKey);\r
775 if (EFI_ERROR (Status)) {\r
776 //\r
777 // Notify other drivers that ExitBootServices fail\r
778 //\r
779 CoreNotifySignalList (&gEventExitBootServicesFailedGuid);\r
780 return Status;\r
781 }\r
782\r
783 gMemoryMapTerminated = TRUE;\r
784\r
785 //\r
786 // Notify other drivers that we are exiting boot services.\r
787 //\r
788 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
789\r
790 //\r
791 // Report that ExitBootServices() has been called\r
792 //\r
793 REPORT_STATUS_CODE (\r
794 EFI_PROGRESS_CODE,\r
795 (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
796 );\r
797\r
798 MemoryProtectionExitBootServicesCallback ();\r
799\r
800 //\r
801 // Disable interrupt of Debug timer.\r
802 //\r
803 SaveAndSetDebugTimerInterrupt (FALSE);\r
804\r
805 //\r
806 // Disable CPU Interrupts\r
807 //\r
808 gCpu->DisableInterrupt (gCpu);\r
809\r
810 //\r
811 // Clear the non-runtime values of the EFI System Table\r
812 //\r
813 gDxeCoreST->BootServices = NULL;\r
814 gDxeCoreST->ConIn = NULL;\r
815 gDxeCoreST->ConsoleInHandle = NULL;\r
816 gDxeCoreST->ConOut = NULL;\r
817 gDxeCoreST->ConsoleOutHandle = NULL;\r
818 gDxeCoreST->StdErr = NULL;\r
819 gDxeCoreST->StandardErrorHandle = NULL;\r
820\r
821 //\r
822 // Recompute the 32-bit CRC of the EFI System Table\r
823 //\r
824 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
825\r
826 //\r
827 // Zero out the Boot Service Table\r
828 //\r
829 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));\r
830 gBS = NULL;\r
831\r
832 //\r
833 // Update the AtRuntime field in Runtiem AP.\r
834 //\r
835 gRuntime->AtRuntime = TRUE;\r
836\r
837 return Status;\r
838}\r
839\r
840/**\r
841 Given a compressed source buffer, this function retrieves the size of the\r
842 uncompressed buffer and the size of the scratch buffer required to decompress\r
843 the compressed source buffer.\r
844\r
845 The GetInfo() function retrieves the size of the uncompressed buffer and the\r
846 temporary scratch buffer required to decompress the buffer specified by Source\r
847 and SourceSize. If the size of the uncompressed buffer or the size of the\r
848 scratch buffer cannot be determined from the compressed data specified by\r
849 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
850 size of the uncompressed buffer is returned in DestinationSize, the size of\r
851 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
852 The GetInfo() function does not have scratch buffer available to perform a\r
853 thorough checking of the validity of the source data. It just retrieves the\r
854 "Original Size" field from the beginning bytes of the source data and output\r
855 it as DestinationSize. And ScratchSize is specific to the decompression\r
856 implementation.\r
857\r
858 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
859 @param Source The source buffer containing the compressed data.\r
860 @param SourceSize The size, in bytes, of the source buffer.\r
861 @param DestinationSize A pointer to the size, in bytes, of the\r
862 uncompressed buffer that will be generated when the\r
863 compressed buffer specified by Source and\r
864 SourceSize is decompressed.\r
865 @param ScratchSize A pointer to the size, in bytes, of the scratch\r
866 buffer that is required to decompress the\r
867 compressed buffer specified by Source and\r
868 SourceSize.\r
869\r
870 @retval EFI_SUCCESS The size of the uncompressed data was returned in\r
871 DestinationSize and the size of the scratch buffer\r
872 was returned in ScratchSize.\r
873 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
874 the scratch buffer cannot be determined from the\r
875 compressed data specified by Source and\r
876 SourceSize.\r
877\r
878**/\r
879EFI_STATUS\r
880EFIAPI\r
881DxeMainUefiDecompressGetInfo (\r
882 IN EFI_DECOMPRESS_PROTOCOL *This,\r
883 IN VOID *Source,\r
884 IN UINT32 SourceSize,\r
885 OUT UINT32 *DestinationSize,\r
886 OUT UINT32 *ScratchSize\r
887 )\r
888{\r
889 if ((Source == NULL) || (DestinationSize == NULL) || (ScratchSize == NULL)) {\r
890 return EFI_INVALID_PARAMETER;\r
891 }\r
892\r
893 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
894}\r
895\r
896/**\r
897 Decompresses a compressed source buffer.\r
898\r
899 The Decompress() function extracts decompressed data to its original form.\r
900 This protocol is designed so that the decompression algorithm can be\r
901 implemented without using any memory services. As a result, the Decompress()\r
902 Function is not allowed to call AllocatePool() or AllocatePages() in its\r
903 implementation. It is the caller's responsibility to allocate and free the\r
904 Destination and Scratch buffers.\r
905 If the compressed source data specified by Source and SourceSize is\r
906 successfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
907 the compressed source data specified by Source and SourceSize is not in a\r
908 valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
909\r
910 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
911 @param Source The source buffer containing the compressed data.\r
912 @param SourceSize SourceSizeThe size of source data.\r
913 @param Destination On output, the destination buffer that contains\r
914 the uncompressed data.\r
915 @param DestinationSize The size of the destination buffer. The size of\r
916 the destination buffer needed is obtained from\r
917 EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
918 @param Scratch A temporary scratch buffer that is used to perform\r
919 the decompression.\r
920 @param ScratchSize The size of scratch buffer. The size of the\r
921 scratch buffer needed is obtained from GetInfo().\r
922\r
923 @retval EFI_SUCCESS Decompression completed successfully, and the\r
924 uncompressed buffer is returned in Destination.\r
925 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and\r
926 SourceSize is corrupted (not in a valid\r
927 compressed format).\r
928\r
929**/\r
930EFI_STATUS\r
931EFIAPI\r
932DxeMainUefiDecompress (\r
933 IN EFI_DECOMPRESS_PROTOCOL *This,\r
934 IN VOID *Source,\r
935 IN UINT32 SourceSize,\r
936 IN OUT VOID *Destination,\r
937 IN UINT32 DestinationSize,\r
938 IN OUT VOID *Scratch,\r
939 IN UINT32 ScratchSize\r
940 )\r
941{\r
942 EFI_STATUS Status;\r
943 UINT32 TestDestinationSize;\r
944 UINT32 TestScratchSize;\r
945\r
946 if ((Source == NULL) || (Destination == NULL) || (Scratch == NULL)) {\r
947 return EFI_INVALID_PARAMETER;\r
948 }\r
949\r
950 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
951 if (EFI_ERROR (Status)) {\r
952 return Status;\r
953 }\r
954\r
955 if ((ScratchSize < TestScratchSize) || (DestinationSize < TestDestinationSize)) {\r
956 return RETURN_INVALID_PARAMETER;\r
957 }\r
958\r
959 return UefiDecompress (Source, Destination, Scratch);\r
960}\r