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