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