2 Locate the entry point for the PEI Core
4 Copyright (c) 2008 - 2009, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/PeCoffGetEntryPointLib.h>
25 FindPeiCoreEntryPoint (
26 IN EFI_FIRMWARE_VOLUME_HEADER
*BootFirmwareVolumePtr
,
27 OUT VOID
**PeiCoreEntryPoint
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 *PeiCoreEntryPoint
= NULL
;
41 CurrentAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) BootFirmwareVolumePtr
;
42 EndOfFirmwareVolume
= CurrentAddress
+ BootFirmwareVolumePtr
->FvLength
;
45 // Loop through the FFS files in the Boot Firmware Volume
47 for (EndOfFile
= CurrentAddress
+ BootFirmwareVolumePtr
->HeaderLength
; ; ) {
49 CurrentAddress
= (EndOfFile
+ 7) & 0xfffffffffffffff8ULL
;
50 if (CurrentAddress
> EndOfFirmwareVolume
) {
54 File
= (EFI_FFS_FILE_HEADER
*)(UINTN
) CurrentAddress
;
55 Size
= *(UINT32
*) File
->Size
& 0xffffff;
56 if (Size
< (sizeof (*File
) + sizeof (*Section
))) {
60 EndOfFile
= CurrentAddress
+ Size
;
61 if (EndOfFile
> EndOfFirmwareVolume
) {
66 // Look for PEI Core files
68 if (File
->Type
!= EFI_FV_FILETYPE_PEI_CORE
) {
73 // Loop through the FFS file sections within the PEI Core FFS file
75 EndOfSection
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) (File
+ 1);
77 CurrentAddress
= (EndOfSection
+ 3) & 0xfffffffffffffffcULL
;
78 Section
= (EFI_COMMON_SECTION_HEADER
*)(UINTN
) CurrentAddress
;
80 Size
= *(UINT32
*) Section
->Size
& 0xffffff;
81 if (Size
< sizeof (*Section
)) {
85 EndOfSection
= CurrentAddress
+ Size
;
86 if (EndOfSection
> EndOfFile
) {
91 // Look for executable sections
93 if (Section
->Type
== EFI_SECTION_PE32
) {
94 Status
= PeCoffLoaderGetEntryPoint ((VOID
*) (Section
+ 1), PeiCoreEntryPoint
);
95 if (!EFI_ERROR (Status
)) {