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