1 ;------------------------------------------------------------------------------
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
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.
14 ; SearchForSecAndPeiEntry.asm
18 ; Search for the SEC Core and PEI Core entry points
20 ;------------------------------------------------------------------------------
24 %define EFI_FV_FILETYPE_SECURITY_CORE 0x03
25 %define EFI_FV_FILETYPE_PEI_CORE 0x04
29 ; EBP - BFV Base Address
32 ; ESI - SEC Core Entry Point Address (or 0 if not found)
33 ; EDI - PEI Core Entry Point Address (or 0 if not found)
38 Flat32SearchForSecAndPeiEntries:
41 ; Initialize EBP and ESI to 0
48 ; Pass over the BFV header
53 jc doneSeachingForSecAndPeiEntries
55 jmp searchingForFfsFileHeaderLoop
57 moveForwardWhileSearchingForFfsFileHeaderLoop:
59 ; Make forward progress in the search
62 jc doneSeachingForSecAndPeiEntries
64 searchingForFfsFileHeaderLoop:
66 jz doneSeachingForSecAndPeiEntries
69 ; Ensure 8 byte alignment
72 jc doneSeachingForSecAndPeiEntries
76 ; Look to see if there is an FFS file at eax
80 jz moveForwardWhileSearchingForFfsFileHeaderLoop
84 jz moveForwardWhileSearchingForFfsFileHeaderLoop
87 jz jumpSinceWeFoundTheLastFfsFile
88 jc moveForwardWhileSearchingForFfsFileHeaderLoop
89 jumpSinceWeFoundTheLastFfsFile:
92 ; There seems to be a valid file at eax
94 mov bl, [eax + 0x12] ; BL - File Type
95 cmp bl, EFI_FV_FILETYPE_PEI_CORE
97 cmp bl, EFI_FV_FILETYPE_SECURITY_CORE
98 jne readyToTryFfsFileAtEcx
101 callEdx GetEntryPointOfFfsFileReturnEdx
103 jz readyToTryFfsFileAtEcx
106 jmp readyToTryFfsFileAtEcx
109 callEdx GetEntryPointOfFfsFileReturnEdx
111 jz readyToTryFfsFileAtEcx
115 readyToTryFfsFileAtEcx:
117 jmp searchingForFfsFileHeaderLoop
119 doneSeachingForSecAndPeiEntries:
122 jnz secCoreEntryPointWasFound
123 writeToSerialPort '!'
124 secCoreEntryPointWasFound:
125 writeToSerialPort 'S'
126 writeToSerialPort 'E'
127 writeToSerialPort 'C'
128 writeToSerialPort ' '
131 jnz peiCoreEntryPointWasFound
132 writeToSerialPort '!'
133 peiCoreEntryPointWasFound:
134 writeToSerialPort 'P'
135 writeToSerialPort 'E'
136 writeToSerialPort 'I'
137 writeToSerialPort ' '
139 OneTimeCallRet Flat32SearchForSecAndPeiEntries
142 %define EFI_SECTION_PE32 0x10
146 ; EAX - Start of FFS file
147 ; ECX - End of FFS file
150 ; EAX - Entry point of PE32 (or 0 if not found)
155 GetEntryPointOfFfsFileReturnEdx:
157 jz getEntryPointOfFfsFileErrorReturn
158 add eax, 0x18 ; EAX = Start of section
160 getEntryPointOfFfsFileLoopForSections:
162 jae getEntryPointOfFfsFileErrorReturn
164 cmp byte [eax + 3], EFI_SECTION_PE32
165 je getEntryPointOfFfsFileFoundPe32Section
168 ; The section type was not PE32, so move to next section
173 jc getEntryPointOfFfsFileErrorReturn
176 ; Ensure that FFS section is 32-bit aligned
179 jc getEntryPointOfFfsFileErrorReturn
181 jmp getEntryPointOfFfsFileLoopForSections
183 getEntryPointOfFfsFileFoundPe32Section:
184 add eax, 4 ; EAX = Start of PE32 image
188 jne thereIsNotAnMzSignature
189 movzx ebx, word [eax + 0x3c]
191 thereIsNotAnMzSignature:
193 ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)
195 jne thereIsNoVzSignature
196 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
197 ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +
198 ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
201 movzx ebx, word [ebx + 0x6]
203 jmp getEntryPointOfFfsFileReturn
205 thereIsNoVzSignature:
207 ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)
208 cmp dword [ebx], `PE\x00\x00`
209 jne getEntryPointOfFfsFileErrorReturn
211 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
212 ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
213 add eax, [ebx + 0x4 + 0x14 + 0x10]
214 jmp getEntryPointOfFfsFileReturn
216 getEntryPointOfFfsFileErrorReturn:
219 getEntryPointOfFfsFileReturn: