1 ;------------------------------------------------------------------------------
3 ; Search for the SEC Core entry point
5 ; Copyright (c) 2008 - 2009, Intel Corporation
6 ; All rights reserved. This program and the accompanying materials
7 ; are licensed and made available under the terms and conditions of the BSD License
8 ; which accompanies this distribution. The full text of the license may be found at
9 ; http://opensource.org/licenses/bsd-license.php
11 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 ;------------------------------------------------------------------------------
18 %define EFI_FV_FILETYPE_SECURITY_CORE 0x03
21 ; Modified: EAX, EBX, ECX, EDX
22 ; Preserved: EDI, EBP, ESP
24 ; @param[in] EBP Address of Boot Firmware Volume (BFV)
25 ; @param[out] ESI SEC Core Entry Point Address
27 Flat32SearchForSecEntryPoint:
30 ; Initialize EBP and ESI to 0
36 ; Pass over the BFV header
41 jc secEntryPointWasNotFound
43 jmp searchingForFfsFileHeaderLoop
45 moveForwardWhileSearchingForFfsFileHeaderLoop:
47 ; Make forward progress in the search
50 jc secEntryPointWasNotFound
52 searchingForFfsFileHeaderLoop:
54 jz secEntryPointWasNotFound
57 ; Ensure 8 byte alignment
60 jc secEntryPointWasNotFound
64 ; Look to see if there is an FFS file at eax
68 jz moveForwardWhileSearchingForFfsFileHeaderLoop
72 jz moveForwardWhileSearchingForFfsFileHeaderLoop
74 jz jumpSinceWeFoundTheLastFfsFile
75 jc moveForwardWhileSearchingForFfsFileHeaderLoop
76 jumpSinceWeFoundTheLastFfsFile:
79 ; There seems to be a valid file at eax
81 cmp byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type
82 jne readyToTryFfsFileAtEcx
85 OneTimeCall GetEntryPointOfFfsFile
87 jnz doneSeachingForSecEntryPoint
89 readyToTryFfsFileAtEcx:
91 ; Try the next FFS file at ECX
94 jmp searchingForFfsFileHeaderLoop
96 secEntryPointWasNotFound:
99 doneSeachingForSecEntryPoint:
103 jnz secCoreEntryPointWasFound
105 secCoreEntryPointWasNotFound:
107 ; Hang if the SEC entry point was not found
109 debugShowPostCode POSTCODE_SEC_NOT_FOUND
112 secCoreEntryPointWasFound:
113 debugShowPostCode POSTCODE_SEC_FOUND
115 OneTimeCallRet Flat32SearchForSecEntryPoint
117 %define EFI_SECTION_PE32 0x10
121 ; EAX - Start of FFS file
122 ; ECX - End of FFS file
125 ; EAX - Entry point of PE32 (or 0 if not found)
130 GetEntryPointOfFfsFile:
132 jz getEntryPointOfFfsFileErrorReturn
133 add eax, 0x18 ; EAX = Start of section
135 getEntryPointOfFfsFileLoopForSections:
137 jae getEntryPointOfFfsFileErrorReturn
139 cmp byte [eax + 3], EFI_SECTION_PE32
140 je getEntryPointOfFfsFileFoundPe32Section
143 ; The section type was not PE32, so move to next section
148 jc getEntryPointOfFfsFileErrorReturn
151 ; Ensure that FFS section is 32-bit aligned
154 jc getEntryPointOfFfsFileErrorReturn
156 jmp getEntryPointOfFfsFileLoopForSections
158 getEntryPointOfFfsFileFoundPe32Section:
159 add eax, 4 ; EAX = Start of PE32 image
163 jne thereIsNotAnMzSignature
164 movzx ebx, word [eax + 0x3c]
166 thereIsNotAnMzSignature:
168 ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)
170 jne thereIsNoVzSignature
171 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
172 ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +
173 ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
176 movzx ebx, word [ebx + 0x6]
178 jmp getEntryPointOfFfsFileReturn
180 thereIsNoVzSignature:
182 ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)
183 cmp dword [ebx], `PE\x00\x00`
184 jne getEntryPointOfFfsFileErrorReturn
186 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
187 ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
188 add eax, [ebx + 0x4 + 0x14 + 0x10]
189 jmp getEntryPointOfFfsFileReturn
191 getEntryPointOfFfsFileErrorReturn:
194 getEntryPointOfFfsFileReturn:
195 OneTimeCallRet GetEntryPointOfFfsFile