2 Locate the entry point for the PEI Core
4 Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 @param FirmwareVolumePtr Point to the firmware volume for finding core image.
17 @param FileType The FileType for searching, either SecCore or PeiCore.
18 @param CoreImageBase The base address of the core image.
24 IN EFI_FIRMWARE_VOLUME_HEADER
*FirmwareVolumePtr
,
25 IN EFI_FV_FILETYPE FileType
,
26 OUT EFI_PHYSICAL_ADDRESS
*CoreImageBase
29 EFI_PHYSICAL_ADDRESS CurrentAddress
;
30 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
31 EFI_FFS_FILE_HEADER
*File
;
33 EFI_PHYSICAL_ADDRESS EndOfFile
;
34 EFI_COMMON_SECTION_HEADER
*Section
;
35 EFI_PHYSICAL_ADDRESS EndOfSection
;
39 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)FirmwareVolumePtr
;
40 EndOfFirmwareVolume
= CurrentAddress
+ FirmwareVolumePtr
->FvLength
;
43 // Loop through the FFS files in the Boot Firmware Volume
45 for (EndOfFile
= CurrentAddress
+ FirmwareVolumePtr
->HeaderLength
; ; ) {
46 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
47 if (CurrentAddress
> EndOfFirmwareVolume
) {
51 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
)CurrentAddress
;
52 if (IS_FFS_FILE2 (File
)) {
53 Size
= FFS_FILE2_SIZE (File
);
54 if (Size
<= 0x00FFFFFF) {
58 Size
= FFS_FILE_SIZE (File
);
59 if (Size
< sizeof (EFI_FFS_FILE_HEADER
)) {
64 EndOfFile
= CurrentAddress
+ Size
;
65 if (EndOfFile
> EndOfFirmwareVolume
) {
70 // Look for particular Core file (either SEC Core or PEI Core)
72 if (File
->Type
!= FileType
) {
77 // Loop through the FFS file sections within the FFS file
79 if (IS_FFS_FILE2 (File
)) {
80 EndOfSection
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)((UINT8
*)File
+ sizeof (EFI_FFS_FILE_HEADER2
));
82 EndOfSection
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)((UINT8
*)File
+ sizeof (EFI_FFS_FILE_HEADER
));
86 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
87 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
)CurrentAddress
;
89 if (IS_SECTION2 (Section
)) {
90 Size
= SECTION2_SIZE (Section
);
91 if (Size
<= 0x00FFFFFF) {
95 Size
= SECTION_SIZE (Section
);
96 if (Size
< sizeof (EFI_COMMON_SECTION_HEADER
)) {
101 EndOfSection
= CurrentAddress
+ Size
;
102 if (EndOfSection
> EndOfFile
) {
103 return EFI_NOT_FOUND
;
107 // Look for executable sections
109 if ((Section
->Type
== EFI_SECTION_PE32
) || (Section
->Type
== EFI_SECTION_TE
)) {
110 if (File
->Type
== FileType
) {
111 if (IS_SECTION2 (Section
)) {
112 *CoreImageBase
= (PHYSICAL_ADDRESS
)(UINTN
)((UINT8
*)Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
114 *CoreImageBase
= (PHYSICAL_ADDRESS
)(UINTN
)((UINT8
*)Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
123 // Either SEC Core or PEI Core images found
125 if (*CoreImageBase
!= 0) {
132 Find and return Pei Core entry point.
134 It also find SEC and PEI Core file debug information. It will report them if
135 remote debug is enabled.
137 @param SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.
138 @param PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.
139 @param PeiCoreEntryPoint The entry point of the PEI core.
144 FindAndReportEntryPoints (
145 IN EFI_FIRMWARE_VOLUME_HEADER
*SecCoreFirmwareVolumePtr
,
146 IN EFI_FIRMWARE_VOLUME_HEADER
*PeiCoreFirmwareVolumePtr
,
147 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
151 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
152 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
153 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
156 // Find SEC Core image base
158 Status
= FindImageBase (SecCoreFirmwareVolumePtr
, EFI_FV_FILETYPE_SECURITY_CORE
, &SecCoreImageBase
);
159 ASSERT_EFI_ERROR (Status
);
161 ZeroMem ((VOID
*)&ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
163 // Report SEC Core debug information when remote debug is enabled
165 ImageContext
.ImageAddress
= SecCoreImageBase
;
166 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*)(UINTN
)ImageContext
.ImageAddress
);
167 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
170 // Find PEI Core image base
172 Status
= FindImageBase (PeiCoreFirmwareVolumePtr
, EFI_FV_FILETYPE_PEI_CORE
, &PeiCoreImageBase
);
173 ASSERT_EFI_ERROR (Status
);
176 // Report PEI Core debug information when remote debug is enabled
178 ImageContext
.ImageAddress
= PeiCoreImageBase
;
179 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*)(UINTN
)ImageContext
.ImageAddress
);
180 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
183 // Find PEI Core entry point
185 Status
= PeCoffLoaderGetEntryPoint ((VOID
*)(UINTN
)PeiCoreImageBase
, (VOID
**)PeiCoreEntryPoint
);
186 if (EFI_ERROR (Status
)) {
187 *PeiCoreEntryPoint
= 0;