2 Pei Core Load Image Support
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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
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.
18 EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi
= {
19 PeiLoadImageLoadImageWrapper
23 EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList
= {
24 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiPeiLoadFilePpiGuid
,
31 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file.
32 The function is used for XIP code to have optimized memory copy.
34 @param FileHandle - The handle to the PE/COFF file
35 @param FileOffset - The offset, in bytes, into the file to read
36 @param ReadSize - The number of bytes to read from the file starting at FileOffset
37 @param Buffer - A pointer to the buffer to read the data into.
39 @return EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
54 Destination8
= Buffer
;
55 Source8
= (CHAR8
*) ((UINTN
) FileHandle
+ FileOffset
);
56 if (Destination8
!= Source8
) {
57 CopyMem (Destination8
, Source8
, *ReadSize
);
65 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file.
66 The function is implemented as PIC so as to support shadowing.
68 @param FileHandle - The handle to the PE/COFF file
69 @param FileOffset - The offset, in bytes, into the file to read
70 @param ReadSize - The number of bytes to read from the file starting at FileOffset
71 @param Buffer - A pointer to the buffer to read the data into.
73 @return EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
78 PeiImageReadForShadow (
85 volatile CHAR8
*Destination8
;
89 Destination8
= Buffer
;
90 Source8
= (CHAR8
*) ((UINTN
) FileHandle
+ FileOffset
);
91 if (Destination8
!= Source8
) {
93 while ((Length
--) > 0) {
94 *(Destination8
++) = *(Source8
++);
103 Support routine to get the Image read file function.
105 @param ImageContext - The context of the image being loaded
107 @retval EFI_SUCCESS - If Image function location is found
111 GetImageReadFunction (
112 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
115 PEI_CORE_INSTANCE
*Private
;
118 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
120 if (!Private
->PeiMemoryInstalled
|| (Private
->HobList
.HandoffInformationTable
->BootMode
== BOOT_ON_S3_RESUME
) || EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA64
)) {
121 ImageContext
->ImageRead
= PeiImageRead
;
123 if (Private
->ShadowedImageRead
== NULL
) {
124 MemoryBuffer
= AllocatePages (0x400 / EFI_PAGE_SIZE
+ 1);
125 ASSERT (MemoryBuffer
!= NULL
);
126 CopyMem (MemoryBuffer
, (CONST VOID
*) (UINTN
) PeiImageReadForShadow
, 0x400);
127 Private
->ShadowedImageRead
= (PE_COFF_LOADER_READ_FILE
) (UINTN
) MemoryBuffer
;
130 ImageContext
->ImageRead
= Private
->ShadowedImageRead
;
136 To check memory usage bit map arry to figure out if the memory range the image will be loaded in is available or not. If
137 memory range is avaliable, the function will mark the correponding bits to 1 which indicates the memory range is used.
138 The function is only invoked when load modules at fixed address feature is enabled.
140 @param Private Pointer to the private data passed in from caller
141 @param ImageBase The base addres the image will be loaded at.
142 @param ImageSize The size of the image
144 @retval EFI_SUCCESS The memory range the image will be loaded in is available
145 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
148 CheckAndMarkFixLoadingMemoryUsageBitMap (
149 IN PEI_CORE_INSTANCE
*Private
,
150 IN EFI_PHYSICAL_ADDRESS ImageBase
,
154 UINT32 DxeCodePageNumber
;
155 UINT64 ReservedCodeSize
;
156 EFI_PHYSICAL_ADDRESS PeiCodeBase
;
157 UINT32 BaseOffsetPageNumber
;
158 UINT32 TopOffsetPageNumber
;
160 UINT64
*MemoryUsageBitMap
;
164 // The reserved code range includes RuntimeCodePage range, Boot time code range and PEI code range.
166 DxeCodePageNumber
= PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
);
167 DxeCodePageNumber
+= PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
);
168 ReservedCodeSize
= EFI_PAGES_TO_SIZE(DxeCodePageNumber
+ PcdGet32(PcdLoadFixAddressPeiCodePageNumber
));
169 PeiCodeBase
= Private
->LoadModuleAtFixAddressTopAddress
- ReservedCodeSize
;
172 // Test the memory range for loading the image in the PEI code range.
174 if ((Private
->LoadModuleAtFixAddressTopAddress
- EFI_PAGES_TO_SIZE(DxeCodePageNumber
)) < (ImageBase
+ ImageSize
) ||
175 (PeiCodeBase
> ImageBase
)) {
176 return EFI_NOT_FOUND
;
180 // Test if the memory is avalaible or not.
182 MemoryUsageBitMap
= Private
->PeiCodeMemoryRangeUsageBitMap
;
183 BaseOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
- PeiCodeBase
));
184 TopOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
+ ImageSize
- PeiCodeBase
));
185 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
186 if ((MemoryUsageBitMap
[Index
/ 64] & LShiftU64(1, (Index
% 64))) != 0) {
188 // This page is already used.
190 return EFI_NOT_FOUND
;
195 // Being here means the memory range is available. So mark the bits for the memory range
197 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
198 MemoryUsageBitMap
[Index
/ 64] |= LShiftU64(1, (Index
% 64));
204 Get the fixed loadding address from image header assigned by build tool. This function only be called
205 when Loading module at Fixed address feature enabled.
207 @param ImageContext Pointer to the image context structure that describes the PE/COFF
208 image that needs to be examined by this function.
209 @param Private Pointer to the private data passed in from caller
211 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
212 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
216 GetPeCoffImageFixLoadingAssignedAddress(
217 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
218 IN PEI_CORE_INSTANCE
*Private
221 UINTN SectionHeaderOffset
;
223 EFI_IMAGE_SECTION_HEADER SectionHeader
;
224 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
225 EFI_PHYSICAL_ADDRESS FixLoaddingAddress
;
228 UINT16 NumberOfSections
;
229 UINT64 ValueInSectionHeader
;
232 FixLoaddingAddress
= 0;
233 Status
= EFI_NOT_FOUND
;
236 // Get PeHeader pointer
238 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
239 if (ImageContext
->IsTeImage
) {
241 // for TE image, the fix loadding address is saved in first section header that doesn't point
244 SectionHeaderOffset
= sizeof (EFI_TE_IMAGE_HEADER
);
245 NumberOfSections
= ImgHdr
->Te
.NumberOfSections
;
247 SectionHeaderOffset
= (UINTN
)(
248 ImageContext
->PeCoffHeaderOffset
+
250 sizeof (EFI_IMAGE_FILE_HEADER
) +
251 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
253 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
256 // Get base address from the first section header that doesn't point to code section.
258 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
260 // Read section header from file
262 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
263 Status
= ImageContext
->ImageRead (
264 ImageContext
->Handle
,
269 if (EFI_ERROR (Status
)) {
273 Status
= EFI_NOT_FOUND
;
275 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
277 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
278 // that doesn't point to code section in image header, as well as ImageBase field of image header. A notable thing is
279 // that for PEIM, the value in ImageBase field may not be equal to the value in PointerToRelocations & PointerToLineNumbers because
280 // for XIP PEIM, ImageBase field holds the image base address running on the Flash. And PointerToRelocations & PointerToLineNumbers
281 // hold the image base address when it is shadow to the memory. And there is an assumption that when the feature is enabled, if a
282 // module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers fields should NOT be Zero, or
283 // else, these 2 fileds should be set to Zero
285 ValueInSectionHeader
= ReadUnaligned64((UINT64
*)&SectionHeader
.PointerToRelocations
);
286 if (ValueInSectionHeader
!= 0) {
288 // Found first section header that doesn't point to code section.
290 if ((INT64
)PcdGet64(PcdLoadModuleAtFixAddressEnable
) > 0) {
292 // When LMFA feature is configured as Load Module at Fixed Absolute Address mode, PointerToRelocations & PointerToLineNumbers field
293 // hold the absolute address of image base runing in memory
295 FixLoaddingAddress
= ValueInSectionHeader
;
298 // When LMFA feature is configured as Load Module at Fixed offset mode, PointerToRelocations & PointerToLineNumbers field
299 // hold the offset relative to a platform-specific top address.
301 FixLoaddingAddress
= (EFI_PHYSICAL_ADDRESS
)(Private
->LoadModuleAtFixAddressTopAddress
+ (INT64
)ValueInSectionHeader
);
304 // Check if the memory range is avaliable.
306 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (Private
, FixLoaddingAddress
, (UINT32
) ImageContext
->ImageSize
);
307 if (!EFI_ERROR(Status
)) {
309 // The assigned address is valid. Return the specified loadding address
311 ImageContext
->ImageAddress
= FixLoaddingAddress
;
316 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
318 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status= %r \n", (VOID
*)(UINTN
)FixLoaddingAddress
, Status
));
323 Loads and relocates a PE/COFF image into memory.
324 If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.
326 @param Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
327 @param ImageAddress - The base address of the relocated PE/COFF image
328 @param ImageSize - The size of the relocated PE/COFF image
329 @param EntryPoint - The entry point of the relocated PE/COFF image
331 @retval EFI_SUCCESS The file was loaded and relocated
332 @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and relocate the PE/COFF file
336 LoadAndRelocatePeCoffImage (
338 OUT EFI_PHYSICAL_ADDRESS
*ImageAddress
,
339 OUT UINT64
*ImageSize
,
340 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
344 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
345 PEI_CORE_INSTANCE
*Private
;
347 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
349 ZeroMem (&ImageContext
, sizeof (ImageContext
));
350 ImageContext
.Handle
= Pe32Data
;
351 Status
= GetImageReadFunction (&ImageContext
);
353 ASSERT_EFI_ERROR (Status
);
355 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
356 if (EFI_ERROR (Status
)) {
360 // When Image has no reloc section, it can't be relocated into memory.
362 if (ImageContext
.RelocationsStripped
&& (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
363 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN
) Pe32Data
));
367 // Set default base address to current image address.
369 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Pe32Data
;
372 // Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.
374 if ((!ImageContext
.RelocationsStripped
) && (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
375 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0) {
376 Status
= GetPeCoffImageFixLoadingAssignedAddress(&ImageContext
, Private
);
377 if (EFI_ERROR (Status
)){
378 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
380 // The PEIM is not assiged valid address, try to allocate page to load it.
382 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
385 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32
) ImageContext
.ImageSize
));
387 ASSERT (ImageContext
.ImageAddress
!= 0);
388 if (ImageContext
.ImageAddress
== 0) {
389 return EFI_OUT_OF_RESOURCES
;
393 // Skip the reserved space for the stripped PeHeader when load TeImage into memory.
395 if (ImageContext
.IsTeImage
) {
396 ImageContext
.ImageAddress
= ImageContext
.ImageAddress
+
397 ((EFI_TE_IMAGE_HEADER
*) Pe32Data
)->StrippedSize
-
398 sizeof (EFI_TE_IMAGE_HEADER
);
403 // Load the image to our new buffer
405 Status
= PeCoffLoaderLoadImage (&ImageContext
);
406 if (EFI_ERROR (Status
)) {
410 // Relocate the image in our new buffer
412 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
413 if (EFI_ERROR (Status
)) {
418 // Flush the instruction cache so the image data is written before we execute it
420 if ((!ImageContext
.RelocationsStripped
) && (Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
421 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
424 *ImageAddress
= ImageContext
.ImageAddress
;
425 *ImageSize
= ImageContext
.ImageSize
;
426 *EntryPoint
= ImageContext
.EntryPoint
;
432 Loads a PEIM into memory for subsequent execution. If there are compressed
433 images or images that need to be relocated into memory for performance reasons,
434 this service performs that transformation.
436 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
437 @param FileHandle Pointer to the FFS file header of the image.
438 @param ImageAddressArg Pointer to PE/TE image.
439 @param ImageSizeArg Size of PE/TE image.
440 @param EntryPoint Pointer to entry point of specified image file for output.
441 @param AuthenticationState - Pointer to attestation authentication state of image.
443 @retval EFI_SUCCESS Image is successfully loaded.
444 @retval EFI_NOT_FOUND Fail to locate necessary PPI.
445 @retval EFI_UNSUPPORTED Image Machine Type is not supported.
449 PeiLoadImageLoadImage (
450 IN CONST EFI_PEI_SERVICES
**PeiServices
,
451 IN EFI_PEI_FILE_HANDLE FileHandle
,
452 OUT EFI_PHYSICAL_ADDRESS
*ImageAddressArg
, OPTIONAL
453 OUT UINT64
*ImageSizeArg
, OPTIONAL
454 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
455 OUT UINT32
*AuthenticationState
460 EFI_PHYSICAL_ADDRESS ImageAddress
;
462 EFI_PHYSICAL_ADDRESS ImageEntryPoint
;
464 EFI_SECTION_TYPE SearchType1
;
465 EFI_SECTION_TYPE SearchType2
;
469 *AuthenticationState
= 0;
471 if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst
)) {
472 SearchType1
= EFI_SECTION_TE
;
473 SearchType2
= EFI_SECTION_PE32
;
475 SearchType1
= EFI_SECTION_PE32
;
476 SearchType2
= EFI_SECTION_TE
;
480 // Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst
481 // is true, TE will be searched first).
483 Status
= PeiServicesFfsFindSectionData (
489 // If we didn't find a first exe section, try to find the second exe section.
491 if (EFI_ERROR (Status
)) {
492 Status
= PeiServicesFfsFindSectionData (
497 if (EFI_ERROR (Status
)) {
499 // PEI core only carry the loader function fro TE and PE32 executables
500 // If this two section does not exist, just return.
507 // If memory is installed, perform the shadow operations
509 Status
= LoadAndRelocatePeCoffImage (
516 ASSERT_EFI_ERROR (Status
);
519 if (EFI_ERROR (Status
)) {
524 // Got the entry point from the loaded Pe32Data
526 Pe32Data
= (VOID
*) ((UINTN
) ImageAddress
);
527 *EntryPoint
= ImageEntryPoint
;
529 Machine
= PeCoffLoaderGetMachineType (Pe32Data
);
531 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Machine
)) {
532 if (!EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Machine
)) {
533 return EFI_UNSUPPORTED
;
537 if (ImageAddressArg
!= NULL
) {
538 *ImageAddressArg
= ImageAddress
;
541 if (ImageSizeArg
!= NULL
) {
542 *ImageSizeArg
= ImageSize
;
547 CHAR8 AsciiBuffer
[512];
552 // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
554 if (Machine
!= EFI_IMAGE_MACHINE_IA64
) {
555 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)*EntryPoint
));
558 // For IPF Image, the real entry point should be print.
560 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID
*)(UINTN
)ImageAddress
, (VOID
*)(UINTN
)(*(UINT64
*)(UINTN
)*EntryPoint
)));
564 // Print Module Name by PeImage PDB file name.
566 AsciiString
= PeCoffLoaderGetPdbPointer (Pe32Data
);
568 if (AsciiString
!= NULL
) {
569 for (Index
= (INT32
) AsciiStrLen (AsciiString
) - 1; Index
>= 0; Index
--) {
570 if (AsciiString
[Index
] == '\\') {
576 for (Index1
= 0; AsciiString
[Index
+ 1 + Index1
] != '.'; Index1
++) {
577 AsciiBuffer
[Index1
] = AsciiString
[Index
+ 1 + Index1
];
579 AsciiBuffer
[Index1
] = '\0';
580 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "%a.efi", AsciiBuffer
));
586 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "\n"));
594 The wrapper function of PeiLoadImageLoadImage().
596 @param This - Pointer to EFI_PEI_LOAD_FILE_PPI.
597 @param FileHandle - Pointer to the FFS file header of the image.
598 @param ImageAddressArg - Pointer to PE/TE image.
599 @param ImageSizeArg - Size of PE/TE image.
600 @param EntryPoint - Pointer to entry point of specified image file for output.
601 @param AuthenticationState - Pointer to attestation authentication state of image.
603 @return Status of PeiLoadImageLoadImage().
608 PeiLoadImageLoadImageWrapper (
609 IN CONST EFI_PEI_LOAD_FILE_PPI
*This
,
610 IN EFI_PEI_FILE_HANDLE FileHandle
,
611 OUT EFI_PHYSICAL_ADDRESS
*ImageAddressArg
, OPTIONAL
612 OUT UINT64
*ImageSizeArg
, OPTIONAL
613 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
614 OUT UINT32
*AuthenticationState
617 return PeiLoadImageLoadImage (
618 GetPeiServicesTablePointer (),
628 Check whether the input image has the relocation.
630 @param Pe32Data Pointer to the PE/COFF or TE image.
632 @retval TRUE Relocation is stripped.
633 @retval FALSE Relocation is not stripped.
641 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
642 EFI_IMAGE_DOS_HEADER
*DosHdr
;
644 ASSERT (Pe32Data
!= NULL
);
646 DosHdr
= (EFI_IMAGE_DOS_HEADER
*)Pe32Data
;
647 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
649 // DOS image header is present, so read the PE header after the DOS image header.
651 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)((UINTN
) Pe32Data
+ (UINTN
) ((DosHdr
->e_lfanew
) & 0x0ffff));
654 // DOS image header is not present, so PE header is at the image base.
656 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*)Pe32Data
;
660 // Three cases with regards to relocations:
661 // - Image has base relocs, RELOCS_STRIPPED==0 => image is relocatable
662 // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable
663 // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but
664 // has no base relocs to apply
665 // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.
667 // Look at the file header to determine if relocations have been stripped, and
668 // save this info in the image context for later use.
670 if (Hdr
.Te
->Signature
== EFI_TE_IMAGE_HEADER_SIGNATURE
) {
671 if ((Hdr
.Te
->DataDirectory
[0].Size
== 0) && (Hdr
.Te
->DataDirectory
[0].VirtualAddress
== 0)) {
676 } else if (Hdr
.Pe32
->Signature
== EFI_IMAGE_NT_SIGNATURE
) {
677 if ((Hdr
.Pe32
->FileHeader
.Characteristics
& EFI_IMAGE_FILE_RELOCS_STRIPPED
) != 0) {
688 Routine to load image file for subsequent execution by LoadFile Ppi.
689 If any LoadFile Ppi is not found, the build-in support function for the PE32+/TE
690 XIP image format is used.
692 @param PeiServices - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
693 @param FileHandle - Pointer to the FFS file header of the image.
694 @param PeimState - The dispatch state of the input PEIM handle.
695 @param EntryPoint - Pointer to entry point of specified image file for output.
696 @param AuthenticationState - Pointer to attestation authentication state of image.
698 @retval EFI_SUCCESS - Image is successfully loaded.
699 @retval EFI_NOT_FOUND - Fail to locate necessary PPI
700 @retval Others - Fail to load file.
705 IN CONST EFI_PEI_SERVICES
**PeiServices
,
706 IN EFI_PEI_FILE_HANDLE FileHandle
,
708 OUT EFI_PHYSICAL_ADDRESS
*EntryPoint
,
709 OUT UINT32
*AuthenticationState
712 EFI_STATUS PpiStatus
;
715 EFI_PEI_LOAD_FILE_PPI
*LoadFile
;
716 EFI_PHYSICAL_ADDRESS ImageAddress
;
722 // If any instances of PEI_LOAD_FILE_PPI are installed, they are called.
723 // one at a time, until one reports EFI_SUCCESS.
727 PpiStatus
= PeiServicesLocatePpi (
728 &gEfiPeiLoadFilePpiGuid
,
733 if (!EFI_ERROR (PpiStatus
)) {
734 Status
= LoadFile
->LoadFile (
742 if (!EFI_ERROR (Status
)) {
744 // The shadowed PEIM must be relocatable.
746 if (PeimState
== PEIM_STATE_REGISITER_FOR_SHADOW
) {
747 IsStrip
= RelocationIsStrip ((VOID
*) (UINTN
) ImageAddress
);
750 return EFI_UNSUPPORTED
;
755 // The image to be started must have the machine type supported by PeiCore.
757 ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID
*) (UINTN
) ImageAddress
)));
758 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID
*) (UINTN
) ImageAddress
))) {
759 return EFI_UNSUPPORTED
;
765 } while (!EFI_ERROR (PpiStatus
));
773 Install Pei Load File PPI.
776 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
777 @param OldCoreData - Pointer to PEI_CORE_INSTANCE.
781 InitializeImageServices (
782 IN PEI_CORE_INSTANCE
*PrivateData
,
783 IN PEI_CORE_INSTANCE
*OldCoreData
786 if (OldCoreData
== NULL
) {
788 // The first time we are XIP (running from FLASH). We need to remember the
789 // FLASH address so we can reinstall the memory version that runs faster
791 PrivateData
->XipLoadFile
= &gPpiLoadFilePpiList
;
792 PeiServicesInstallPpi (PrivateData
->XipLoadFile
);
795 // 2nd time we are running from memory so replace the XIP version with the
796 // new memory version.
798 PeiServicesReInstallPpi (PrivateData
->XipLoadFile
, &gPpiLoadFilePpiList
);