]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
db25fcfa8de34af0e48b9f21d448ed9505974937
[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 // This Tiano extension was removed when UEFI 2.0 support was added.
312 // It's now just a protocol.
313 //
314 ,
315 (EFI_REPORT_STATUS_CODE) CoreEfiNotAvailableYetArg5 // ReportStatusCode
316 #elif (EFI_SPECIFICATION_VERSION >= 0x00020000)
317 //
318 // New runtime services added by UEFI 2.0
319 //
320 ,
321 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule
322 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
323 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo
324 #endif
325 };
326
327 //
328 // DXE Core Global Variables for the EFI System Table, Boot Services Table,
329 // DXE Services Table, and Runtime Services Table
330 //
331 EFI_BOOT_SERVICES *gBS = &mBootServices;
332 EFI_DXE_SERVICES *gDS = &mDxeServices;
333 EFI_SYSTEM_TABLE *gST = NULL;
334
335 //
336 // For debug initialize gRT to template. gRT must be allocated from RT memory
337 // but gRT is used for ASSERT () and DEBUG () type macros so lets give it
338 // a value that will not cause debug infrastructure to crash early on.
339 //
340 EFI_RUNTIME_SERVICES *gRT = &mEfiRuntimeServicesTableTemplate;
341 EFI_HANDLE gDxeCoreImageHandle = NULL;
342
343 VOID *mHobStart;
344
345 //
346 // EFI Decompress Protocol
347 //
348 EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {
349 DxeMainUefiDecompressGetInfo,
350 DxeMainUefiDecompress
351 };
352
353 //
354 // Tiano Decompress Protocol
355 //
356 EFI_TIANO_DECOMPRESS_PROTOCOL gEfiTianoDecompress = {
357 DxeMainTianoDecompressGetInfo,
358 DxeMainTianoDecompress
359 };
360
361 //
362 // Customized Decompress Protocol
363 //
364 EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL gEfiCustomizedDecompress = {
365 DxeMainCustomDecompressGetInfo,
366 DxeMainCustomDecompress
367 };
368
369 //
370 // Main entry point to the DXE Core
371 //
372 VOID
373 EFIAPI
374 DxeMain (
375 IN VOID *HobStart
376 )
377 /*++
378
379 Routine Description:
380
381 Main entry point to DXE Core.
382
383 Arguments:
384
385 HobStart - Pointer to the beginning of the HOB List from PEI
386
387 Returns:
388
389 This function should never return
390
391 --*/
392 {
393 EFI_STATUS Status;
394 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;
395 UINT64 MemoryLength;
396
397 mHobStart = HobStart;
398
399 //
400 // Initialize Memory Services
401 //
402 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);
403
404 //
405 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
406 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
407 //
408 gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
409 ASSERT (gST != NULL);
410
411 gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
412 ASSERT (gRT != NULL);
413
414 gST->RuntimeServices = gRT;
415
416 //
417 // Start the Image Services.
418 //
419 Status = CoreInitializeImageServices (HobStart);
420 ASSERT_EFI_ERROR (Status);
421
422 //
423 // Call constructor for all libraries
424 //
425 ProcessLibraryConstructorList (gDxeCoreImageHandle, gST);
426
427 PERF_START (0,DXE_TOK, NULL, 0) ;
428
429 //
430 // Initialize the Global Coherency Domain Services
431 //
432 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);
433 ASSERT_EFI_ERROR (Status);
434
435 //
436 // Install the DXE Services Table into the EFI System Tables's Configuration Table
437 //
438 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);
439 ASSERT_EFI_ERROR (Status);
440
441 //
442 // Install the HOB List into the EFI System Tables's Configuration Table
443 //
444 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);
445 ASSERT_EFI_ERROR (Status);
446
447 //
448 // Install Memory Type Information Table into the EFI System Tables's Configuration Table
449 //
450 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);
451 ASSERT_EFI_ERROR (Status);
452
453 //
454 // Initialize the ReportStatusCode with PEI version, if availible
455 //
456 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);
457 #if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
458 //
459 // This Tiano extension was removed when UEFI 2.0 support was added.
460 // It's now just a protocol.
461 //
462 gRT->ReportStatusCode = gStatusCode->ReportStatusCode;
463 #endif
464
465 //
466 // Report Status Code here for DXE_ENTRY_POINT once it is available
467 //
468 CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT));
469
470 //
471 // Create the aligned system table pointer structure that is used by external
472 // debuggers to locate the system table... Also, install debug image info
473 // configuration table.
474 //
475 CoreInitializeDebugImageInfoTable ();
476 CoreNewDebugImageInfoEntry (
477 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
478 gDxeCoreLoadedImage,
479 gDxeCoreImageHandle
480 );
481
482 DEBUG ((EFI_D_INFO | EFI_D_LOAD, "HOBLIST address in DXE = 0x%08x\n", HobStart));
483
484 //
485 // Initialize the Event Services
486 //
487 Status = CoreInitializeEventServices ();
488 ASSERT_EFI_ERROR (Status);
489
490
491 //
492 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
493 //
494 // These Protocols are not architectural. This implementation is sharing code between
495 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented
496 // as part of the DXE Core. However, that would also require the DXE Core to be ported
497 // each time a different CPU is used, a different Decompression algorithm is used, or a
498 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains
499 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,
500 // and from CPU to CPU.
501 //
502
503 //
504 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components
505 //
506 Status = CoreInstallMultipleProtocolInterfaces (
507 &mDecompressHandle,
508 &gEfiDecompressProtocolGuid, &gEfiDecompress,
509 &gEfiTianoDecompressProtocolGuid, &gEfiTianoDecompress,
510 &gEfiCustomizedDecompressProtocolGuid, &gEfiCustomizedDecompress,
511 NULL
512 );
513 ASSERT_EFI_ERROR (Status);
514
515 gEfiPeiPeCoffLoader = GetPeCoffLoaderProtocol ();
516 ASSERT (gEfiPeiPeCoffLoader != NULL);
517
518 //
519 // Register for the GUIDs of the Architectural Protocols, so the rest of the
520 // EFI Boot Services and EFI Runtime Services tables can be filled in.
521 //
522 CoreNotifyOnArchProtocolInstallation ();
523
524 //
525 // Produce Firmware Volume Protocols, one for each FV in the HOB list.
526 //
527 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);
528 ASSERT_EFI_ERROR (Status);
529
530 Status = FwVolDriverInit (gDxeCoreImageHandle, gST);
531 ASSERT_EFI_ERROR (Status);
532
533 //
534 // Produce the Section Extraction Protocol
535 //
536 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);
537 ASSERT_EFI_ERROR (Status);
538
539 //
540 // Initialize the DXE Dispatcher
541 //
542 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
543 CoreInitializeDispatcher ();
544 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
545
546 //
547 // Invoke the DXE Dispatcher
548 //
549 PERF_START (0, "CoreDispatcher", "DxeMain", 0);
550 CoreDispatcher ();
551 PERF_END (0, "CoreDispatcher", "DxeMain", 0);
552
553 //
554 // Display Architectural protocols that were not loaded if this is DEBUG build
555 //
556 DEBUG_CODE_BEGIN ();
557 CoreDisplayMissingArchProtocols ();
558 DEBUG_CODE_END ();
559
560 //
561 // Assert if the Architectural Protocols are not present.
562 //
563 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());
564
565 //
566 // Report Status code before transfer control to BDS
567 //
568 CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT));
569 //
570 // Display any drivers that were not dispatched because dependency expression
571 // evaluated to false if this is a debug build
572 //
573 DEBUG_CODE_BEGIN ();
574 CoreDisplayDiscoveredNotDispatched ();
575 DEBUG_CODE_END ();
576
577 //
578 // Transfer control to the BDS Architectural Protocol
579 //
580 gBds->Entry (gBds);
581
582 //
583 // BDS should never return
584 //
585 ASSERT (FALSE);
586 CpuDeadLoop ();
587 }
588
589
590 EFI_STATUS
591 EFIAPI
592 CoreEfiNotAvailableYetArg0 (
593 VOID
594 )
595 /*++
596
597 Routine Description:
598
599 Place holder function until all the Boot Services and Runtime Services are available
600
601 Arguments:
602
603 None
604
605 Returns:
606
607 EFI_NOT_AVAILABLE_YET
608
609 --*/
610 {
611 //
612 // This function should never be executed. If it does, then the architectural protocols
613 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
614 // DXE Core and all the Architectural Protocols are complete.
615 //
616
617 return EFI_NOT_AVAILABLE_YET;
618 }
619
620 EFI_STATUS
621 EFIAPI
622 CoreEfiNotAvailableYetArg1 (
623 UINTN Arg1
624 )
625 /*++
626
627 Routine Description:
628
629 Place holder function until all the Boot Services and Runtime Services are available
630
631 Arguments:
632
633 Arg1 - Undefined
634
635 Returns:
636
637 EFI_NOT_AVAILABLE_YET
638
639 --*/
640 {
641 //
642 // This function should never be executed. If it does, then the architectural protocols
643 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
644 // DXE Core and all the Architectural Protocols are complete.
645 //
646
647 return EFI_NOT_AVAILABLE_YET;
648 }
649
650 EFI_STATUS
651 EFIAPI
652 CoreEfiNotAvailableYetArg2 (
653 UINTN Arg1,
654 UINTN Arg2
655 )
656 /*++
657
658 Routine Description:
659
660 Place holder function until all the Boot Services and Runtime Services are available
661
662 Arguments:
663
664 Arg1 - Undefined
665
666 Arg2 - Undefined
667
668 Returns:
669
670 EFI_NOT_AVAILABLE_YET
671
672 --*/
673 {
674 //
675 // This function should never be executed. If it does, then the architectural protocols
676 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
677 // DXE Core and all the Architectural Protocols are complete.
678 //
679
680 return EFI_NOT_AVAILABLE_YET;
681 }
682
683 EFI_STATUS
684 EFIAPI
685 CoreEfiNotAvailableYetArg3 (
686 UINTN Arg1,
687 UINTN Arg2,
688 UINTN Arg3
689 )
690 /*++
691
692 Routine Description:
693
694 Place holder function until all the Boot Services and Runtime Services are available
695
696 Arguments:
697
698 Arg1 - Undefined
699
700 Arg2 - Undefined
701
702 Arg3 - Undefined
703
704 Returns:
705
706 EFI_NOT_AVAILABLE_YET
707
708 --*/
709 {
710 //
711 // This function should never be executed. If it does, then the architectural protocols
712 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
713 // DXE Core and all the Architectural Protocols are complete.
714 //
715
716 return EFI_NOT_AVAILABLE_YET;
717 }
718
719 EFI_STATUS
720 EFIAPI
721 CoreEfiNotAvailableYetArg4 (
722 UINTN Arg1,
723 UINTN Arg2,
724 UINTN Arg3,
725 UINTN Arg4
726 )
727 /*++
728
729 Routine Description:
730
731 Place holder function until all the Boot Services and Runtime Services are available
732
733 Arguments:
734
735 Arg1 - Undefined
736
737 Arg2 - Undefined
738
739 Arg3 - Undefined
740
741 Arg4 - Undefined
742
743 Returns:
744
745 EFI_NOT_AVAILABLE_YET
746
747 --*/
748 {
749 //
750 // This function should never be executed. If it does, then the architectural protocols
751 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
752 // DXE Core and all the Architectural Protocols are complete.
753 //
754
755 return EFI_NOT_AVAILABLE_YET;
756 }
757
758 EFI_STATUS
759 EFIAPI
760 CoreEfiNotAvailableYetArg5 (
761 UINTN Arg1,
762 UINTN Arg2,
763 UINTN Arg3,
764 UINTN Arg4,
765 UINTN Arg5
766 )
767 /*++
768
769 Routine Description:
770
771 Place holder function until all the Boot Services and Runtime Services are available
772
773 Arguments:
774
775 Arg1 - Undefined
776
777 Arg2 - Undefined
778
779 Arg3 - Undefined
780
781 Arg4 - Undefined
782
783 Arg5 - Undefined
784
785 Returns:
786
787 EFI_NOT_AVAILABLE_YET
788
789 --*/
790 {
791 //
792 // This function should never be executed. If it does, then the architectural protocols
793 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
794 // DXE Core and all the Architectural Protocols are complete.
795 //
796
797 return EFI_NOT_AVAILABLE_YET;
798 }
799
800
801 EFI_STATUS
802 CoreGetPeiProtocol (
803 IN EFI_GUID *ProtocolGuid,
804 IN VOID **Interface
805 )
806 /*++
807
808 Routine Description:
809
810 Searches for a Protocol Interface passed from PEI through a HOB
811
812 Arguments:
813
814 ProtocolGuid - The Protocol GUID to search for in the HOB List
815
816 Interface - A pointer to the interface for the Protocol GUID
817
818 Returns:
819
820 EFI_SUCCESS - The Protocol GUID was found and its interface is returned in Interface
821
822 EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List
823
824 --*/
825 {
826 EFI_HOB_GUID_TYPE *GuidHob;
827 VOID *Buffer;
828
829 GuidHob = GetNextGuidHob (ProtocolGuid, mHobStart);
830 if (GuidHob == NULL) {
831 return EFI_NOT_FOUND;
832 }
833
834 Buffer = GET_GUID_HOB_DATA (GuidHob);
835 ASSERT (Buffer != NULL);
836
837 *Interface = (VOID *)(*(UINTN *)(Buffer));
838
839 return EFI_SUCCESS;
840 }
841
842
843 VOID
844 CalculateEfiHdrCrc (
845 IN OUT EFI_TABLE_HEADER *Hdr
846 )
847 /*++
848
849 Routine Description:
850
851 Calcualte the 32-bit CRC in a EFI table using the service provided by the
852 gRuntime service.
853
854 Arguments:
855
856 Hdr - Pointer to an EFI standard header
857
858 Returns:
859
860 None
861
862 --*/
863 {
864 UINT32 Crc;
865
866 Hdr->CRC32 = 0;
867
868 //
869 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
870 // Crc will come back as zero if we set it to zero here
871 //
872 Crc = 0;
873 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
874 Hdr->CRC32 = Crc;
875 }
876
877
878
879 EFI_STATUS
880 EFIAPI
881 CoreExitBootServices (
882 IN EFI_HANDLE ImageHandle,
883 IN UINTN MapKey
884 )
885 /*++
886
887 Routine Description:
888
889 EFI 1.0 API to terminate Boot Services
890
891 Arguments:
892
893 ImageHandle - Handle that represents the identity of the calling image
894
895 MapKey -Key to the latest memory map.
896
897 Returns:
898
899 EFI_SUCCESS - Boot Services terminated
900 EFI_INVALID_PARAMETER - MapKey is incorrect.
901
902 --*/
903 {
904 EFI_STATUS Status;
905
906 //
907 // Terminate memory services if the MapKey matches
908 //
909 Status = CoreTerminateMemoryMap (MapKey);
910 if (EFI_ERROR (Status)) {
911 return Status;
912 }
913
914 //
915 // Notify other drivers that we are exiting boot services.
916 //
917 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);
918
919 //
920 // Disable Timer
921 //
922 gTimer->SetTimerPeriod (gTimer, 0);
923
924 //
925 // Disable CPU Interrupts
926 //
927 gCpu->DisableInterrupt (gCpu);
928
929 //
930 // Register Runtime events with the Runtime Architectural Protocol
931 //
932 CoreShutdownEventServices ();
933
934 //
935 // Register Runtime images with the Runtime Architectural Protocol
936 //
937 CoreShutdownImageServices ();
938
939 //
940 // Report that ExitBootServices() has been called
941 //
942 // We are using gEfiDxeServicesTableGuid as the caller ID for Dxe Core
943 //
944 CoreReportProgressCode ((EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES));
945
946 //
947 // Clear the non-runtime values of the EFI System Table
948 //
949 gST->BootServices = NULL;
950 gST->ConIn = NULL;
951 gST->ConsoleInHandle = NULL;
952 gST->ConOut = NULL;
953 gST->ConsoleOutHandle = NULL;
954 gST->StdErr = NULL;
955 gST->StandardErrorHandle = NULL;
956
957 //
958 // Recompute the 32-bit CRC of the EFI System Table
959 //
960 CalculateEfiHdrCrc (&gST->Hdr);
961
962 //
963 // Zero out the Boot Service Table
964 //
965 SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);
966 gBS = NULL;
967
968 return Status;
969 }
970
971 EFI_STATUS
972 DxeMainUefiDecompressGetInfo (
973 IN EFI_DECOMPRESS_PROTOCOL *This,
974 IN VOID *Source,
975 IN UINT32 SourceSize,
976 OUT UINT32 *DestinationSize,
977 OUT UINT32 *ScratchSize
978 )
979 {
980 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
981 }
982
983 EFI_STATUS
984 EFIAPI
985 DxeMainUefiDecompress (
986 IN EFI_DECOMPRESS_PROTOCOL *This,
987 IN VOID *Source,
988 IN UINT32 SourceSize,
989 IN OUT VOID *Destination,
990 IN UINT32 DestinationSize,
991 IN OUT VOID *Scratch,
992 IN UINT32 ScratchSize
993 )
994 {
995 EFI_STATUS Status;
996 UINT32 TestDestinationSize;
997 UINT32 TestScratchSize;
998
999 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
1000 if (EFI_ERROR (Status)) {
1001 return Status;
1002 }
1003
1004 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
1005 return RETURN_INVALID_PARAMETER;
1006 }
1007
1008 return UefiDecompress (Source, Destination, Scratch);
1009 }
1010
1011 EFI_STATUS
1012 DxeMainTianoDecompressGetInfo (
1013 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,
1014 IN VOID *Source,
1015 IN UINT32 SourceSize,
1016 OUT UINT32 *DestinationSize,
1017 OUT UINT32 *ScratchSize
1018 )
1019 {
1020 return TianoDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
1021 }
1022
1023 EFI_STATUS
1024 EFIAPI
1025 DxeMainTianoDecompress (
1026 IN EFI_TIANO_DECOMPRESS_PROTOCOL *This,
1027 IN VOID *Source,
1028 IN UINT32 SourceSize,
1029 IN OUT VOID *Destination,
1030 IN UINT32 DestinationSize,
1031 IN OUT VOID *Scratch,
1032 IN UINT32 ScratchSize
1033 )
1034 {
1035 EFI_STATUS Status;
1036 UINT32 TestDestinationSize;
1037 UINT32 TestScratchSize;
1038
1039 Status = TianoDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
1040 if (EFI_ERROR (Status)) {
1041 return Status;
1042 }
1043
1044 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
1045 return RETURN_INVALID_PARAMETER;
1046 }
1047
1048 return TianoDecompress (Source, Destination, Scratch);
1049 }
1050
1051 EFI_STATUS
1052 DxeMainCustomDecompressGetInfo (
1053 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,
1054 IN VOID *Source,
1055 IN UINT32 SourceSize,
1056 OUT UINT32 *DestinationSize,
1057 OUT UINT32 *ScratchSize
1058 )
1059 {
1060 return CustomDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
1061 }
1062
1063 EFI_STATUS
1064 EFIAPI
1065 DxeMainCustomDecompress (
1066 IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This,
1067 IN VOID *Source,
1068 IN UINT32 SourceSize,
1069 IN OUT VOID *Destination,
1070 IN UINT32 DestinationSize,
1071 IN OUT VOID *Scratch,
1072 IN UINT32 ScratchSize
1073 )
1074 {
1075 EFI_STATUS Status;
1076 UINT32 TestDestinationSize;
1077 UINT32 TestScratchSize;
1078
1079 Status = CustomDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
1080 if (EFI_ERROR (Status)) {
1081 return Status;
1082 }
1083
1084 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
1085 return RETURN_INVALID_PARAMETER;
1086 }
1087
1088 return CustomDecompress (Source, Destination, Scratch);
1089 }
1090