]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/ResetVector/Vtf0/Ia32/SearchForSecEntry.asm
UefiCpuPkg VTF0: Fix support for finding SEC image of type TE.
[mirror_edk2.git] / UefiCpuPkg / ResetVector / Vtf0 / Ia32 / SearchForSecEntry.asm
CommitLineData
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
01a1c0fc 6; This program and the accompanying materials\r
bc252e8e
EB
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
16BITS 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
27Flat32SearchForSecEntryPoint:\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
45moveForwardWhileSearchingForFfsFileHeaderLoop:\r
46 ;\r
47 ; Make forward progress in the search\r
48 ;\r
49 inc eax\r
50 jc secEntryPointWasNotFound\r
51\r
52searchingForFfsFileHeaderLoop:\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
76jumpSinceWeFoundTheLastFfsFile:\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
84fileTypeIsSecCore:\r
85 OneTimeCall GetEntryPointOfFfsFile\r
86 test eax, eax\r
87 jnz doneSeachingForSecEntryPoint\r
88\r
89readyToTryFfsFileAtEcx:\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
96secEntryPointWasNotFound:\r
97 xor eax, eax\r
98\r
99doneSeachingForSecEntryPoint:\r
100 mov esi, eax\r
101\r
102 test esi, esi\r
103 jnz secCoreEntryPointWasFound\r
104\r
105secCoreEntryPointWasNotFound:\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
112secCoreEntryPointWasFound:\r
113 debugShowPostCode POSTCODE_SEC_FOUND\r
114\r
115 OneTimeCallRet Flat32SearchForSecEntryPoint\r
116\r
117%define EFI_SECTION_PE32 0x10\r
f7bb9801 118%define EFI_SECTION_TE 0x12\r
bc252e8e
EB
119\r
120;\r
121; Input:\r
122; EAX - Start of FFS file\r
123; ECX - End of FFS file\r
124;\r
125; Output:\r
126; EAX - Entry point of PE32 (or 0 if not found)\r
127;\r
128; Modified:\r
129; EBX\r
130;\r
131GetEntryPointOfFfsFile:\r
132 test eax, eax\r
133 jz getEntryPointOfFfsFileErrorReturn\r
134 add eax, 0x18 ; EAX = Start of section\r
135\r
136getEntryPointOfFfsFileLoopForSections:\r
137 cmp eax, ecx\r
138 jae getEntryPointOfFfsFileErrorReturn\r
139\r
140 cmp byte [eax + 3], EFI_SECTION_PE32\r
141 je getEntryPointOfFfsFileFoundPe32Section\r
142\r
f7bb9801 143 cmp byte [eax + 3], EFI_SECTION_TE\r
144 je getEntryPointOfFfsFileFoundTeSection\r
145\r
bc252e8e 146 ;\r
f7bb9801 147 ; The section type was not PE32 or TE, so move to next section\r
bc252e8e
EB
148 ;\r
149 mov ebx, dword [eax]\r
150 and ebx, 0x00ffffff\r
151 add eax, ebx\r
152 jc getEntryPointOfFfsFileErrorReturn\r
153\r
154 ;\r
155 ; Ensure that FFS section is 32-bit aligned\r
156 ;\r
157 add eax, 3\r
158 jc getEntryPointOfFfsFileErrorReturn\r
159 and al, 0xfc\r
160 jmp getEntryPointOfFfsFileLoopForSections\r
161\r
162getEntryPointOfFfsFileFoundPe32Section:\r
163 add eax, 4 ; EAX = Start of PE32 image\r
164\r
bc252e8e 165 cmp word [eax], 'MZ'\r
f7bb9801 166 jne getEntryPointOfFfsFileErrorReturn\r
bc252e8e
EB
167 movzx ebx, word [eax + 0x3c]\r
168 add ebx, eax\r
f7bb9801 169\r
170 ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)\r
171 cmp dword [ebx], `PE\x00\x00`\r
172 jne getEntryPointOfFfsFileErrorReturn\r
173\r
174 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r
175 ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
176 add eax, [ebx + 0x4 + 0x14 + 0x10]\r
177 jmp getEntryPointOfFfsFileReturn\r
178\r
179getEntryPointOfFfsFileFoundTeSection:\r
180 add eax, 4 ; EAX = Start of TE image\r
181 mov ebx, eax\r
bc252e8e
EB
182\r
183 ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)\r
184 cmp word [ebx], 'VZ'\r
f7bb9801 185 jne getEntryPointOfFfsFileErrorReturn\r
bc252e8e
EB
186 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +\r
187 ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +\r
188 ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);\r
189 add eax, [ebx + 0x8]\r
190 add eax, 0x28\r
191 movzx ebx, word [ebx + 0x6]\r
192 sub eax, ebx\r
193 jmp getEntryPointOfFfsFileReturn\r
194\r
bc252e8e
EB
195getEntryPointOfFfsFileErrorReturn:\r
196 mov eax, 0\r
197\r
198getEntryPointOfFfsFileReturn:\r
199 OneTimeCallRet GetEntryPointOfFfsFile\r
200\r