]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/ResetVector/Ia32/SearchForSecEntry.asm
OVMF: Define MDEPKG_NDEBUG to disable all debug code by default
[mirror_edk2.git] / OvmfPkg / ResetVector / Ia32 / SearchForSecEntry.asm
CommitLineData
49ba9447 1;------------------------------------------------------------------------------\r
7a55c43b 2; @file\r
3; Search for the SEC Core entry point\r
49ba9447 4;\r
7a55c43b 5; Copyright (c) 2008 - 2009, Intel Corporation\r
49ba9447 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
49ba9447 14;------------------------------------------------------------------------------\r
15\r
16BITS 32\r
17\r
18%define EFI_FV_FILETYPE_SECURITY_CORE 0x03\r
49ba9447 19\r
20;\r
7a55c43b 21; Modified: EAX, EBX, ECX, EDX\r
22; Preserved: EDI, EBP, ESP\r
49ba9447 23;\r
7a55c43b 24; @param[in] EBP Address of Boot Firmware Volume (BFV)\r
25; @param[out] ESI SEC Core Entry Point Address\r
49ba9447 26;\r
7a55c43b 27Flat32SearchForSecEntryPoint:\r
49ba9447 28\r
29 ;\r
30 ; Initialize EBP and ESI to 0\r
31 ;\r
32 xor ebx, ebx\r
33 mov esi, ebx\r
49ba9447 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
7a55c43b 41 jc secEntryPointWasNotFound\r
49ba9447 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
7a55c43b 50 jc secEntryPointWasNotFound\r
49ba9447 51\r
52searchingForFfsFileHeaderLoop:\r
53 test eax, eax\r
7a55c43b 54 jz secEntryPointWasNotFound\r
49ba9447 55\r
56 ;\r
57 ; Ensure 8 byte alignment\r
58 ;\r
59 add eax, 7\r
7a55c43b 60 jc secEntryPointWasNotFound\r
49ba9447 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
49ba9447 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
7a55c43b 81 cmp byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type\r
49ba9447 82 jne readyToTryFfsFileAtEcx\r
83\r
84fileTypeIsSecCore:\r
7a55c43b 85 OneTimeCall GetEntryPointOfFfsFile\r
49ba9447 86 test eax, eax\r
7a55c43b 87 jnz doneSeachingForSecEntryPoint\r
49ba9447 88\r
89readyToTryFfsFileAtEcx:\r
7a55c43b 90 ;\r
91 ; Try the next FFS file at ECX\r
92 ;\r
49ba9447 93 mov eax, ecx\r
94 jmp searchingForFfsFileHeaderLoop\r
95\r
7a55c43b 96secEntryPointWasNotFound:\r
97 xor eax, eax\r
98\r
99doneSeachingForSecEntryPoint:\r
100 mov esi, eax\r
49ba9447 101\r
102 test esi, esi\r
103 jnz secCoreEntryPointWasFound\r
49ba9447 104\r
7a55c43b 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
49ba9447 111\r
7a55c43b 112secCoreEntryPointWasFound:\r
113 debugShowPostCode POSTCODE_SEC_FOUND\r
49ba9447 114\r
7a55c43b 115 OneTimeCallRet Flat32SearchForSecEntryPoint\r
49ba9447 116\r
117%define EFI_SECTION_PE32 0x10\r
118\r
119;\r
120; Input:\r
121; EAX - Start of FFS file\r
9337cf8c 122; ECX - End of FFS file\r
49ba9447 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
7a55c43b 130GetEntryPointOfFfsFile:\r
49ba9447 131 test eax, eax\r
132 jz getEntryPointOfFfsFileErrorReturn\r
9337cf8c 133 add eax, 0x18 ; EAX = Start of section\r
49ba9447 134\r
9337cf8c 135getEntryPointOfFfsFileLoopForSections:\r
136 cmp eax, ecx\r
137 jae getEntryPointOfFfsFileErrorReturn\r
49ba9447 138\r
9337cf8c 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
158getEntryPointOfFfsFileFoundPe32Section:\r
159 add eax, 4 ; EAX = Start of PE32 image\r
49ba9447 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
166thereIsNotAnMzSignature:\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
180thereIsNoVzSignature:\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
191getEntryPointOfFfsFileErrorReturn:\r
192 mov eax, 0\r
193\r
194getEntryPointOfFfsFileReturn:\r
7a55c43b 195 OneTimeCallRet GetEntryPointOfFfsFile\r
49ba9447 196\r