]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/ResetVector/Vtf0/Ia32/SearchForSecEntry.asm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / ResetVector / Vtf0 / Ia32 / SearchForSecEntry.asm
1 ;------------------------------------------------------------------------------
2 ; @file
3 ; Search for the SEC Core entry point
4 ;
5 ; Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
6 ; SPDX-License-Identifier: BSD-2-Clause-Patent
7 ;
8 ;------------------------------------------------------------------------------
9
10 BITS 32
11
12 %define EFI_FV_FILETYPE_SECURITY_CORE 0x03
13
14 ;
15 ; Modified: EAX, EBX, ECX, EDX
16 ; Preserved: EDI, EBP, ESP
17 ;
18 ; @param[in] EBP Address of Boot Firmware Volume (BFV)
19 ; @param[out] ESI SEC Core Entry Point Address
20 ;
21 Flat32SearchForSecEntryPoint:
22
23 ;
24 ; Initialize EBP and ESI to 0
25 ;
26 xor ebx, ebx
27 mov esi, ebx
28
29 ;
30 ; Pass over the BFV header
31 ;
32 mov eax, ebp
33 mov bx, [ebp + 0x30]
34 add eax, ebx
35 jc secEntryPointWasNotFound
36
37 jmp searchingForFfsFileHeaderLoop
38
39 moveForwardWhileSearchingForFfsFileHeaderLoop:
40 ;
41 ; Make forward progress in the search
42 ;
43 inc eax
44 jc secEntryPointWasNotFound
45
46 searchingForFfsFileHeaderLoop:
47 test eax, eax
48 jz secEntryPointWasNotFound
49
50 ;
51 ; Ensure 8 byte alignment
52 ;
53 add eax, 7
54 jc secEntryPointWasNotFound
55 and al, 0xf8
56
57 ;
58 ; Look to see if there is an FFS file at eax
59 ;
60 mov bl, [eax + 0x17]
61 test bl, 0x20
62 jz moveForwardWhileSearchingForFfsFileHeaderLoop
63 mov ecx, [eax + 0x14]
64 and ecx, 0x00ffffff
65 or ecx, ecx
66 jz moveForwardWhileSearchingForFfsFileHeaderLoop
67 add ecx, eax
68 jz jumpSinceWeFoundTheLastFfsFile
69 jc moveForwardWhileSearchingForFfsFileHeaderLoop
70 jumpSinceWeFoundTheLastFfsFile:
71
72 ;
73 ; There seems to be a valid file at eax
74 ;
75 cmp byte [eax + 0x12], EFI_FV_FILETYPE_SECURITY_CORE ; Check File Type
76 jne readyToTryFfsFileAtEcx
77
78 fileTypeIsSecCore:
79 OneTimeCall GetEntryPointOfFfsFile
80 test eax, eax
81 jnz doneSeachingForSecEntryPoint
82
83 readyToTryFfsFileAtEcx:
84 ;
85 ; Try the next FFS file at ECX
86 ;
87 mov eax, ecx
88 jmp searchingForFfsFileHeaderLoop
89
90 secEntryPointWasNotFound:
91 xor eax, eax
92
93 doneSeachingForSecEntryPoint:
94 mov esi, eax
95
96 test esi, esi
97 jnz secCoreEntryPointWasFound
98
99 secCoreEntryPointWasNotFound:
100 ;
101 ; Hang if the SEC entry point was not found
102 ;
103 debugShowPostCode POSTCODE_SEC_NOT_FOUND
104 jz $
105
106 secCoreEntryPointWasFound:
107 debugShowPostCode POSTCODE_SEC_FOUND
108
109 OneTimeCallRet Flat32SearchForSecEntryPoint
110
111 %define EFI_SECTION_PE32 0x10
112 %define EFI_SECTION_TE 0x12
113
114 ;
115 ; Input:
116 ; EAX - Start of FFS file
117 ; ECX - End of FFS file
118 ;
119 ; Output:
120 ; EAX - Entry point of PE32 (or 0 if not found)
121 ;
122 ; Modified:
123 ; EBX
124 ;
125 GetEntryPointOfFfsFile:
126 test eax, eax
127 jz getEntryPointOfFfsFileErrorReturn
128 add eax, 0x18 ; EAX = Start of section
129
130 getEntryPointOfFfsFileLoopForSections:
131 cmp eax, ecx
132 jae getEntryPointOfFfsFileErrorReturn
133
134 cmp byte [eax + 3], EFI_SECTION_PE32
135 je getEntryPointOfFfsFileFoundPe32Section
136
137 cmp byte [eax + 3], EFI_SECTION_TE
138 je getEntryPointOfFfsFileFoundTeSection
139
140 ;
141 ; The section type was not PE32 or TE, so move to next section
142 ;
143 mov ebx, dword [eax]
144 and ebx, 0x00ffffff
145 add eax, ebx
146 jc getEntryPointOfFfsFileErrorReturn
147
148 ;
149 ; Ensure that FFS section is 32-bit aligned
150 ;
151 add eax, 3
152 jc getEntryPointOfFfsFileErrorReturn
153 and al, 0xfc
154 jmp getEntryPointOfFfsFileLoopForSections
155
156 getEntryPointOfFfsFileFoundPe32Section:
157 add eax, 4 ; EAX = Start of PE32 image
158
159 cmp word [eax], 'MZ'
160 jne getEntryPointOfFfsFileErrorReturn
161 movzx ebx, word [eax + 0x3c]
162 add ebx, eax
163
164 ; if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)
165 cmp dword [ebx], `PE\x00\x00`
166 jne getEntryPointOfFfsFileErrorReturn
167
168 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
169 ; (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
170 add eax, [ebx + 0x4 + 0x14 + 0x10]
171 jmp getEntryPointOfFfsFileReturn
172
173 getEntryPointOfFfsFileFoundTeSection:
174 add eax, 4 ; EAX = Start of TE image
175 mov ebx, eax
176
177 ; if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE)
178 cmp word [ebx], 'VZ'
179 jne getEntryPointOfFfsFileErrorReturn
180 ; *EntryPoint = (VOID *)((UINTN)Pe32Data +
181 ; (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) +
182 ; sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
183 add eax, [ebx + 0x8]
184 add eax, 0x28
185 movzx ebx, word [ebx + 0x6]
186 sub eax, ebx
187 jmp getEntryPointOfFfsFileReturn
188
189 getEntryPointOfFfsFileErrorReturn:
190 mov eax, 0
191
192 getEntryPointOfFfsFileReturn:
193 OneTimeCallRet GetEntryPointOfFfsFile
194