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