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