3 Responsibility of this module is to load the DXE Core from a Firmware Volume.
5 Copyright (c) 2016 HP Development Company, L.P.
6 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
15 // Module Globals used in the DXE to PEI hand off
16 // These must be module globals, so the stack can be switched
18 CONST EFI_DXE_IPL_PPI mDxeIplPpi
= {
22 CONST EFI_PEI_PPI_DESCRIPTOR mDxeIplPpiList
= {
23 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
28 CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi
= {
29 CustomGuidedSectionExtract
32 CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi
= {
36 CONST EFI_PEI_PPI_DESCRIPTOR mDecompressPpiList
= {
37 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
38 &gEfiPeiDecompressPpiGuid
,
39 (VOID
*) &mDecompressPpi
42 CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi
= {
43 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
44 &gEfiEndOfPeiSignalPpiGuid
,
48 CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList
= {
49 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
50 &gEfiPeiMemoryDiscoveredPpiGuid
,
51 InstallIplPermanentMemoryPpis
55 Entry point of DXE IPL PEIM.
57 This function installs DXE IPL PPI. It also reloads
58 itself to memory on non-S3 resume boot path.
60 @param FileHandle Handle of the file being invoked.
61 @param PeiServices Describes the list of possible PEI Services.
63 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
64 @retval Others Some error occurs during the execution of this function.
69 PeimInitializeDxeIpl (
70 IN EFI_PEI_FILE_HANDLE FileHandle
,
71 IN CONST EFI_PEI_SERVICES
**PeiServices
75 EFI_BOOT_MODE BootMode
;
78 BootMode
= GetBootModeHob ();
80 if (BootMode
!= BOOT_ON_S3_RESUME
) {
81 Status
= PeiServicesRegisterForShadow (FileHandle
);
82 if (Status
== EFI_SUCCESS
) {
84 // EFI_SUCESS means it is the first time to call register for shadow.
90 // Ensure that DXE IPL is shadowed to permanent memory.
92 ASSERT (Status
== EFI_ALREADY_STARTED
);
95 // DXE core load requires permanent memory.
97 Status
= PeiServicesLocatePpi (
98 &gEfiPeiMemoryDiscoveredPpiGuid
,
103 ASSERT_EFI_ERROR (Status
);
104 if (EFI_ERROR (Status
)) {
109 // Now the permanent memory exists, install the PPIs for decompression
110 // and section extraction.
112 Status
= InstallIplPermanentMemoryPpis (NULL
, NULL
, NULL
);
113 ASSERT_EFI_ERROR (Status
);
116 // Install memory discovered PPI notification to install PPIs for
117 // decompression and section extraction.
119 Status
= PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList
);
120 ASSERT_EFI_ERROR (Status
);
124 // Install DxeIpl PPI.
126 Status
= PeiServicesInstallPpi (&mDxeIplPpiList
);
127 ASSERT_EFI_ERROR(Status
);
133 This function installs the PPIs that require permanent memory.
135 @param PeiServices Indirect reference to the PEI Services Table.
136 @param NotifyDescriptor Address of the notification descriptor data structure.
137 @param Ppi Address of the PPI that was installed.
139 @return EFI_SUCCESS The PPIs were installed successfully.
140 @return Others Some error occurs during the execution of this function.
145 InstallIplPermanentMemoryPpis (
146 IN EFI_PEI_SERVICES
**PeiServices
,
147 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
152 EFI_GUID
*ExtractHandlerGuidTable
;
153 UINTN ExtractHandlerNumber
;
154 EFI_PEI_PPI_DESCRIPTOR
*GuidPpi
;
157 // Get custom extract guided section method guid list
159 ExtractHandlerNumber
= ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable
);
162 // Install custom guided section extraction PPI
164 if (ExtractHandlerNumber
> 0) {
165 GuidPpi
= (EFI_PEI_PPI_DESCRIPTOR
*) AllocatePool (ExtractHandlerNumber
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
166 ASSERT (GuidPpi
!= NULL
);
167 while (ExtractHandlerNumber
-- > 0) {
168 GuidPpi
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
169 GuidPpi
->Ppi
= (VOID
*) &mCustomGuidedSectionExtractionPpi
;
170 GuidPpi
->Guid
= &ExtractHandlerGuidTable
[ExtractHandlerNumber
];
171 Status
= PeiServicesInstallPpi (GuidPpi
++);
172 ASSERT_EFI_ERROR(Status
);
177 // Install Decompress PPI.
179 Status
= PeiServicesInstallPpi (&mDecompressPpiList
);
180 ASSERT_EFI_ERROR(Status
);
186 Validate variable data for the MemoryTypeInformation.
188 @param MemoryData Variable data.
189 @param MemoryDataSize Variable data length.
191 @return TRUE The variable data is valid.
192 @return FALSE The variable data is invalid.
196 ValidateMemoryTypeInfoVariable (
197 IN EFI_MEMORY_TYPE_INFORMATION
*MemoryData
,
198 IN UINTN MemoryDataSize
204 // Check the input parameter.
205 if (MemoryData
== NULL
) {
210 Count
= MemoryDataSize
/ sizeof (*MemoryData
);
213 if (Count
* sizeof(*MemoryData
) != MemoryDataSize
) {
217 // Check last entry type filed.
218 if (MemoryData
[Count
- 1].Type
!= EfiMaxMemoryType
) {
222 // Check the type filed.
223 for (Index
= 0; Index
< Count
- 1; Index
++) {
224 if (MemoryData
[Index
].Type
>= EfiMaxMemoryType
) {
233 Main entry point to last PEIM.
235 This function finds DXE Core in the firmware volume and transfer the control to
238 @param This Entry point for DXE IPL PPI.
239 @param PeiServices General purpose services available to every PEIM.
240 @param HobList Address to the Pei HOB list.
242 @return EFI_SUCCESS DXE core was successfully loaded.
243 @return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.
249 IN CONST EFI_DXE_IPL_PPI
*This
,
250 IN EFI_PEI_SERVICES
**PeiServices
,
251 IN EFI_PEI_HOB_POINTERS HobList
255 EFI_FV_FILE_INFO DxeCoreFileInfo
;
256 EFI_PHYSICAL_ADDRESS DxeCoreAddress
;
258 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
;
259 EFI_BOOT_MODE BootMode
;
260 EFI_PEI_FILE_HANDLE FileHandle
;
261 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
262 EFI_PEI_LOAD_FILE_PPI
*LoadFile
;
264 UINT32 AuthenticationState
;
266 EFI_PEI_S3_RESUME2_PPI
*S3Resume
;
267 EFI_PEI_RECOVERY_MODULE_PPI
*PeiRecovery
;
268 EFI_PEI_CAPSULE_ON_DISK_PPI
*PeiCapsuleOnDisk
;
269 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
270 VOID
*CapsuleOnDiskModePpi
;
273 // if in S3 Resume, restore configure
275 BootMode
= GetBootModeHob ();
277 if (BootMode
== BOOT_ON_S3_RESUME
) {
278 Status
= PeiServicesLocatePpi (
279 &gEfiPeiS3Resume2PpiGuid
,
284 if (EFI_ERROR (Status
)) {
286 // Report Status code that S3Resume PPI can not be found
289 EFI_ERROR_CODE
| EFI_ERROR_MAJOR
,
290 (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND
)
293 ASSERT_EFI_ERROR (Status
);
295 Status
= S3Resume
->S3RestoreConfig2 (S3Resume
);
296 ASSERT_EFI_ERROR (Status
);
297 } else if (BootMode
== BOOT_IN_RECOVERY_MODE
) {
298 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_PC_RECOVERY_BEGIN
));
299 Status
= PeiServicesLocatePpi (
300 &gEfiPeiRecoveryModulePpiGuid
,
303 (VOID
**) &PeiRecovery
306 if (EFI_ERROR (Status
)) {
307 DEBUG ((DEBUG_ERROR
, "Locate Recovery PPI Failed.(Status = %r)\n", Status
));
309 // Report Status code the failure of locating Recovery PPI
312 EFI_ERROR_CODE
| EFI_ERROR_MAJOR
,
313 (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND
)
318 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_PC_CAPSULE_LOAD
));
319 Status
= PeiRecovery
->LoadRecoveryCapsule (PeiServices
, PeiRecovery
);
320 if (EFI_ERROR (Status
)) {
321 DEBUG ((DEBUG_ERROR
, "Load Recovery Capsule Failed.(Status = %r)\n", Status
));
323 // Report Status code that recovery image can not be found
326 EFI_ERROR_CODE
| EFI_ERROR_MAJOR
,
327 (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_EC_NO_RECOVERY_CAPSULE
)
331 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_PC_CAPSULE_START
));
333 // Now should have a HOB with the DXE core
335 } else if (BootMode
== BOOT_ON_FLASH_UPDATE
) {
337 // If Capsule On Disk mode, call storage stack to read Capsule Relocation file
338 // IoMmmu is highly recommmended to enable before reading
340 Status
= PeiServicesLocatePpi (
341 &gEdkiiPeiBootInCapsuleOnDiskModePpiGuid
,
344 &CapsuleOnDiskModePpi
346 if (!EFI_ERROR(Status
)) {
347 Status
= PeiServicesLocatePpi (
348 &gEdkiiPeiCapsuleOnDiskPpiGuid
,
351 (VOID
**) &PeiCapsuleOnDisk
355 // Whether failed, still goes to Firmware Update boot path. BDS will clear corresponding indicator and reboot later on
357 if (!EFI_ERROR (Status
)) {
358 Status
= PeiCapsuleOnDisk
->LoadCapsuleOnDisk (PeiServices
, PeiCapsuleOnDisk
);
363 if (GetFirstGuidHob ((CONST EFI_GUID
*)&gEfiMemoryTypeInformationGuid
) == NULL
) {
365 // Don't build GuidHob if GuidHob has been installed.
367 Status
= PeiServicesLocatePpi (
368 &gEfiPeiReadOnlyVariable2PpiGuid
,
373 if (!EFI_ERROR (Status
)) {
374 DataSize
= sizeof (MemoryData
);
375 Status
= Variable
->GetVariable (
377 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
378 &gEfiMemoryTypeInformationGuid
,
383 if (!EFI_ERROR (Status
) && ValidateMemoryTypeInfoVariable(MemoryData
, DataSize
)) {
385 // Build the GUID'd HOB for DXE
388 &gEfiMemoryTypeInformationGuid
,
397 // Look in all the FVs present in PEI and find the DXE Core FileHandle
399 FileHandle
= DxeIplFindDxeCore ();
402 // Load the DXE Core from a Firmware Volume.
406 Status
= PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid
, Instance
++, NULL
, (VOID
**) &LoadFile
);
408 // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.
410 ASSERT_EFI_ERROR (Status
);
412 Status
= LoadFile
->LoadFile (
420 } while (EFI_ERROR (Status
));
423 // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.
425 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &DxeCoreFileInfo
);
426 ASSERT_EFI_ERROR (Status
);
429 // Add HOB for the DXE Core
432 &DxeCoreFileInfo
.FileName
,
434 ALIGN_VALUE (DxeCoreSize
, EFI_PAGE_SIZE
),
439 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT
441 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT
));
443 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID
*)(UINTN
)DxeCoreAddress
, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint
)));
446 // Transfer control to the DXE Core
447 // The hand off state is simply a pointer to the HOB list
449 HandOffToDxeCore (DxeCoreEntryPoint
, HobList
);
451 // If we get here, then the DXE Core returned. This is an error
452 // DxeCore should not return.
457 return EFI_OUT_OF_RESOURCES
;
462 Searches DxeCore in all firmware Volumes and loads the first
463 instance that contains DxeCore.
465 @return FileHandle of DxeCore to load DxeCore.
475 EFI_PEI_FV_HANDLE VolumeHandle
;
476 EFI_PEI_FILE_HANDLE FileHandle
;
481 // Traverse all firmware volume instances
483 Status
= PeiServicesFfsFindNextVolume (Instance
, &VolumeHandle
);
485 // If some error occurs here, then we cannot find any firmware
486 // volume that may contain DxeCore.
488 if (EFI_ERROR (Status
)) {
489 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_CORE_EC_DXE_CORRUPT
));
491 ASSERT_EFI_ERROR (Status
);
494 // Find the DxeCore file type from the beginning in this firmware volume.
497 Status
= PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE
, VolumeHandle
, &FileHandle
);
498 if (!EFI_ERROR (Status
)) {
500 // Find DxeCore FileHandle in this volume, then we skip other firmware volume and
501 // return the FileHandle.
506 // We cannot find DxeCore in this firmware volume, then search the next volume.
515 The ExtractSection() function processes the input section and
516 returns a pointer to the section contents. If the section being
517 extracted does not require processing (if the section
518 GuidedSectionHeader.Attributes has the
519 EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
520 OutputBuffer is just updated to point to the start of the
521 section's contents. Otherwise, *Buffer must be allocated
522 from PEI permanent memory.
524 @param This Indicates the
525 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
526 Buffer containing the input GUIDed section to be
527 processed. OutputBuffer OutputBuffer is
528 allocated from PEI permanent memory and contains
529 the new section stream.
530 @param InputSection A pointer to the input buffer, which contains
531 the input section to be processed.
532 @param OutputBuffer A pointer to a caller-allocated buffer, whose
533 size is specified by the contents of OutputSize.
534 @param OutputSize A pointer to a caller-allocated
535 UINTN in which the size of *OutputBuffer
536 allocation is stored. If the function
537 returns anything other than EFI_SUCCESS,
538 the value of OutputSize is undefined.
539 @param AuthenticationStatus A pointer to a caller-allocated
540 UINT32 that indicates the
541 authentication status of the
542 output buffer. If the input
543 section's GuidedSectionHeader.
544 Attributes field has the
545 EFI_GUIDED_SECTION_AUTH_STATUS_VALID
547 AuthenticationStatus must return
548 zero. These bits reflect the
549 status of the extraction
550 operation. If the function
551 returns anything other than
552 EFI_SUCCESS, the value of
553 AuthenticationStatus is
556 @retval EFI_SUCCESS The InputSection was
557 successfully processed and the
558 section contents were returned.
560 @retval EFI_OUT_OF_RESOURCES The system has insufficient
561 resources to process the request.
563 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
564 not match this instance of the
565 GUIDed Section Extraction PPI.
570 CustomGuidedSectionExtract (
571 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*This
,
572 IN CONST VOID
*InputSection
,
573 OUT VOID
**OutputBuffer
,
574 OUT UINTN
*OutputSize
,
575 OUT UINT32
*AuthenticationStatus
579 UINT8
*ScratchBuffer
;
580 UINT32 ScratchBufferSize
;
581 UINT32 OutputBufferSize
;
582 UINT16 SectionAttribute
;
585 // Init local variable
587 ScratchBuffer
= NULL
;
590 // Call GetInfo to get the size and attribute of input guided section data.
592 Status
= ExtractGuidedSectionGetInfo (
599 if (EFI_ERROR (Status
)) {
600 DEBUG ((DEBUG_ERROR
, "GetInfo from guided section Failed - %r\n", Status
));
604 if (ScratchBufferSize
!= 0) {
606 // Allocate scratch buffer
608 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
609 if (ScratchBuffer
== NULL
) {
610 return EFI_OUT_OF_RESOURCES
;
614 if (((SectionAttribute
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) != 0) && OutputBufferSize
> 0) {
616 // Allocate output buffer
618 *OutputBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize
));
619 if (*OutputBuffer
== NULL
) {
620 return EFI_OUT_OF_RESOURCES
;
622 DEBUG ((DEBUG_INFO
, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize
, *OutputBuffer
));
625 Status
= ExtractGuidedSectionDecode (
631 if (EFI_ERROR (Status
)) {
635 DEBUG ((DEBUG_ERROR
, "Extract guided section Failed - %r\n", Status
));
639 *OutputSize
= (UINTN
) OutputBufferSize
;
647 Decompresses a section to the output buffer.
649 This function looks up the compression type field in the input section and
650 applies the appropriate compression algorithm to compress the section to a
651 callee allocated buffer.
653 @param This Points to this instance of the
654 EFI_PEI_DECOMPRESS_PEI PPI.
655 @param CompressionSection Points to the compressed section.
656 @param OutputBuffer Holds the returned pointer to the decompressed
658 @param OutputSize Holds the returned size of the decompress
661 @retval EFI_SUCCESS The section was decompressed successfully.
662 OutputBuffer contains the resulting data and
663 OutputSize contains the resulting size.
669 IN CONST EFI_PEI_DECOMPRESS_PPI
*This
,
670 IN CONST EFI_COMPRESSION_SECTION
*CompressionSection
,
671 OUT VOID
**OutputBuffer
,
672 OUT UINTN
*OutputSize
677 UINT8
*ScratchBuffer
;
678 UINT32 DstBufferSize
;
679 UINT32 ScratchBufferSize
;
680 VOID
*CompressionSource
;
681 UINT32 CompressionSourceSize
;
682 UINT32 UncompressedLength
;
683 UINT8 CompressionType
;
685 if (CompressionSection
->CommonHeader
.Type
!= EFI_SECTION_COMPRESSION
) {
687 return EFI_INVALID_PARAMETER
;
690 if (IS_SECTION2 (CompressionSection
)) {
691 CompressionSource
= (VOID
*) ((UINT8
*) CompressionSection
+ sizeof (EFI_COMPRESSION_SECTION2
));
692 CompressionSourceSize
= (UINT32
) (SECTION2_SIZE (CompressionSection
) - sizeof (EFI_COMPRESSION_SECTION2
));
693 UncompressedLength
= ((EFI_COMPRESSION_SECTION2
*) CompressionSection
)->UncompressedLength
;
694 CompressionType
= ((EFI_COMPRESSION_SECTION2
*) CompressionSection
)->CompressionType
;
696 CompressionSource
= (VOID
*) ((UINT8
*) CompressionSection
+ sizeof (EFI_COMPRESSION_SECTION
));
697 CompressionSourceSize
= (UINT32
) (SECTION_SIZE (CompressionSection
) - sizeof (EFI_COMPRESSION_SECTION
));
698 UncompressedLength
= CompressionSection
->UncompressedLength
;
699 CompressionType
= CompressionSection
->CompressionType
;
703 // This is a compression set, expand it
705 switch (CompressionType
) {
706 case EFI_STANDARD_COMPRESSION
:
707 if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress
)) {
709 // Load EFI standard compression.
710 // For compressed data, decompress them to destination buffer.
712 Status
= UefiDecompressGetInfo (
714 CompressionSourceSize
,
718 if (EFI_ERROR (Status
)) {
722 DEBUG ((DEBUG_ERROR
, "Decompress GetInfo Failed - %r\n", Status
));
723 return EFI_NOT_FOUND
;
726 // Allocate scratch buffer
728 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
729 if (ScratchBuffer
== NULL
) {
730 return EFI_OUT_OF_RESOURCES
;
733 // Allocate destination buffer
735 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
736 if (DstBuffer
== NULL
) {
737 return EFI_OUT_OF_RESOURCES
;
740 // Call decompress function
742 Status
= UefiDecompress (
747 if (EFI_ERROR (Status
)) {
751 DEBUG ((DEBUG_ERROR
, "Decompress Failed - %r\n", Status
));
752 return EFI_NOT_FOUND
;
757 // PcdDxeIplSupportUefiDecompress is FALSE
758 // Don't support UEFI decompression algorithm.
761 return EFI_NOT_FOUND
;
764 case EFI_NOT_COMPRESSED
:
766 // Allocate destination buffer
768 DstBufferSize
= UncompressedLength
;
769 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
770 if (DstBuffer
== NULL
) {
771 return EFI_OUT_OF_RESOURCES
;
774 // stream is not actually compressed, just encapsulated. So just copy it.
776 CopyMem (DstBuffer
, CompressionSource
, DstBufferSize
);
781 // Don't support other unknown compression type.
784 return EFI_NOT_FOUND
;
787 *OutputSize
= DstBufferSize
;
788 *OutputBuffer
= DstBuffer
;
795 Updates the Stack HOB passed to DXE phase.
797 This function traverses the whole HOB list and update the stack HOB to
798 reflect the real stack that is used by DXE core.
800 @param BaseAddress The lower address of stack used by DxeCore.
801 @param Length The length of stack used by DxeCore.
806 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
810 EFI_PEI_HOB_POINTERS Hob
;
812 Hob
.Raw
= GetHobList ();
813 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, Hob
.Raw
)) != NULL
) {
814 if (CompareGuid (&gEfiHobMemoryAllocStackGuid
, &(Hob
.MemoryAllocationStack
->AllocDescriptor
.Name
))) {
816 // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to
817 // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some
818 // PEIMs may also keep key information on stack
820 BuildMemoryAllocationHob (
821 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
,
822 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
,
826 // Update the BSP Stack Hob to reflect the new stack info.
828 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
829 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
= Length
;
832 Hob
.Raw
= GET_NEXT_HOB (Hob
);