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
14 // Module Globals used in the DXE to PEI hand off
15 // These must be module globals, so the stack can be switched
17 CONST EFI_DXE_IPL_PPI mDxeIplPpi
= {
21 CONST EFI_PEI_PPI_DESCRIPTOR mDxeIplPpiList
= {
22 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
27 CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi
= {
28 CustomGuidedSectionExtract
31 CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi
= {
35 CONST EFI_PEI_PPI_DESCRIPTOR mDecompressPpiList
= {
36 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
37 &gEfiPeiDecompressPpiGuid
,
38 (VOID
*)&mDecompressPpi
41 CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi
= {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
43 &gEfiEndOfPeiSignalPpiGuid
,
47 CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList
= {
48 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
49 &gEfiPeiMemoryDiscoveredPpiGuid
,
50 InstallIplPermanentMemoryPpis
54 Entry point of DXE IPL PEIM.
56 This function installs DXE IPL PPI. It also reloads
57 itself to memory on non-S3 resume boot path.
59 @param FileHandle Handle of the file being invoked.
60 @param PeiServices Describes the list of possible PEI Services.
62 @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
63 @retval Others Some error occurs during the execution of this function.
68 PeimInitializeDxeIpl (
69 IN EFI_PEI_FILE_HANDLE FileHandle
,
70 IN CONST EFI_PEI_SERVICES
**PeiServices
74 EFI_BOOT_MODE BootMode
;
77 BootMode
= GetBootModeHob ();
79 if (BootMode
!= BOOT_ON_S3_RESUME
) {
80 Status
= PeiServicesRegisterForShadow (FileHandle
);
81 if (Status
== EFI_SUCCESS
) {
83 // EFI_SUCESS means it is the first time to call register for shadow.
89 // Ensure that DXE IPL is shadowed to permanent memory.
91 ASSERT (Status
== EFI_ALREADY_STARTED
);
94 // DXE core load requires permanent memory.
96 Status
= PeiServicesLocatePpi (
97 &gEfiPeiMemoryDiscoveredPpiGuid
,
102 ASSERT_EFI_ERROR (Status
);
103 if (EFI_ERROR (Status
)) {
108 // Now the permanent memory exists, install the PPIs for decompression
109 // and section extraction.
111 Status
= InstallIplPermanentMemoryPpis (NULL
, NULL
, NULL
);
112 ASSERT_EFI_ERROR (Status
);
115 // Install memory discovered PPI notification to install PPIs for
116 // decompression and section extraction.
118 Status
= PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList
);
119 ASSERT_EFI_ERROR (Status
);
123 // Install DxeIpl PPI.
125 Status
= PeiServicesInstallPpi (&mDxeIplPpiList
);
126 ASSERT_EFI_ERROR (Status
);
132 This function installs the PPIs that require permanent memory.
134 @param PeiServices Indirect reference to the PEI Services Table.
135 @param NotifyDescriptor Address of the notification descriptor data structure.
136 @param Ppi Address of the PPI that was installed.
138 @return EFI_SUCCESS The PPIs were installed successfully.
139 @return Others Some error occurs during the execution of this function.
144 InstallIplPermanentMemoryPpis (
145 IN EFI_PEI_SERVICES
**PeiServices
,
146 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
151 EFI_GUID
*ExtractHandlerGuidTable
;
152 UINTN ExtractHandlerNumber
;
153 EFI_PEI_PPI_DESCRIPTOR
*GuidPpi
;
156 // Get custom extract guided section method guid list
158 ExtractHandlerNumber
= ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable
);
161 // Install custom guided section extraction PPI
163 if (ExtractHandlerNumber
> 0) {
164 GuidPpi
= (EFI_PEI_PPI_DESCRIPTOR
*)AllocatePool (ExtractHandlerNumber
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
165 ASSERT (GuidPpi
!= NULL
);
166 while (ExtractHandlerNumber
-- > 0) {
167 GuidPpi
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
168 GuidPpi
->Ppi
= (VOID
*)&mCustomGuidedSectionExtractionPpi
;
169 GuidPpi
->Guid
= &ExtractHandlerGuidTable
[ExtractHandlerNumber
];
170 Status
= PeiServicesInstallPpi (GuidPpi
++);
171 ASSERT_EFI_ERROR (Status
);
176 // Install Decompress PPI.
178 Status
= PeiServicesInstallPpi (&mDecompressPpiList
);
179 ASSERT_EFI_ERROR (Status
);
185 Validate variable data for the MemoryTypeInformation.
187 @param MemoryData Variable data.
188 @param MemoryDataSize Variable data length.
190 @return TRUE The variable data is valid.
191 @return FALSE The variable data is invalid.
195 ValidateMemoryTypeInfoVariable (
196 IN EFI_MEMORY_TYPE_INFORMATION
*MemoryData
,
197 IN UINTN MemoryDataSize
203 // Check the input parameter.
204 if (MemoryData
== NULL
) {
209 Count
= MemoryDataSize
/ sizeof (*MemoryData
);
212 if (Count
* sizeof (*MemoryData
) != MemoryDataSize
) {
216 // Check last entry type filed.
217 if (MemoryData
[Count
- 1].Type
!= EfiMaxMemoryType
) {
221 // Check the type filed.
222 for (Index
= 0; Index
< Count
- 1; Index
++) {
223 if (MemoryData
[Index
].Type
>= EfiMaxMemoryType
) {
232 Main entry point to last PEIM.
234 This function finds DXE Core in the firmware volume and transfer the control to
237 @param This Entry point for DXE IPL PPI.
238 @param PeiServices General purpose services available to every PEIM.
239 @param HobList Address to the Pei HOB list.
241 @return EFI_SUCCESS DXE core was successfully loaded.
242 @return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.
248 IN CONST EFI_DXE_IPL_PPI
*This
,
249 IN EFI_PEI_SERVICES
**PeiServices
,
250 IN EFI_PEI_HOB_POINTERS HobList
254 EFI_FV_FILE_INFO DxeCoreFileInfo
;
255 EFI_PHYSICAL_ADDRESS DxeCoreAddress
;
257 EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
;
258 EFI_BOOT_MODE BootMode
;
259 EFI_PEI_FILE_HANDLE FileHandle
;
260 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
261 EFI_PEI_LOAD_FILE_PPI
*LoadFile
;
263 UINT32 AuthenticationState
;
265 EFI_PEI_S3_RESUME2_PPI
*S3Resume
;
266 EFI_PEI_RECOVERY_MODULE_PPI
*PeiRecovery
;
267 EDKII_PEI_CAPSULE_ON_DISK_PPI
*PeiCapsuleOnDisk
;
268 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
269 VOID
*CapsuleOnDiskModePpi
;
272 // if in S3 Resume, restore configure
274 BootMode
= GetBootModeHob ();
276 if (BootMode
== BOOT_ON_S3_RESUME
) {
277 Status
= PeiServicesLocatePpi (
278 &gEfiPeiS3Resume2PpiGuid
,
283 if (EFI_ERROR (Status
)) {
285 // Report Status code that S3Resume PPI can not be found
288 EFI_ERROR_CODE
| EFI_ERROR_MAJOR
,
289 (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
)
332 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_PC_CAPSULE_START
));
334 // Now should have a HOB with the DXE core
336 } else if (BootMode
== BOOT_ON_FLASH_UPDATE
) {
338 // If Capsule On Disk mode, call storage stack to read Capsule Relocation file
339 // IoMmmu is highly recommmended to enable before reading
341 Status
= PeiServicesLocatePpi (
342 &gEdkiiPeiBootInCapsuleOnDiskModePpiGuid
,
345 &CapsuleOnDiskModePpi
347 if (!EFI_ERROR (Status
)) {
348 Status
= PeiServicesLocatePpi (
349 &gEdkiiPeiCapsuleOnDiskPpiGuid
,
352 (VOID
**)&PeiCapsuleOnDisk
356 // Whether failed, still goes to Firmware Update boot path. BDS will clear corresponding indicator and reboot later on
358 if (!EFI_ERROR (Status
)) {
359 Status
= PeiCapsuleOnDisk
->LoadCapsuleOnDisk (PeiServices
, PeiCapsuleOnDisk
);
364 if (GetFirstGuidHob ((CONST EFI_GUID
*)&gEfiMemoryTypeInformationGuid
) == NULL
) {
366 // Don't build GuidHob if GuidHob has been installed.
368 Status
= PeiServicesLocatePpi (
369 &gEfiPeiReadOnlyVariable2PpiGuid
,
374 if (!EFI_ERROR (Status
)) {
375 DataSize
= sizeof (MemoryData
);
376 Status
= Variable
->GetVariable (
378 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
379 &gEfiMemoryTypeInformationGuid
,
384 if (!EFI_ERROR (Status
) && ValidateMemoryTypeInfoVariable (MemoryData
, DataSize
)) {
386 // Build the GUID'd HOB for DXE
389 &gEfiMemoryTypeInformationGuid
,
398 // Look in all the FVs present in PEI and find the DXE Core FileHandle
400 FileHandle
= DxeIplFindDxeCore ();
403 // Load the DXE Core from a Firmware Volume.
407 Status
= PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid
, Instance
++, NULL
, (VOID
**)&LoadFile
);
409 // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.
411 ASSERT_EFI_ERROR (Status
);
413 Status
= LoadFile
->LoadFile (
421 } while (EFI_ERROR (Status
));
424 // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.
426 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &DxeCoreFileInfo
);
427 ASSERT_EFI_ERROR (Status
);
430 // Add HOB for the DXE Core
433 &DxeCoreFileInfo
.FileName
,
435 ALIGN_VALUE (DxeCoreSize
, EFI_PAGE_SIZE
),
440 // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT
442 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT
));
444 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID
*)(UINTN
)DxeCoreAddress
, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint
)));
447 // Transfer control to the DXE Core
448 // The hand off state is simply a pointer to the HOB list
450 HandOffToDxeCore (DxeCoreEntryPoint
, HobList
);
452 // If we get here, then the DXE Core returned. This is an error
453 // DxeCore should not return.
458 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
));
492 ASSERT_EFI_ERROR (Status
);
495 // Find the DxeCore file type from the beginning in this firmware volume.
498 Status
= PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE
, VolumeHandle
, &FileHandle
);
499 if (!EFI_ERROR (Status
)) {
501 // Find DxeCore FileHandle in this volume, then we skip other firmware volume and
502 // return the FileHandle.
508 // 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
;
623 DEBUG ((DEBUG_INFO
, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize
, *OutputBuffer
));
626 Status
= ExtractGuidedSectionDecode (
632 if (EFI_ERROR (Status
)) {
636 DEBUG ((DEBUG_ERROR
, "Extract guided section Failed - %r\n", Status
));
640 *OutputSize
= (UINTN
)OutputBufferSize
;
646 Decompresses a section to the output buffer.
648 This function looks up the compression type field in the input section and
649 applies the appropriate compression algorithm to compress the section to a
650 callee allocated buffer.
652 @param This Points to this instance of the
653 EFI_PEI_DECOMPRESS_PEI PPI.
654 @param CompressionSection Points to the compressed section.
655 @param OutputBuffer Holds the returned pointer to the decompressed
657 @param OutputSize Holds the returned size of the decompress
660 @retval EFI_SUCCESS The section was decompressed successfully.
661 OutputBuffer contains the resulting data and
662 OutputSize contains the resulting size.
668 IN CONST EFI_PEI_DECOMPRESS_PPI
*This
,
669 IN CONST EFI_COMPRESSION_SECTION
*CompressionSection
,
670 OUT VOID
**OutputBuffer
,
671 OUT UINTN
*OutputSize
676 UINT8
*ScratchBuffer
;
677 UINT32 DstBufferSize
;
678 UINT32 ScratchBufferSize
;
679 VOID
*CompressionSource
;
680 UINT32 CompressionSourceSize
;
681 UINT32 UncompressedLength
;
682 UINT8 CompressionType
;
684 if (CompressionSection
->CommonHeader
.Type
!= EFI_SECTION_COMPRESSION
) {
686 return EFI_INVALID_PARAMETER
;
689 if (IS_SECTION2 (CompressionSection
)) {
690 CompressionSource
= (VOID
*)((UINT8
*)CompressionSection
+ sizeof (EFI_COMPRESSION_SECTION2
));
691 CompressionSourceSize
= (UINT32
)(SECTION2_SIZE (CompressionSection
) - sizeof (EFI_COMPRESSION_SECTION2
));
692 UncompressedLength
= ((EFI_COMPRESSION_SECTION2
*)CompressionSection
)->UncompressedLength
;
693 CompressionType
= ((EFI_COMPRESSION_SECTION2
*)CompressionSection
)->CompressionType
;
695 CompressionSource
= (VOID
*)((UINT8
*)CompressionSection
+ sizeof (EFI_COMPRESSION_SECTION
));
696 CompressionSourceSize
= (UINT32
)(SECTION_SIZE (CompressionSection
) - sizeof (EFI_COMPRESSION_SECTION
));
697 UncompressedLength
= CompressionSection
->UncompressedLength
;
698 CompressionType
= CompressionSection
->CompressionType
;
702 // This is a compression set, expand it
704 switch (CompressionType
) {
705 case EFI_STANDARD_COMPRESSION
:
706 if (FeaturePcdGet (PcdDxeIplSupportUefiDecompress
)) {
708 // Load EFI standard compression.
709 // For compressed data, decompress them to destination buffer.
711 Status
= UefiDecompressGetInfo (
713 CompressionSourceSize
,
717 if (EFI_ERROR (Status
)) {
721 DEBUG ((DEBUG_ERROR
, "Decompress GetInfo Failed - %r\n", Status
));
722 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
;
734 // Allocate destination buffer
736 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
737 if (DstBuffer
== NULL
) {
738 return EFI_OUT_OF_RESOURCES
;
742 // Call decompress function
744 Status
= UefiDecompress (
749 if (EFI_ERROR (Status
)) {
753 DEBUG ((DEBUG_ERROR
, "Decompress Failed - %r\n", Status
));
754 return EFI_NOT_FOUND
;
760 // PcdDxeIplSupportUefiDecompress is FALSE
761 // Don't support UEFI decompression algorithm.
764 return EFI_NOT_FOUND
;
767 case EFI_NOT_COMPRESSED
:
769 // Allocate destination buffer
771 DstBufferSize
= UncompressedLength
;
772 DstBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
773 if (DstBuffer
== NULL
) {
774 return EFI_OUT_OF_RESOURCES
;
778 // stream is not actually compressed, just encapsulated. So just copy it.
780 CopyMem (DstBuffer
, CompressionSource
, DstBufferSize
);
785 // Don't support other unknown compression type.
788 return EFI_NOT_FOUND
;
791 *OutputSize
= DstBufferSize
;
792 *OutputBuffer
= DstBuffer
;
798 Updates the Stack HOB passed to DXE phase.
800 This function traverses the whole HOB list and update the stack HOB to
801 reflect the real stack that is used by DXE core.
803 @param BaseAddress The lower address of stack used by DxeCore.
804 @param Length The length of stack used by DxeCore.
809 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
813 EFI_PEI_HOB_POINTERS Hob
;
815 Hob
.Raw
= GetHobList ();
816 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, Hob
.Raw
)) != NULL
) {
817 if (CompareGuid (&gEfiHobMemoryAllocStackGuid
, &(Hob
.MemoryAllocationStack
->AllocDescriptor
.Name
))) {
819 // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to
820 // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some
821 // PEIMs may also keep key information on stack
823 BuildMemoryAllocationHob (
824 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
,
825 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
,
829 // Update the BSP Stack Hob to reflect the new stack info.
831 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
832 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
= Length
;
836 Hob
.Raw
= GET_NEXT_HOB (Hob
);