]>
Commit | Line | Data |
---|---|---|
bc252e8e EB |
1 | ;------------------------------------------------------------------------------\r |
2 | ; @file\r | |
3 | ; Search for the SEC Core entry point\r | |
4 | ;\r | |
f7bb9801 | 5 | ; Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r |
0acd8697 | 6 | ; SPDX-License-Identifier: BSD-2-Clause-Patent\r |
bc252e8e EB |
7 | ;\r |
8 | ;------------------------------------------------------------------------------\r | |
9 | \r | |
10 | BITS 32\r | |
11 | \r | |
12 | %define EFI_FV_FILETYPE_SECURITY_CORE 0x03\r | |
13 | \r | |
14 | ;\r | |
15 | ; Modified: EAX, EBX, ECX, EDX\r | |
16 | ; Preserved: EDI, EBP, ESP\r | |
17 | ;\r | |
18 | ; @param[in] EBP Address of Boot Firmware Volume (BFV)\r | |
19 | ; @param[out] ESI SEC Core Entry Point Address\r | |
20 | ;\r | |
21 | Flat32SearchForSecEntryPoint:\r | |
22 | \r | |
23 | ;\r | |
24 | ; Initialize EBP and ESI to 0\r | |
25 | ;\r | |
26 | xor ebx, ebx\r | |
27 | mov esi, ebx\r | |
28 | \r | |
29 | ;\r | |
30 | ; Pass over the BFV header\r | |
31 | ;\r | |
32 | mov eax, ebp\r | |
33 | mov bx, [ebp + 0x30]\r | |
34 | add eax, ebx\r | |
35 | jc secEntryPointWasNotFound\r | |
36 | \r | |
37 | jmp searchingForFfsFileHeaderLoop\r | |
38 | \r | |
39 | moveForwardWhileSearchingForFfsFileHeaderLoop:\r | |
40 | ;\r | |
41 | ; Make forward progress in the search\r | |
42 | ;\r | |
43 | inc eax\r | |
44 | jc secEntryPointWasNotFound\r | |
45 | \r | |
46 | searchingForFfsFileHeaderLoop:\r | |
47 | test eax, eax\r | |
48 | jz secEntryPointWasNotFound\r | |
49 | \r | |
50 | ;\r | |
51 | ; Ensure 8 byte alignment\r | |
52 | ;\r | |
53 | add eax, 7\r | |
54 | jc secEntryPointWasNotFound\r | |
55 | and al, 0xf8\r | |
56 | \r | |
57 | ;\r | |
58 | ; Look to see if there is an FFS file at eax\r | |
59 | ;\r | |
60 | mov bl, [eax + 0x17]\r | |
61 | test bl, 0x20\r | |
62 | jz moveForwardWhileSearchingForFfsFileHeaderLoop\r | |
63 | mov ecx, [eax + 0x14]\r | |
64 | and ecx, 0x00ffffff\r | |
65 | or ecx, ecx\r | |
66 | jz moveForwardWhileSearchingForFfsFileHeaderLoop\r | |
67 | add ecx, eax\r | |
68 | jz jumpSinceWeFoundTheLastFfsFile\r | |
69 | jc moveForwardWhileSearchingForFfsFileHeaderLoop\r | |
70 | jumpSinceWeFoundTheLastFfsFile:\r | |
71 | \r | |
72 | ;\r | |
73 | ; There seems to be a valid file at eax\r | |
74 | ;\r | |
75 | cmp byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type\r | |
76 | jne readyToTryFfsFileAtEcx\r | |
77 | \r | |
78 | fileTypeIsSecCore:\r | |
79 | OneTimeCall GetEntryPointOfFfsFile\r | |
80 | test eax, eax\r | |
81 | jnz doneSeachingForSecEntryPoint\r | |
82 | \r | |
83 | readyToTryFfsFileAtEcx:\r | |
84 | ;\r | |
85 | ; Try the next FFS file at ECX\r | |
86 | ;\r | |
87 | mov eax, ecx\r | |
88 | jmp searchingForFfsFileHeaderLoop\r | |
89 | \r | |
90 | secEntryPointWasNotFound:\r | |
91 | xor eax, eax\r | |
92 | \r | |
93 | doneSeachingForSecEntryPoint:\r | |
94 | mov esi, eax\r | |
95 | \r | |
96 | test esi, esi\r | |
97 | jnz secCoreEntryPointWasFound\r | |
98 | \r | |
99 | secCoreEntryPointWasNotFound:\r | |
100 | ;\r | |
101 | ; Hang if the SEC entry point was not found\r | |
102 | ;\r | |
103 | debugShowPostCode POSTCODE_SEC_NOT_FOUND\r | |
104 | jz $\r | |
105 | \r | |
106 | secCoreEntryPointWasFound:\r | |
107 | debugShowPostCode POSTCODE_SEC_FOUND\r | |
108 | \r | |
109 | OneTimeCallRet Flat32SearchForSecEntryPoint\r | |
110 | \r | |
111 | %define EFI_SECTION_PE32 0x10\r | |
f7bb9801 | 112 | %define EFI_SECTION_TE 0x12\r |
bc252e8e EB |
113 | \r |
114 | ;\r | |
115 | ; Input:\r | |
116 | ; EAX - Start of FFS file\r | |
117 | ; ECX - End of FFS file\r | |
118 | ;\r | |
119 | ; Output:\r | |
120 | ; EAX - Entry point of PE32 (or 0 if not found)\r | |
121 | ;\r | |
122 | ; Modified:\r | |
123 | ; EBX\r | |
124 | ;\r | |
125 | GetEntryPointOfFfsFile:\r | |
126 | test eax, eax\r | |
127 | jz getEntryPointOfFfsFileErrorReturn\r | |
128 | add eax, 0x18 ; EAX = Start of section\r | |
129 | \r | |
130 | getEntryPointOfFfsFileLoopForSections:\r | |
131 | cmp eax, ecx\r | |
132 | jae getEntryPointOfFfsFileErrorReturn\r | |
133 | \r | |
134 | cmp byte [eax + 3], EFI_SECTION_PE32\r | |
135 | je getEntryPointOfFfsFileFoundPe32Section\r | |
136 | \r | |
f7bb9801 | 137 | cmp byte [eax + 3], EFI_SECTION_TE\r |
138 | je getEntryPointOfFfsFileFoundTeSection\r | |
139 | \r | |
bc252e8e | 140 | ;\r |
f7bb9801 | 141 | ; The section type was not PE32 or TE, so move to next section\r |
bc252e8e EB |
142 | ;\r |
143 | mov ebx, dword [eax]\r | |
144 | and ebx, 0x00ffffff\r | |
145 | add eax, ebx\r | |
146 | jc getEntryPointOfFfsFileErrorReturn\r | |
147 | \r | |
148 | ;\r | |
149 | ; Ensure that FFS section is 32-bit aligned\r | |
150 | ;\r | |
151 | add eax, 3\r | |
152 | jc getEntryPointOfFfsFileErrorReturn\r | |
153 | and al, 0xfc\r | |
154 | jmp getEntryPointOfFfsFileLoopForSections\r | |
155 | \r | |
156 | getEntryPointOfFfsFileFoundPe32Section:\r | |
157 | add eax, 4 ; EAX = Start of PE32 image\r | |
158 | \r | |
bc252e8e | 159 | cmp word [eax], 'MZ'\r |
f7bb9801 | 160 | jne getEntryPointOfFfsFileErrorReturn\r |
bc252e8e EB |
161 | movzx ebx, word [eax + 0x3c]\r |
162 | add ebx, eax\r | |
f7bb9801 | 163 | \r |
164 | ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)\r | |
165 | cmp dword [ebx], `PE\x00\x00`\r | |
166 | jne getEntryPointOfFfsFileErrorReturn\r | |
167 | \r | |
168 | ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r | |
169 | ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r | |
170 | add eax, [ebx + 0x4 + 0x14 + 0x10]\r | |
171 | jmp getEntryPointOfFfsFileReturn\r | |
172 | \r | |
173 | getEntryPointOfFfsFileFoundTeSection:\r | |
174 | add eax, 4 ; EAX = Start of TE image\r | |
175 | mov ebx, eax\r | |
bc252e8e EB |
176 | \r |
177 | ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)\r | |
178 | cmp word [ebx], 'VZ'\r | |
f7bb9801 | 179 | jne getEntryPointOfFfsFileErrorReturn\r |
bc252e8e EB |
180 | ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r |
181 | ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +\r | |
182 | ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);\r | |
183 | add eax, [ebx + 0x8]\r | |
184 | add eax, 0x28\r | |
185 | movzx ebx, word [ebx + 0x6]\r | |
186 | sub eax, ebx\r | |
187 | jmp getEntryPointOfFfsFileReturn\r | |
188 | \r | |
bc252e8e EB |
189 | getEntryPointOfFfsFileErrorReturn:\r |
190 | mov eax, 0\r | |
191 | \r | |
192 | getEntryPointOfFfsFileReturn:\r | |
193 | OneTimeCallRet GetEntryPointOfFfsFile\r | |
194 | \r |