1 ;------------------------------------------------------------------------------
3 ; Search for the SEC Core entry point
5 ; Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
6 ; SPDX-License-Identifier: BSD-2-Clause-Patent
8 ;------------------------------------------------------------------------------
12 %define EFI_FV_FILETYPE_SECURITY_CORE 0x03
15 ; Modified: EAX, EBX, ECX, EDX
16 ; Preserved: EDI, EBP, ESP
18 ; @param[in] EBP Address of Boot Firmware Volume (BFV)
19 ; @param[out] ESI SEC Core Entry Point Address
21 Flat32SearchForSecEntryPoint:
24 ; Initialize EBP and ESI to 0
30 ; Pass over the BFV header
35 jc secEntryPointWasNotFound
37 jmp searchingForFfsFileHeaderLoop
39 moveForwardWhileSearchingForFfsFileHeaderLoop:
41 ; Make forward progress in the search
44 jc secEntryPointWasNotFound
46 searchingForFfsFileHeaderLoop:
48 jz secEntryPointWasNotFound
51 ; Ensure 8 byte alignment
54 jc secEntryPointWasNotFound
58 ; Look to see if there is an FFS file at eax
62 jz moveForwardWhileSearchingForFfsFileHeaderLoop
66 jz moveForwardWhileSearchingForFfsFileHeaderLoop
68 jz jumpSinceWeFoundTheLastFfsFile
69 jc moveForwardWhileSearchingForFfsFileHeaderLoop
70 jumpSinceWeFoundTheLastFfsFile:
73 ; There seems to be a valid file at eax
75 cmp byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type
76 jne readyToTryFfsFileAtEcx
79 OneTimeCall GetEntryPointOfFfsFile
81 jnz doneSeachingForSecEntryPoint
83 readyToTryFfsFileAtEcx:
85 ; Try the next FFS file at ECX
88 jmp searchingForFfsFileHeaderLoop
90 secEntryPointWasNotFound:
93 doneSeachingForSecEntryPoint:
97 jnz secCoreEntryPointWasFound
99 secCoreEntryPointWasNotFound:
101 ; Hang if the SEC entry point was not found
103 debugShowPostCode POSTCODE_SEC_NOT_FOUND
106 secCoreEntryPointWasFound:
107 debugShowPostCode POSTCODE_SEC_FOUND
109 OneTimeCallRet Flat32SearchForSecEntryPoint
111 %define EFI_SECTION_PE32 0x10
112 %define EFI_SECTION_TE 0x12
116 ; EAX - Start of FFS file
117 ; ECX - End of FFS file
120 ; EAX - Entry point of PE32 (or 0 if not found)
125 GetEntryPointOfFfsFile:
127 jz getEntryPointOfFfsFileErrorReturn
128 add eax, 0x18 ; EAX = Start of section
130 getEntryPointOfFfsFileLoopForSections:
132 jae getEntryPointOfFfsFileErrorReturn
134 cmp byte [eax + 3], EFI_SECTION_PE32
135 je getEntryPointOfFfsFileFoundPe32Section
137 cmp byte [eax + 3], EFI_SECTION_TE
138 je getEntryPointOfFfsFileFoundTeSection
141 ; The section type was not PE32 or TE, so move to next section
146 jc getEntryPointOfFfsFileErrorReturn
149 ; Ensure that FFS section is 32-bit aligned
152 jc getEntryPointOfFfsFileErrorReturn
154 jmp getEntryPointOfFfsFileLoopForSections
156 getEntryPointOfFfsFileFoundPe32Section:
157 add eax, 4 ; EAX = Start of PE32 image
160 jne getEntryPointOfFfsFileErrorReturn
161 movzx ebx, word [eax + 0x3c]
164 ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)
165 cmp dword [ebx], `PE\x00\x00`
166 jne getEntryPointOfFfsFileErrorReturn
168 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
169 ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
170 add eax, [ebx + 0x4 + 0x14 + 0x10]
171 jmp getEntryPointOfFfsFileReturn
173 getEntryPointOfFfsFileFoundTeSection:
174 add eax, 4 ; EAX = Start of TE image
177 ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)
179 jne getEntryPointOfFfsFileErrorReturn
180 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
181 ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +
182 ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
185 movzx ebx, word [ebx + 0x6]
187 jmp getEntryPointOfFfsFileReturn
189 getEntryPointOfFfsFileErrorReturn:
192 getEntryPointOfFfsFileReturn:
193 OneTimeCallRet GetEntryPointOfFfsFile