2 Locate the entry point for the PEI Core
4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/PeCoffGetEntryPointLib.h>
18 @param BootFirmwareVolumePtr Point to the boot firmware volume.
19 @param SecCoreImageBase The base address of the SEC core image.
20 @param PeiCoreImageBase The base address of the PEI core image.
26 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
27 OUT EFI_PHYSICAL_ADDRESS
*SecCoreImageBase
,
28 OUT EFI_PHYSICAL_ADDRESS
*PeiCoreImageBase
31 EFI_PHYSICAL_ADDRESS CurrentAddress
;
32 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
33 EFI_FFS_FILE_HEADER
*File
;
35 EFI_PHYSICAL_ADDRESS EndOfFile
;
36 EFI_COMMON_SECTION_HEADER
*Section
;
37 EFI_PHYSICAL_ADDRESS EndOfSection
;
39 *SecCoreImageBase
= 0;
40 *PeiCoreImageBase
= 0;
42 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) BootFirmwareVolumePtr
;
43 EndOfFirmwareVolume
= CurrentAddress
+ BootFirmwareVolumePtr
->FvLength
;
46 // Loop through the FFS files in the Boot Firmware Volume
48 for (EndOfFile
= CurrentAddress
+ BootFirmwareVolumePtr
->HeaderLength
; ; ) {
50 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
51 if (CurrentAddress
> EndOfFirmwareVolume
) {
55 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
56 if (IS_FFS_FILE2 (File
)) {
57 Size
= FFS_FILE2_SIZE (File
);
58 if (Size
<= 0x00FFFFFF) {
62 Size
= FFS_FILE_SIZE (File
);
63 if (Size
< sizeof (EFI_FFS_FILE_HEADER
)) {
68 EndOfFile
= CurrentAddress
+ Size
;
69 if (EndOfFile
> EndOfFirmwareVolume
) {
74 // Look for SEC Core / PEI Core files
76 if (File
->Type
!= EFI_FV_FILETYPE_SECURITY_CORE
&&
77 File
->Type
!= EFI_FV_FILETYPE_PEI_CORE
) {
82 // Loop through the FFS file sections within the FFS file
84 if (IS_FFS_FILE2 (File
)) {
85 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER2
));
87 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER
));
90 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
91 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
93 if (IS_SECTION2 (Section
)) {
94 Size
= SECTION2_SIZE (Section
);
95 if (Size
<= 0x00FFFFFF) {
99 Size
= SECTION_SIZE (Section
);
100 if (Size
< sizeof (EFI_COMMON_SECTION_HEADER
)) {
101 return EFI_NOT_FOUND
;
105 EndOfSection
= CurrentAddress
+ Size
;
106 if (EndOfSection
> EndOfFile
) {
107 return EFI_NOT_FOUND
;
111 // Look for executable sections
113 if (Section
->Type
== EFI_SECTION_PE32
|| Section
->Type
== EFI_SECTION_TE
) {
114 if (File
->Type
== EFI_FV_FILETYPE_SECURITY_CORE
) {
115 if (IS_SECTION2 (Section
)) {
116 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
118 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
121 if (IS_SECTION2 (Section
)) {
122 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
124 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
132 // Both SEC Core and PEI Core images found
134 if (*SecCoreImageBase
!= 0 && *PeiCoreImageBase
!= 0) {
141 Find and return Pei Core entry point.
143 It also find SEC and PEI Core file debug information. It will report them if
144 remote debug is enabled.
146 @param BootFirmwareVolumePtr Point to the boot firmware volume.
147 @param PeiCoreEntryPoint The entry point of the PEI core.
152 FindAndReportEntryPoints (
153 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
154 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
158 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
159 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
160 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
163 // Find SEC Core and PEI Core image base
165 Status
= FindImageBase (BootFirmwareVolumePtr
, &SecCoreImageBase
, &PeiCoreImageBase
);
166 ASSERT_EFI_ERROR (Status
);
168 ZeroMem ((VOID
*) &ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
170 // Report SEC Core debug information when remote debug is enabled
172 ImageContext
.ImageAddress
= SecCoreImageBase
;
173 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
174 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
177 // Report PEI Core debug information when remote debug is enabled
179 ImageContext
.ImageAddress
= PeiCoreImageBase
;
180 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
181 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
184 // Find PEI Core entry point
186 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) (UINTN
) PeiCoreImageBase
, (VOID
**) PeiCoreEntryPoint
);
187 if (EFI_ERROR (Status
)) {
188 *PeiCoreEntryPoint
= 0;