2 Locate the entry point for the PEI Core
4 Copyright (c) 2008 - 2019, 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.
22 @param FirmwareVolumePtr Point to the firmware volume for finding core image.
23 @param FileType The FileType for searching, either SecCore or PeiCore.
24 @param CoreImageBase The base address of the core image.
30 IN EFI_FIRMWARE_VOLUME_HEADER
*FirmwareVolumePtr
,
31 IN EFI_FV_FILETYPE FileType
,
32 OUT EFI_PHYSICAL_ADDRESS
*CoreImageBase
35 EFI_PHYSICAL_ADDRESS CurrentAddress
;
36 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
37 EFI_FFS_FILE_HEADER
*File
;
39 EFI_PHYSICAL_ADDRESS EndOfFile
;
40 EFI_COMMON_SECTION_HEADER
*Section
;
41 EFI_PHYSICAL_ADDRESS EndOfSection
;
45 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) FirmwareVolumePtr
;
46 EndOfFirmwareVolume
= CurrentAddress
+ FirmwareVolumePtr
->FvLength
;
49 // Loop through the FFS files in the Boot Firmware Volume
51 for (EndOfFile
= CurrentAddress
+ FirmwareVolumePtr
->HeaderLength
; ; ) {
53 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
54 if (CurrentAddress
> EndOfFirmwareVolume
) {
58 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
59 if (IS_FFS_FILE2 (File
)) {
60 Size
= FFS_FILE2_SIZE (File
);
61 if (Size
<= 0x00FFFFFF) {
65 Size
= FFS_FILE_SIZE (File
);
66 if (Size
< sizeof (EFI_FFS_FILE_HEADER
)) {
71 EndOfFile
= CurrentAddress
+ Size
;
72 if (EndOfFile
> EndOfFirmwareVolume
) {
77 // Look for particular Core file (either SEC Core or PEI Core)
79 if (File
->Type
!= FileType
) {
84 // Loop through the FFS file sections within the FFS file
86 if (IS_FFS_FILE2 (File
)) {
87 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER2
));
89 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER
));
92 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
93 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
95 if (IS_SECTION2 (Section
)) {
96 Size
= SECTION2_SIZE (Section
);
97 if (Size
<= 0x00FFFFFF) {
101 Size
= SECTION_SIZE (Section
);
102 if (Size
< sizeof (EFI_COMMON_SECTION_HEADER
)) {
103 return EFI_NOT_FOUND
;
107 EndOfSection
= CurrentAddress
+ Size
;
108 if (EndOfSection
> EndOfFile
) {
109 return EFI_NOT_FOUND
;
113 // Look for executable sections
115 if (Section
->Type
== EFI_SECTION_PE32
|| Section
->Type
== EFI_SECTION_TE
) {
116 if (File
->Type
== FileType
) {
117 if (IS_SECTION2 (Section
)) {
118 *CoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
120 *CoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
128 // Either SEC Core or PEI Core images found
130 if (*CoreImageBase
!= 0) {
137 Find and return Pei Core entry point.
139 It also find SEC and PEI Core file debug information. It will report them if
140 remote debug is enabled.
142 @param SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.
143 @param PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.
144 @param PeiCoreEntryPoint The entry point of the PEI core.
149 FindAndReportEntryPoints (
150 IN EFI_FIRMWARE_VOLUME_HEADER
*SecCoreFirmwareVolumePtr
,
151 IN EFI_FIRMWARE_VOLUME_HEADER
*PeiCoreFirmwareVolumePtr
,
152 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
156 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
157 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
158 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
161 // Find SEC Core image base
163 Status
= FindImageBase (SecCoreFirmwareVolumePtr
, EFI_FV_FILETYPE_SECURITY_CORE
, &SecCoreImageBase
);
164 ASSERT_EFI_ERROR (Status
);
166 ZeroMem ((VOID
*) &ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
168 // Report SEC Core debug information when remote debug is enabled
170 ImageContext
.ImageAddress
= SecCoreImageBase
;
171 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
172 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
175 // Find PEI Core image base
177 Status
= FindImageBase (PeiCoreFirmwareVolumePtr
, EFI_FV_FILETYPE_PEI_CORE
, &PeiCoreImageBase
);
178 ASSERT_EFI_ERROR (Status
);
181 // Report PEI Core debug information when remote debug is enabled
183 ImageContext
.ImageAddress
= PeiCoreImageBase
;
184 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
185 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
188 // Find PEI Core entry point
190 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) (UINTN
) PeiCoreImageBase
, (VOID
**) PeiCoreEntryPoint
);
191 if (EFI_ERROR (Status
)) {
192 *PeiCoreEntryPoint
= 0;