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