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