]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
5a8814041c11b7c0e8f4b4da18fc33ccfd1d6032
[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 //
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 // Call constructor for all libraries
291 //
292 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
293 PERF_END (NULL,"PEI", NULL, 0) ;
294 PERF_START (NULL,"DXE", NULL, 0) ;
295
296 //
297 // Report DXE Core image information to the PE/COFF Extra Action Library
298 //
299 ZeroMem (&ImageContext, sizeof (ImageContext));
300 ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;
301 ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);
302 PeCoffLoaderRelocateImageExtraAction (&ImageContext);
303
304 //
305 // Initialize the Global Coherency Domain Services
306 //
307 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);
308 ASSERT_EFI_ERROR (Status);
309
310 //
311 // Install the DXE Services Table into the EFI System Tables's Configuration Table
312 //
313 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);
314 ASSERT_EFI_ERROR (Status);
315
316 //
317 // Install the HOB List into the EFI System Tables's Configuration Table
318 //
319 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);
320 ASSERT_EFI_ERROR (Status);
321
322 //
323 // Install Memory Type Information Table into the EFI System Tables's Configuration Table
324 //
325 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);
326 ASSERT_EFI_ERROR (Status);
327
328 //
329 // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address
330 // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI
331 // Code and Tseg base to load SMM driver.
332 //
333 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
334 Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);
335 ASSERT_EFI_ERROR (Status);
336 }
337 //
338 // Report Status Code here for DXE_ENTRY_POINT once it is available
339 //
340 REPORT_STATUS_CODE (
341 EFI_PROGRESS_CODE,
342 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)
343 );
344
345 //
346 // Create the aligned system table pointer structure that is used by external
347 // debuggers to locate the system table... Also, install debug image info
348 // configuration table.
349 //
350 CoreInitializeDebugImageInfoTable ();
351 CoreNewDebugImageInfoEntry (
352 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
353 gDxeCoreLoadedImage,
354 gDxeCoreImageHandle
355 );
356
357 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
358
359 DEBUG_CODE_BEGIN ();
360 EFI_PEI_HOB_POINTERS Hob;
361
362 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
363 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
364 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
365 Hob.MemoryAllocation->AllocDescriptor.MemoryType, \
366 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \
367 Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));
368 }
369 }
370 for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
371 if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
372 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV2 Hob 0x%0lx - 0x%0lx\n", Hob.FirmwareVolume2->BaseAddress, Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1));
373 } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
374 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV Hob 0x%0lx - 0x%0lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume2->Length - 1));
375 }
376 }
377 DEBUG_CODE_END ();
378
379 //
380 // Initialize the Event Services
381 //
382 Status = CoreInitializeEventServices ();
383 ASSERT_EFI_ERROR (Status);
384
385 //
386 // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,
387 // and install configuration table
388 //
389 GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
390 if (GuidHob != NULL) {
391 VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));
392 VectorInfo = VectorInfoList;
393 Index = 1;
394 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
395 VectorInfo ++;
396 Index ++;
397 }
398 VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList);
399 ASSERT (VectorInfo != NULL);
400 Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo);
401 ASSERT_EFI_ERROR (Status);
402 }
403
404 //
405 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
406 //
407 // These Protocols are not architectural. This implementation is sharing code between
408 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented
409 // as part of the DXE Core. However, that would also require the DXE Core to be ported
410 // each time a different CPU is used, a different Decompression algorithm is used, or a
411 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains
412 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,
413 // and from CPU to CPU.
414 //
415
416 //
417 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components
418 //
419 Status = CoreInstallMultipleProtocolInterfaces (
420 &mDecompressHandle,
421 &gEfiDecompressProtocolGuid, &gEfiDecompress,
422 NULL
423 );
424 ASSERT_EFI_ERROR (Status);
425
426 //
427 // Register for the GUIDs of the Architectural Protocols, so the rest of the
428 // EFI Boot Services and EFI Runtime Services tables can be filled in.
429 // Also register for the GUIDs of optional protocols.
430 //
431 CoreNotifyOnProtocolInstallation ();
432
433 //
434 // Produce Firmware Volume Protocols, one for each FV in the HOB list.
435 //
436 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);
437 ASSERT_EFI_ERROR (Status);
438
439 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);
440 ASSERT_EFI_ERROR (Status);
441
442 //
443 // Produce the Section Extraction Protocol
444 //
445 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);
446 ASSERT_EFI_ERROR (Status);
447
448 //
449 // Initialize the DXE Dispatcher
450 //
451 PERF_START (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;
452 CoreInitializeDispatcher ();
453 PERF_END (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;
454
455 //
456 // Invoke the DXE Dispatcher
457 //
458 PERF_START (NULL, "CoreDispatcher", "DxeMain", 0);
459 CoreDispatcher ();
460 PERF_END (NULL, "CoreDispatcher", "DxeMain", 0);
461
462 //
463 // Display Architectural protocols that were not loaded if this is DEBUG build
464 //
465 DEBUG_CODE_BEGIN ();
466 CoreDisplayMissingArchProtocols ();
467 DEBUG_CODE_END ();
468
469 //
470 // Display any drivers that were not dispatched because dependency expression
471 // evaluated to false if this is a debug build
472 //
473 DEBUG_CODE_BEGIN ();
474 CoreDisplayDiscoveredNotDispatched ();
475 DEBUG_CODE_END ();
476
477 //
478 // Assert if the Architectural Protocols are not present.
479 //
480 Status = CoreAllEfiServicesAvailable ();
481 if (EFI_ERROR(Status)) {
482 //
483 // Report Status code that some Architectural Protocols are not present.
484 //
485 REPORT_STATUS_CODE (
486 EFI_ERROR_CODE | EFI_ERROR_MAJOR,
487 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)
488 );
489 }
490 ASSERT_EFI_ERROR (Status);
491
492 //
493 // Report Status code before transfer control to BDS
494 //
495 REPORT_STATUS_CODE (
496 EFI_PROGRESS_CODE,
497 (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)
498 );
499
500 //
501 // Transfer control to the BDS Architectural Protocol
502 //
503 gBds->Entry (gBds);
504
505 //
506 // BDS should never return
507 //
508 ASSERT (FALSE);
509 CpuDeadLoop ();
510 }
511
512
513
514 /**
515 Place holder function until all the Boot Services and Runtime Services are
516 available.
517
518 @return EFI_NOT_AVAILABLE_YET
519
520 **/
521 EFI_STATUS
522 EFIAPI
523 CoreEfiNotAvailableYetArg0 (
524 VOID
525 )
526 {
527 //
528 // This function should never be executed. If it does, then the architectural protocols
529 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
530 // DXE Core and all the Architectural Protocols are complete.
531 //
532
533 return EFI_NOT_AVAILABLE_YET;
534 }
535
536
537 /**
538 Place holder function until all the Boot Services and Runtime Services are
539 available.
540
541 @param Arg1 Undefined
542
543 @return EFI_NOT_AVAILABLE_YET
544
545 **/
546 EFI_STATUS
547 EFIAPI
548 CoreEfiNotAvailableYetArg1 (
549 UINTN Arg1
550 )
551 {
552 //
553 // This function should never be executed. If it does, then the architectural protocols
554 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
555 // DXE Core and all the Architectural Protocols are complete.
556 //
557
558 return EFI_NOT_AVAILABLE_YET;
559 }
560
561
562 /**
563 Place holder function until all the Boot Services and Runtime Services are available.
564
565 @param Arg1 Undefined
566 @param Arg2 Undefined
567
568 @return EFI_NOT_AVAILABLE_YET
569
570 **/
571 EFI_STATUS
572 EFIAPI
573 CoreEfiNotAvailableYetArg2 (
574 UINTN Arg1,
575 UINTN Arg2
576 )
577 {
578 //
579 // This function should never be executed. If it does, then the architectural protocols
580 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
581 // DXE Core and all the Architectural Protocols are complete.
582 //
583
584 return EFI_NOT_AVAILABLE_YET;
585 }
586
587
588 /**
589 Place holder function until all the Boot Services and Runtime Services are available.
590
591 @param Arg1 Undefined
592 @param Arg2 Undefined
593 @param Arg3 Undefined
594
595 @return EFI_NOT_AVAILABLE_YET
596
597 **/
598 EFI_STATUS
599 EFIAPI
600 CoreEfiNotAvailableYetArg3 (
601 UINTN Arg1,
602 UINTN Arg2,
603 UINTN Arg3
604 )
605 {
606 //
607 // This function should never be executed. If it does, then the architectural protocols
608 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
609 // DXE Core and all the Architectural Protocols are complete.
610 //
611
612 return EFI_NOT_AVAILABLE_YET;
613 }
614
615
616 /**
617 Place holder function until all the Boot Services and Runtime Services are available.
618
619 @param Arg1 Undefined
620 @param Arg2 Undefined
621 @param Arg3 Undefined
622 @param Arg4 Undefined
623
624 @return EFI_NOT_AVAILABLE_YET
625
626 **/
627 EFI_STATUS
628 EFIAPI
629 CoreEfiNotAvailableYetArg4 (
630 UINTN Arg1,
631 UINTN Arg2,
632 UINTN Arg3,
633 UINTN Arg4
634 )
635 {
636 //
637 // This function should never be executed. If it does, then the architectural protocols
638 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
639 // DXE Core and all the Architectural Protocols are complete.
640 //
641
642 return EFI_NOT_AVAILABLE_YET;
643 }
644
645
646 /**
647 Place holder function until all the Boot Services and Runtime Services are available.
648
649 @param Arg1 Undefined
650 @param Arg2 Undefined
651 @param Arg3 Undefined
652 @param Arg4 Undefined
653 @param Arg5 Undefined
654
655 @return EFI_NOT_AVAILABLE_YET
656
657 **/
658 EFI_STATUS
659 EFIAPI
660 CoreEfiNotAvailableYetArg5 (
661 UINTN Arg1,
662 UINTN Arg2,
663 UINTN Arg3,
664 UINTN Arg4,
665 UINTN Arg5
666 )
667 {
668 //
669 // This function should never be executed. If it does, then the architectural protocols
670 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
671 // DXE Core and all the Architectural Protocols are complete.
672 //
673
674 return EFI_NOT_AVAILABLE_YET;
675 }
676
677
678 /**
679 Calcualte the 32-bit CRC in a EFI table using the service provided by the
680 gRuntime service.
681
682 @param Hdr Pointer to an EFI standard header
683
684 **/
685 VOID
686 CalculateEfiHdrCrc (
687 IN OUT EFI_TABLE_HEADER *Hdr
688 )
689 {
690 UINT32 Crc;
691
692 Hdr->CRC32 = 0;
693
694 //
695 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
696 // Crc will come back as zero if we set it to zero here
697 //
698 Crc = 0;
699 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
700 Hdr->CRC32 = Crc;
701 }
702
703
704 /**
705 Terminates all boot services.
706
707 @param ImageHandle Handle that identifies the exiting image.
708 @param MapKey Key to the latest memory map.
709
710 @retval EFI_SUCCESS Boot Services terminated
711 @retval EFI_INVALID_PARAMETER MapKey is incorrect.
712
713 **/
714 EFI_STATUS
715 EFIAPI
716 CoreExitBootServices (
717 IN EFI_HANDLE ImageHandle,
718 IN UINTN MapKey
719 )
720 {
721 EFI_STATUS Status;
722
723 //
724 // Disable Timer
725 //
726 gTimer->SetTimerPeriod (gTimer, 0);
727
728 //
729 // Terminate memory services if the MapKey matches
730 //
731 Status = CoreTerminateMemoryMap (MapKey);
732 if (EFI_ERROR (Status)) {
733 //
734 // Notify other drivers that ExitBootServices fail
735 //
736 CoreNotifySignalList (&gEventExitBootServicesFailedGuid);
737 return Status;
738 }
739
740 //
741 // Notify other drivers that we are exiting boot services.
742 //
743 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);
744
745 //
746 // Report that ExitBootServices() has been called
747 //
748 REPORT_STATUS_CODE (
749 EFI_PROGRESS_CODE,
750 (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)
751 );
752
753 //
754 // Disable interrupt of Debug timer.
755 //
756 SaveAndSetDebugTimerInterrupt (FALSE);
757
758 //
759 // Disable CPU Interrupts
760 //
761 gCpu->DisableInterrupt (gCpu);
762
763 //
764 // Clear the non-runtime values of the EFI System Table
765 //
766 gDxeCoreST->BootServices = NULL;
767 gDxeCoreST->ConIn = NULL;
768 gDxeCoreST->ConsoleInHandle = NULL;
769 gDxeCoreST->ConOut = NULL;
770 gDxeCoreST->ConsoleOutHandle = NULL;
771 gDxeCoreST->StdErr = NULL;
772 gDxeCoreST->StandardErrorHandle = NULL;
773
774 //
775 // Recompute the 32-bit CRC of the EFI System Table
776 //
777 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
778
779 //
780 // Zero out the Boot Service Table
781 //
782 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));
783 gBS = NULL;
784
785 //
786 // Update the AtRuntime field in Runtiem AP.
787 //
788 gRuntime->AtRuntime = TRUE;
789
790 return Status;
791 }
792
793
794 /**
795 Given a compressed source buffer, this function retrieves the size of the
796 uncompressed buffer and the size of the scratch buffer required to decompress
797 the compressed source buffer.
798
799 The GetInfo() function retrieves the size of the uncompressed buffer and the
800 temporary scratch buffer required to decompress the buffer specified by Source
801 and SourceSize. If the size of the uncompressed buffer or the size of the
802 scratch buffer cannot be determined from the compressed data specified by
803 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the
804 size of the uncompressed buffer is returned in DestinationSize, the size of
805 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
806 The GetInfo() function does not have scratch buffer available to perform a
807 thorough checking of the validity of the source data. It just retrieves the
808 "Original Size" field from the beginning bytes of the source data and output
809 it as DestinationSize. And ScratchSize is specific to the decompression
810 implementation.
811
812 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
813 @param Source The source buffer containing the compressed data.
814 @param SourceSize The size, in bytes, of the source buffer.
815 @param DestinationSize A pointer to the size, in bytes, of the
816 uncompressed buffer that will be generated when the
817 compressed buffer specified by Source and
818 SourceSize is decompressed.
819 @param ScratchSize A pointer to the size, in bytes, of the scratch
820 buffer that is required to decompress the
821 compressed buffer specified by Source and
822 SourceSize.
823
824 @retval EFI_SUCCESS The size of the uncompressed data was returned in
825 DestinationSize and the size of the scratch buffer
826 was returned in ScratchSize.
827 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of
828 the scratch buffer cannot be determined from the
829 compressed data specified by Source and
830 SourceSize.
831
832 **/
833 EFI_STATUS
834 EFIAPI
835 DxeMainUefiDecompressGetInfo (
836 IN EFI_DECOMPRESS_PROTOCOL *This,
837 IN VOID *Source,
838 IN UINT32 SourceSize,
839 OUT UINT32 *DestinationSize,
840 OUT UINT32 *ScratchSize
841 )
842 {
843 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {
844 return EFI_INVALID_PARAMETER;
845 }
846 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
847 }
848
849
850 /**
851 Decompresses a compressed source buffer.
852
853 The Decompress() function extracts decompressed data to its original form.
854 This protocol is designed so that the decompression algorithm can be
855 implemented without using any memory services. As a result, the Decompress()
856 Function is not allowed to call AllocatePool() or AllocatePages() in its
857 implementation. It is the caller's responsibility to allocate and free the
858 Destination and Scratch buffers.
859 If the compressed source data specified by Source and SourceSize is
860 successfully decompressed into Destination, then EFI_SUCCESS is returned. If
861 the compressed source data specified by Source and SourceSize is not in a
862 valid compressed data format, then EFI_INVALID_PARAMETER is returned.
863
864 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
865 @param Source The source buffer containing the compressed data.
866 @param SourceSize SourceSizeThe size of source data.
867 @param Destination On output, the destination buffer that contains
868 the uncompressed data.
869 @param DestinationSize The size of the destination buffer. The size of
870 the destination buffer needed is obtained from
871 EFI_DECOMPRESS_PROTOCOL.GetInfo().
872 @param Scratch A temporary scratch buffer that is used to perform
873 the decompression.
874 @param ScratchSize The size of scratch buffer. The size of the
875 scratch buffer needed is obtained from GetInfo().
876
877 @retval EFI_SUCCESS Decompression completed successfully, and the
878 uncompressed buffer is returned in Destination.
879 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and
880 SourceSize is corrupted (not in a valid
881 compressed format).
882
883 **/
884 EFI_STATUS
885 EFIAPI
886 DxeMainUefiDecompress (
887 IN EFI_DECOMPRESS_PROTOCOL *This,
888 IN VOID *Source,
889 IN UINT32 SourceSize,
890 IN OUT VOID *Destination,
891 IN UINT32 DestinationSize,
892 IN OUT VOID *Scratch,
893 IN UINT32 ScratchSize
894 )
895 {
896 EFI_STATUS Status;
897 UINT32 TestDestinationSize;
898 UINT32 TestScratchSize;
899
900 if (Source == NULL || Destination== NULL || Scratch == NULL) {
901 return EFI_INVALID_PARAMETER;
902 }
903
904 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
905 if (EFI_ERROR (Status)) {
906 return Status;
907 }
908
909 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
910 return RETURN_INVALID_PARAMETER;
911 }
912
913 return UefiDecompress (Source, Destination, Scratch);
914 }