]>
Commit | Line | Data |
---|---|---|
1921695e MK |
1 | /** @file\r |
2 | Locate the entry point for the PEI Core\r | |
3 | \r | |
08283b96 | 4 | Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>\r |
0acd8697 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
1921695e MK |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
1921695e MK |
10 | \r |
11 | #include "SecMain.h"\r | |
12 | \r | |
13 | /**\r | |
14 | Find core image base.\r | |
15 | \r | |
08283b96 CC |
16 | @param FirmwareVolumePtr Point to the firmware volume for finding core image.\r |
17 | @param FileType The FileType for searching, either SecCore or PeiCore.\r | |
18 | @param CoreImageBase The base address of the core image.\r | |
1921695e MK |
19 | \r |
20 | **/\r | |
21 | EFI_STATUS\r | |
22 | EFIAPI\r | |
23 | FindImageBase (\r | |
053e878b MK |
24 | IN EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumePtr,\r |
25 | IN EFI_FV_FILETYPE FileType,\r | |
26 | OUT EFI_PHYSICAL_ADDRESS *CoreImageBase\r | |
1921695e MK |
27 | )\r |
28 | {\r | |
053e878b MK |
29 | EFI_PHYSICAL_ADDRESS CurrentAddress;\r |
30 | EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;\r | |
31 | EFI_FFS_FILE_HEADER *File;\r | |
32 | UINT32 Size;\r | |
33 | EFI_PHYSICAL_ADDRESS EndOfFile;\r | |
34 | EFI_COMMON_SECTION_HEADER *Section;\r | |
35 | EFI_PHYSICAL_ADDRESS EndOfSection;\r | |
1921695e | 36 | \r |
08283b96 | 37 | *CoreImageBase = 0;\r |
1921695e | 38 | \r |
053e878b | 39 | CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumePtr;\r |
08283b96 | 40 | EndOfFirmwareVolume = CurrentAddress + FirmwareVolumePtr->FvLength;\r |
1921695e MK |
41 | \r |
42 | //\r | |
43 | // Loop through the FFS files in the Boot Firmware Volume\r | |
44 | //\r | |
08283b96 | 45 | for (EndOfFile = CurrentAddress + FirmwareVolumePtr->HeaderLength; ; ) {\r |
1921695e MK |
46 | CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;\r |
47 | if (CurrentAddress > EndOfFirmwareVolume) {\r | |
48 | return EFI_NOT_FOUND;\r | |
49 | }\r | |
50 | \r | |
053e878b | 51 | File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress;\r |
1921695e MK |
52 | if (IS_FFS_FILE2 (File)) {\r |
53 | Size = FFS_FILE2_SIZE (File);\r | |
54 | if (Size <= 0x00FFFFFF) {\r | |
55 | return EFI_NOT_FOUND;\r | |
56 | }\r | |
57 | } else {\r | |
58 | Size = FFS_FILE_SIZE (File);\r | |
59 | if (Size < sizeof (EFI_FFS_FILE_HEADER)) {\r | |
60 | return EFI_NOT_FOUND;\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | EndOfFile = CurrentAddress + Size;\r | |
65 | if (EndOfFile > EndOfFirmwareVolume) {\r | |
66 | return EFI_NOT_FOUND;\r | |
67 | }\r | |
68 | \r | |
69 | //\r | |
08283b96 | 70 | // Look for particular Core file (either SEC Core or PEI Core)\r |
1921695e | 71 | //\r |
08283b96 | 72 | if (File->Type != FileType) {\r |
1921695e MK |
73 | continue;\r |
74 | }\r | |
75 | \r | |
76 | //\r | |
77 | // Loop through the FFS file sections within the FFS file\r | |
78 | //\r | |
79 | if (IS_FFS_FILE2 (File)) {\r | |
053e878b | 80 | EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER2));\r |
1921695e | 81 | } else {\r |
053e878b | 82 | EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)File + sizeof (EFI_FFS_FILE_HEADER));\r |
1921695e | 83 | }\r |
053e878b MK |
84 | \r |
85 | for ( ; ;) {\r | |
1921695e | 86 | CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;\r |
053e878b | 87 | Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress;\r |
1921695e MK |
88 | \r |
89 | if (IS_SECTION2 (Section)) {\r | |
90 | Size = SECTION2_SIZE (Section);\r | |
91 | if (Size <= 0x00FFFFFF) {\r | |
92 | return EFI_NOT_FOUND;\r | |
93 | }\r | |
94 | } else {\r | |
95 | Size = SECTION_SIZE (Section);\r | |
96 | if (Size < sizeof (EFI_COMMON_SECTION_HEADER)) {\r | |
97 | return EFI_NOT_FOUND;\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
101 | EndOfSection = CurrentAddress + Size;\r | |
102 | if (EndOfSection > EndOfFile) {\r | |
103 | return EFI_NOT_FOUND;\r | |
104 | }\r | |
105 | \r | |
106 | //\r | |
107 | // Look for executable sections\r | |
108 | //\r | |
053e878b | 109 | if ((Section->Type == EFI_SECTION_PE32) || (Section->Type == EFI_SECTION_TE)) {\r |
08283b96 | 110 | if (File->Type == FileType) {\r |
1921695e | 111 | if (IS_SECTION2 (Section)) {\r |
053e878b | 112 | *CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r |
1921695e | 113 | } else {\r |
053e878b | 114 | *CoreImageBase = (PHYSICAL_ADDRESS)(UINTN)((UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER));\r |
1921695e MK |
115 | }\r |
116 | }\r | |
053e878b | 117 | \r |
1921695e MK |
118 | break;\r |
119 | }\r | |
120 | }\r | |
121 | \r | |
122 | //\r | |
08283b96 | 123 | // Either SEC Core or PEI Core images found\r |
1921695e | 124 | //\r |
08283b96 | 125 | if (*CoreImageBase != 0) {\r |
1921695e MK |
126 | return EFI_SUCCESS;\r |
127 | }\r | |
128 | }\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | Find and return Pei Core entry point.\r | |
133 | \r | |
134 | It also find SEC and PEI Core file debug information. It will report them if\r | |
135 | remote debug is enabled.\r | |
136 | \r | |
08283b96 CC |
137 | @param SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.\r |
138 | @param PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.\r | |
1921695e MK |
139 | @param PeiCoreEntryPoint The entry point of the PEI core.\r |
140 | \r | |
141 | **/\r | |
142 | VOID\r | |
143 | EFIAPI\r | |
144 | FindAndReportEntryPoints (\r | |
053e878b MK |
145 | IN EFI_FIRMWARE_VOLUME_HEADER *SecCoreFirmwareVolumePtr,\r |
146 | IN EFI_FIRMWARE_VOLUME_HEADER *PeiCoreFirmwareVolumePtr,\r | |
147 | OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint\r | |
1921695e MK |
148 | )\r |
149 | {\r | |
053e878b MK |
150 | EFI_STATUS Status;\r |
151 | EFI_PHYSICAL_ADDRESS SecCoreImageBase;\r | |
152 | EFI_PHYSICAL_ADDRESS PeiCoreImageBase;\r | |
153 | PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r | |
1921695e MK |
154 | \r |
155 | //\r | |
08283b96 | 156 | // Find SEC Core image base\r |
1921695e | 157 | //\r |
08283b96 | 158 | Status = FindImageBase (SecCoreFirmwareVolumePtr, EFI_FV_FILETYPE_SECURITY_CORE, &SecCoreImageBase);\r |
1921695e MK |
159 | ASSERT_EFI_ERROR (Status);\r |
160 | \r | |
053e878b | 161 | ZeroMem ((VOID *)&ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));\r |
1921695e MK |
162 | //\r |
163 | // Report SEC Core debug information when remote debug is enabled\r | |
164 | //\r | |
165 | ImageContext.ImageAddress = SecCoreImageBase;\r | |
053e878b | 166 | ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);\r |
1921695e MK |
167 | PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r |
168 | \r | |
08283b96 CC |
169 | //\r |
170 | // Find PEI Core image base\r | |
171 | //\r | |
172 | Status = FindImageBase (PeiCoreFirmwareVolumePtr, EFI_FV_FILETYPE_PEI_CORE, &PeiCoreImageBase);\r | |
173 | ASSERT_EFI_ERROR (Status);\r | |
174 | \r | |
1921695e MK |
175 | //\r |
176 | // Report PEI Core debug information when remote debug is enabled\r | |
177 | //\r | |
178 | ImageContext.ImageAddress = PeiCoreImageBase;\r | |
053e878b | 179 | ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);\r |
1921695e MK |
180 | PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r |
181 | \r | |
182 | //\r | |
183 | // Find PEI Core entry point\r | |
184 | //\r | |
053e878b | 185 | Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, (VOID **)PeiCoreEntryPoint);\r |
1921695e MK |
186 | if (EFI_ERROR (Status)) {\r |
187 | *PeiCoreEntryPoint = 0;\r | |
188 | }\r | |
189 | \r | |
190 | return;\r | |
191 | }\r |