2 Locate the entry point for the PEI Core
4 Copyright (c) 2008 - 2011, 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 BootFirmwareVolumePtr Point to the boot firmware volume.
23 @param SecCoreImageBase The base address of the SEC core image.
24 @param PeiCoreImageBase The base address of the PEI core image.
30 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
31 OUT EFI_PHYSICAL_ADDRESS
*SecCoreImageBase
,
32 OUT EFI_PHYSICAL_ADDRESS
*PeiCoreImageBase
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
;
43 *SecCoreImageBase
= 0;
44 *PeiCoreImageBase
= 0;
46 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) BootFirmwareVolumePtr
;
47 EndOfFirmwareVolume
= CurrentAddress
+ BootFirmwareVolumePtr
->FvLength
;
50 // Loop through the FFS files in the Boot Firmware Volume
52 for (EndOfFile
= CurrentAddress
+ BootFirmwareVolumePtr
->HeaderLength
; ; ) {
54 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
55 if (CurrentAddress
> EndOfFirmwareVolume
) {
59 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
60 if (IS_FFS_FILE2 (File
)) {
61 Size
= FFS_FILE2_SIZE (File
);
62 if (Size
<= 0x00FFFFFF) {
66 Size
= FFS_FILE_SIZE (File
);
67 if (Size
< sizeof (EFI_FFS_FILE_HEADER
)) {
72 EndOfFile
= CurrentAddress
+ Size
;
73 if (EndOfFile
> EndOfFirmwareVolume
) {
78 // Look for SEC Core / PEI Core files
80 if (File
->Type
!= EFI_FV_FILETYPE_SECURITY_CORE
&&
81 File
->Type
!= EFI_FV_FILETYPE_PEI_CORE
) {
86 // Loop through the FFS file sections within the FFS file
88 if (IS_FFS_FILE2 (File
)) {
89 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER2
));
91 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER
));
94 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
95 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
97 if (IS_SECTION2 (Section
)) {
98 Size
= SECTION2_SIZE (Section
);
99 if (Size
<= 0x00FFFFFF) {
100 return EFI_NOT_FOUND
;
103 Size
= SECTION_SIZE (Section
);
104 if (Size
< sizeof (EFI_COMMON_SECTION_HEADER
)) {
105 return EFI_NOT_FOUND
;
109 EndOfSection
= CurrentAddress
+ Size
;
110 if (EndOfSection
> EndOfFile
) {
111 return EFI_NOT_FOUND
;
115 // Look for executable sections
117 if (Section
->Type
== EFI_SECTION_PE32
|| Section
->Type
== EFI_SECTION_TE
) {
118 if (File
->Type
== EFI_FV_FILETYPE_SECURITY_CORE
) {
119 if (IS_SECTION2 (Section
)) {
120 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
122 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
125 if (IS_SECTION2 (Section
)) {
126 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
128 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
136 // Both SEC Core and PEI Core images found
138 if (*SecCoreImageBase
!= 0 && *PeiCoreImageBase
!= 0) {
145 Find and return Pei Core entry point.
147 It also find SEC and PEI Core file debug information. It will report them if
148 remote debug is enabled.
150 @param BootFirmwareVolumePtr Point to the boot firmware volume.
151 @param PeiCoreEntryPoint The entry point of the PEI core.
156 FindAndReportEntryPoints (
157 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
158 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
162 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
163 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
164 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
167 // Find SEC Core and PEI Core image base
169 Status
= FindImageBase (BootFirmwareVolumePtr
, &SecCoreImageBase
, &PeiCoreImageBase
);
170 ASSERT_EFI_ERROR (Status
);
172 ZeroMem ((VOID
*) &ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
174 // Report SEC Core debug information when remote debug is enabled
176 ImageContext
.ImageAddress
= SecCoreImageBase
;
177 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
178 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
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;