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
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.
18 Pei Core Load Image Support
28 IN EFI_PEI_SERVICES
**PeiServices
,
29 IN EFI_FFS_FILE_HEADER
*PeimFileHeader
,
36 Routine for loading file image.
40 PeiServices - The PEI core services table.
41 PeimFileHeader - Pointer to the FFS file header of the image.
42 EntryPoint - Pointer to entry point of specified image file for output.
46 Status - EFI_SUCCESS - Image is successfully loaded.
47 EFI_NOT_FOUND - Fail to locate necessary PPI
48 Others - Fail to load file.
54 EFI_PEI_FV_FILE_LOADER_PPI
*FvLoadFilePpi
;
55 EFI_PHYSICAL_ADDRESS ImageAddress
;
57 EFI_PHYSICAL_ADDRESS ImageEntryPoint
;
58 EFI_TE_IMAGE_HEADER
*TEImageHeader
;
64 // Try to find a PE32 section.
66 Status
= PeiServicesFfsFindSectionData (
72 // If we didn't find a PE32 section, try to find a TE section.
74 if (EFI_ERROR (Status
)) {
75 Status
= PeiServicesFfsFindSectionData (
78 (VOID
**) &TEImageHeader
80 if (EFI_ERROR (Status
) || TEImageHeader
== NULL
) {
82 // There was not a PE32 or a TE section, so assume that it's a Compressed section
83 // and use the LoadFile
85 Status
= PeiServicesLocatePpi (
86 &gEfiPeiFvFileLoaderPpiGuid
,
89 (VOID
**)&FvLoadFilePpi
91 if (EFI_ERROR (Status
)) {
95 Status
= FvLoadFilePpi
->FvLoadFile (
103 if (EFI_ERROR (Status
)) {
104 return EFI_NOT_FOUND
;
108 // Got the entry point from ImageEntryPoint
110 *EntryPoint
= (VOID
*) ((UINTN
) ImageEntryPoint
);
114 // Retrieve the entry point from the TE image header
116 ImageAddress
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) TEImageHeader
;
117 *EntryPoint
= (VOID
*)((UINTN
) TEImageHeader
+ sizeof (EFI_TE_IMAGE_HEADER
) +
118 TEImageHeader
->AddressOfEntryPoint
- TEImageHeader
->StrippedSize
);
122 // Retrieve the entry point from the PE/COFF image header
124 ImageAddress
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) Pe32Data
;
125 Status
= PeCoffLoaderGetEntryPoint (Pe32Data
, EntryPoint
);
126 if (EFI_ERROR (Status
)) {
127 return EFI_NOT_FOUND
;
132 // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
134 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", Pe32Data
, *EntryPoint
));
136 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
139 CHAR8 AsciiBuffer
[512];
142 ZeroMem (&ImageContext
, sizeof (ImageContext
));
143 ImageContext
.Handle
= Pe32Data
;
144 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
146 PeCoffLoaderGetImageInfo (&ImageContext
);
148 if (ImageContext
.PdbPointer
!= NULL
) {
150 // Copy PDB pointer to AsciiBuffer and replace .PDB with .EFI
152 PdbStr
= ImageContext
.PdbPointer
;
153 for (Index
= 0; PdbStr
!= 0; Index
++, PdbStr
++) {
154 AsciiBuffer
[Index
] = *PdbStr
;
155 if (*PdbStr
== '.') {
156 AsciiBuffer
[Index
] = '\0';
160 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "%a.efi", AsciiBuffer
));
165 DEBUG ((EFI_D_INFO
| EFI_D_LOAD
, "\n"));