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