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