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