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