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