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.
16 #include <Library/BaseLib.h>
17 #include <Library/PeCoffGetEntryPointLib.h>
24 @param BootFirmwareVolumePtr Point to the boot firmware volume.
25 @param SecCoreImageBase The base address of the SEC core image.
26 @param PeiCoreImageBase The base address of the PEI core image.
32 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
33 OUT EFI_PHYSICAL_ADDRESS
*SecCoreImageBase
,
34 OUT EFI_PHYSICAL_ADDRESS
*PeiCoreImageBase
37 EFI_PHYSICAL_ADDRESS CurrentAddress
;
38 EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume
;
39 EFI_FFS_FILE_HEADER
*File
;
41 EFI_PHYSICAL_ADDRESS EndOfFile
;
42 EFI_COMMON_SECTION_HEADER
*Section
;
43 EFI_PHYSICAL_ADDRESS EndOfSection
;
45 *SecCoreImageBase
= 0;
46 *PeiCoreImageBase
= 0;
48 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) BootFirmwareVolumePtr
;
49 EndOfFirmwareVolume
= CurrentAddress
+ BootFirmwareVolumePtr
->FvLength
;
52 // Loop through the FFS files in the Boot Firmware Volume
54 for (EndOfFile
= CurrentAddress
+ BootFirmwareVolumePtr
->HeaderLength
; ; ) {
56 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
57 if (CurrentAddress
> EndOfFirmwareVolume
) {
61 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
62 if (IS_FFS_FILE2 (File
)) {
63 Size
= FFS_FILE2_SIZE (File
);
64 if (Size
<= 0x00FFFFFF) {
68 Size
= FFS_FILE_SIZE (File
);
69 if (Size
< sizeof (EFI_FFS_FILE_HEADER
)) {
74 EndOfFile
= CurrentAddress
+ Size
;
75 if (EndOfFile
> EndOfFirmwareVolume
) {
80 // Look for SEC Core / PEI Core files
82 if (File
->Type
!= EFI_FV_FILETYPE_SECURITY_CORE
&&
83 File
->Type
!= EFI_FV_FILETYPE_PEI_CORE
) {
88 // Loop through the FFS file sections within the FFS file
90 if (IS_FFS_FILE2 (File
)) {
91 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER2
));
93 EndOfSection
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) File
+ sizeof (EFI_FFS_FILE_HEADER
));
96 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
97 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
99 if (IS_SECTION2 (Section
)) {
100 Size
= SECTION2_SIZE (Section
);
101 if (Size
<= 0x00FFFFFF) {
102 return EFI_NOT_FOUND
;
105 Size
= SECTION_SIZE (Section
);
106 if (Size
< sizeof (EFI_COMMON_SECTION_HEADER
)) {
107 return EFI_NOT_FOUND
;
111 EndOfSection
= CurrentAddress
+ Size
;
112 if (EndOfSection
> EndOfFile
) {
113 return EFI_NOT_FOUND
;
117 // Look for executable sections
119 if (Section
->Type
== EFI_SECTION_PE32
|| Section
->Type
== EFI_SECTION_TE
) {
120 if (File
->Type
== EFI_FV_FILETYPE_SECURITY_CORE
) {
121 if (IS_SECTION2 (Section
)) {
122 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
124 *SecCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
127 if (IS_SECTION2 (Section
)) {
128 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER2
));
130 *PeiCoreImageBase
= (PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) Section
+ sizeof (EFI_COMMON_SECTION_HEADER
));
138 // Both SEC Core and PEI Core images found
140 if (*SecCoreImageBase
!= 0 && *PeiCoreImageBase
!= 0) {
147 Find and return Pei Core entry point.
149 It also find SEC and PEI Core file debug information. It will report them if
150 remote debug is enabled.
152 @param BootFirmwareVolumePtr Point to the boot firmware volume.
153 @param PeiCoreEntryPoint The entry point of the PEI core.
158 FindAndReportEntryPoints (
159 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
160 OUT EFI_PEI_CORE_ENTRY_POINT
*PeiCoreEntryPoint
164 EFI_PHYSICAL_ADDRESS SecCoreImageBase
;
165 EFI_PHYSICAL_ADDRESS PeiCoreImageBase
;
166 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
169 // Find SEC Core and PEI Core image base
171 Status
= FindImageBase (BootFirmwareVolumePtr
, &SecCoreImageBase
, &PeiCoreImageBase
);
172 ASSERT_EFI_ERROR (Status
);
174 ZeroMem ((VOID
*) &ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
176 // Report SEC Core debug information when remote debug is enabled
178 ImageContext
.ImageAddress
= SecCoreImageBase
;
179 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
180 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
183 // Report PEI Core debug information when remote debug is enabled
185 ImageContext
.ImageAddress
= PeiCoreImageBase
;
186 ImageContext
.PdbPointer
= PeCoffLoaderGetPdbPointer ((VOID
*) (UINTN
) ImageContext
.ImageAddress
);
187 PeCoffLoaderRelocateImageExtraAction (&ImageContext
);
190 // Find PEI Core entry point
192 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) (UINTN
) PeiCoreImageBase
, (VOID
**) PeiCoreEntryPoint
);
193 if (EFI_ERROR (Status
)) {
194 *PeiCoreEntryPoint
= 0;