]>
Commit | Line | Data |
---|---|---|
0913fadc | 1 | /** @file |
2 | Locate the entry point for the PEI Core | |
3 | ||
4 | Copyright (c) 2008 - 2009, Intel Corporation | |
5 | ||
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 | |
10 | ||
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. | |
13 | ||
14 | **/ | |
15 | ||
16 | #include <PiPei.h> | |
17 | #include <Library/BaseLib.h> | |
18 | #include <Library/PeCoffGetEntryPointLib.h> | |
19 | ||
20 | #include "SecMain.h" | |
21 | ||
22 | ||
23 | VOID | |
24 | EFIAPI | |
25 | FindPeiCoreEntryPoint ( | |
26 | IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr, | |
27 | OUT VOID **PeiCoreEntryPoint | |
28 | ) | |
29 | { | |
30 | EFI_STATUS Status; | |
31 | EFI_PHYSICAL_ADDRESS CurrentAddress; | |
32 | EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; | |
33 | EFI_FFS_FILE_HEADER *File; | |
34 | UINT32 Size; | |
35 | EFI_PHYSICAL_ADDRESS EndOfFile; | |
36 | EFI_COMMON_SECTION_HEADER *Section; | |
37 | EFI_PHYSICAL_ADDRESS EndOfSection; | |
38 | ||
39 | *PeiCoreEntryPoint = NULL; | |
40 | ||
41 | CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) BootFirmwareVolumePtr; | |
42 | EndOfFirmwareVolume = CurrentAddress + BootFirmwareVolumePtr->FvLength; | |
43 | ||
44 | // | |
45 | // Loop through the FFS files in the Boot Firmware Volume | |
46 | // | |
47 | for (EndOfFile = CurrentAddress + BootFirmwareVolumePtr->HeaderLength; ; ) { | |
48 | ||
49 | CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL; | |
50 | if (CurrentAddress > EndOfFirmwareVolume) { | |
51 | return; | |
52 | } | |
53 | ||
54 | File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress; | |
55 | Size = *(UINT32*) File->Size & 0xffffff; | |
56 | if (Size < (sizeof (*File) + sizeof (*Section))) { | |
57 | return; | |
58 | } | |
59 | ||
60 | EndOfFile = CurrentAddress + Size; | |
61 | if (EndOfFile > EndOfFirmwareVolume) { | |
62 | return; | |
63 | } | |
64 | ||
65 | // | |
66 | // Look for PEI Core files | |
67 | // | |
68 | if (File->Type != EFI_FV_FILETYPE_PEI_CORE) { | |
69 | continue; | |
70 | } | |
71 | ||
72 | // | |
73 | // Loop through the FFS file sections within the PEI Core FFS file | |
74 | // | |
75 | EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN) (File + 1); | |
76 | for (;;) { | |
77 | CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL; | |
78 | Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress; | |
79 | ||
80 | Size = *(UINT32*) Section->Size & 0xffffff; | |
81 | if (Size < sizeof (*Section)) { | |
82 | return; | |
83 | } | |
84 | ||
85 | EndOfSection = CurrentAddress + Size; | |
86 | if (EndOfSection > EndOfFile) { | |
87 | return; | |
88 | } | |
89 | ||
90 | // | |
91 | // Look for executable sections | |
92 | // | |
93 | if (Section->Type == EFI_SECTION_PE32) { | |
94 | Status = PeCoffLoaderGetEntryPoint ((VOID*) (Section + 1), PeiCoreEntryPoint); | |
95 | if (!EFI_ERROR (Status)) { | |
96 | return; | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | } | |
102 | } | |
103 |