]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
IntelFsp2Pkg: Add FSPx_ARCH2_UPD support for X64
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / Ia32 / FspApiEntryM.nasm
1 ;; @file
2 ; Provide FSP API entry points.
3 ;
4 ; Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>
5 ; SPDX-License-Identifier: BSD-2-Clause-Patent
6 ;;
7
8 SECTION .text
9
10 ;
11 ; Following are fixed PCDs
12 ;
13 extern ASM_PFX(PcdGet32(PcdTemporaryRamBase))
14 extern ASM_PFX(PcdGet32(PcdTemporaryRamSize))
15 extern ASM_PFX(PcdGet32(PcdFspTemporaryRamSize))
16 extern ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
17
18 struc FSPM_UPD_COMMON
19 ; FSP_UPD_HEADER {
20 .FspUpdHeader: resd 8
21 ; }
22 ; FSPM_ARCH_UPD {
23 .Revision: resb 1
24 .Reserved: resb 3
25 .NvsBufferPtr: resd 1
26 .StackBase: resd 1
27 .StackSize: resd 1
28 .BootLoaderTolumSize: resd 1
29 .BootMode: resd 1
30 .Reserved1: resb 8
31 ; }
32 .size:
33 endstruc
34
35 struc FSPM_UPD_COMMON_FSP24
36 ; FSP_UPD_HEADER {
37 .FspUpdHeader: resd 8
38 ; }
39 ; FSPM_ARCH2_UPD {
40 .Revision: resb 1
41 .Reserved: resb 3
42 .Length resd 1
43 .StackBase: resq 1
44 .StackSize: resq 1
45 .BootLoaderTolumSize: resd 1
46 .BootMode: resd 1
47 .FspEventHandler resq 1
48 .Reserved1: resb 24
49 ; }
50 .size:
51 endstruc
52
53 ;
54 ; Following functions will be provided in C
55 ;
56 extern ASM_PFX(SecStartup)
57 extern ASM_PFX(FspApiCommon)
58
59 ;
60 ; Following functions will be provided in PlatformSecLib
61 ;
62 extern ASM_PFX(AsmGetFspBaseAddress)
63 extern ASM_PFX(AsmGetFspInfoHeader)
64
65 API_PARAM1_OFFSET EQU 34h ; ApiParam1 [ sub esp,8 + pushad + pushfd + push eax + call]
66 FSP_HEADER_IMGBASE_OFFSET EQU 1Ch
67 FSP_HEADER_CFGREG_OFFSET EQU 24h
68
69 ;----------------------------------------------------------------------------
70 ; FspMemoryInit API
71 ;
72 ; This FSP API is called after TempRamInit and initializes the memory.
73 ;
74 ;----------------------------------------------------------------------------
75 global ASM_PFX(FspMemoryInitApi)
76 ASM_PFX(FspMemoryInitApi):
77 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
78 jmp ASM_PFX(FspApiCommon)
79
80 ;----------------------------------------------------------------------------
81 ; TempRamExitApi API
82 ;
83 ; This API tears down temporary RAM
84 ;
85 ;----------------------------------------------------------------------------
86 global ASM_PFX(TempRamExitApi)
87 ASM_PFX(TempRamExitApi):
88 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
89 jmp ASM_PFX(FspApiCommon)
90
91 ;----------------------------------------------------------------------------
92 ; FspApiCommonContinue API
93 ;
94 ; This is the FSP API common entry point to resume the FSP execution
95 ;
96 ;----------------------------------------------------------------------------
97 global ASM_PFX(FspApiCommonContinue)
98 ASM_PFX(FspApiCommonContinue):
99 ;
100 ; EAX holds the API index
101 ;
102
103 ;
104 ; FspMemoryInit API setup the initial stack frame
105 ;
106
107 ;
108 ; Place holder to store the FspInfoHeader pointer
109 ;
110 push eax
111
112 ;
113 ; Update the FspInfoHeader pointer
114 ;
115 push eax
116 call ASM_PFX(AsmGetFspInfoHeader)
117 mov [esp + 4], eax
118 pop eax
119
120 ;
121 ; Create a Task Frame in the stack for the Boot Loader
122 ;
123 pushfd ; 2 pushf for 4 byte alignment
124 cli
125 pushad
126
127 ; Reserve 8 bytes for IDT save/restore
128 sub esp, 8
129 sidt [esp]
130
131
132 ; Get Stackbase and StackSize from FSPM_UPD Param
133 mov edx, [esp + API_PARAM1_OFFSET]
134 cmp edx, 0
135 jnz FspStackSetup
136
137 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
138 push eax
139 call ASM_PFX(AsmGetFspInfoHeader)
140 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
141 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
142 pop eax
143
144 FspStackSetup:
145 mov ecx, [edx + FSPM_UPD_COMMON.Revision]
146 cmp ecx, 3
147 jae FspmUpdCommon2
148
149 ;
150 ; StackBase = temp memory base, StackSize = temp memory size
151 ;
152 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
153 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
154 jmp ChkFspHeapSize
155
156 FspmUpdCommon2:
157 mov edi, [edx + FSPM_UPD_COMMON_FSP24.StackBase]
158 mov ecx, [edx + FSPM_UPD_COMMON_FSP24.StackSize]
159
160 ChkFspHeapSize:
161 ;
162 ; Keep using bootloader stack if heap size % is 0
163 ;
164 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
165 cmp bl, 0
166 jz SkipStackSwitch
167
168 ;
169 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
170 ;
171 add edi, ecx
172 ;
173 ; Switch to new FSP stack
174 ;
175 xchg edi, esp ; Exchange edi and esp, edi will be assigned to the current esp pointer and esp will be Stack base + Stack size
176
177 SkipStackSwitch:
178 ;
179 ; If heap size % is 0:
180 ; EDI is FSPM_UPD_COMMON.StackBase and will hold ESP later (boot loader stack pointer)
181 ; ECX is FSPM_UPD_COMMON.StackSize
182 ; ESP is boot loader stack pointer (no stack switch)
183 ; BL is 0 to indicate no stack switch (EBX will hold FSPM_UPD_COMMON.StackBase later)
184 ;
185 ; If heap size % is not 0
186 ; EDI is boot loader stack pointer
187 ; ECX is FSPM_UPD_COMMON.StackSize
188 ; ESP is new stack (FSPM_UPD_COMMON.StackBase + FSPM_UPD_COMMON.StackSize)
189 ; BL is NOT 0 to indicate stack has switched
190 ;
191 cmp bl, 0
192 jnz StackHasBeenSwitched
193
194 mov ebx, edi ; Put FSPM_UPD_COMMON.StackBase to ebx as temp memory base
195 mov edi, esp ; Put boot loader stack pointer to edi
196 jmp StackSetupDone
197
198 StackHasBeenSwitched:
199 mov ebx, esp ; Put Stack base + Stack size in ebx
200 sub ebx, ecx ; Stack base + Stack size - Stack size as temp memory base
201
202 StackSetupDone:
203
204 ;
205 ; Pass the API Idx to SecStartup
206 ;
207 push eax
208
209 ;
210 ; Pass the BootLoader stack to SecStartup
211 ;
212 push edi
213
214 ;
215 ; Pass entry point of the PEI core
216 ;
217 call ASM_PFX(AsmGetFspBaseAddress)
218 mov edi, eax
219 call ASM_PFX(AsmGetPeiCoreOffset)
220 add edi, eax
221 push edi
222
223 ;
224 ; Pass BFV into the PEI Core
225 ; It uses relative address to calculate the actual boot FV base
226 ; For FSP implementation with single FV, PcdFspBootFirmwareVolumeBase and
227 ; PcdFspAreaBaseAddress are the same. For FSP with multiple FVs,
228 ; they are different. The code below can handle both cases.
229 ;
230 call ASM_PFX(AsmGetFspBaseAddress)
231 push eax
232
233 ;
234 ; Pass stack base and size into the PEI Core
235 ;
236 push ebx
237 push ecx
238
239 ;
240 ; Pass Control into the PEI Core
241 ;
242 call ASM_PFX(SecStartup)
243 add esp, 4
244 exit:
245 ret
246
247 global ASM_PFX(FspPeiCoreEntryOff)
248 ASM_PFX(FspPeiCoreEntryOff):
249 ;
250 ; This value will be patched by the build script
251 ;
252 DD 0x12345678
253
254 global ASM_PFX(AsmGetPeiCoreOffset)
255 ASM_PFX(AsmGetPeiCoreOffset):
256 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
257 ret
258
259 ;----------------------------------------------------------------------------
260 ; TempRamInit API
261 ;
262 ; Empty function for WHOLEARCHIVE build option
263 ;
264 ;----------------------------------------------------------------------------
265 global ASM_PFX(TempRamInitApi)
266 ASM_PFX(TempRamInitApi):
267 jmp $
268 ret
269
270 ;----------------------------------------------------------------------------
271 ; Module Entrypoint API
272 ;----------------------------------------------------------------------------
273 global ASM_PFX(_ModuleEntryPoint)
274 ASM_PFX(_ModuleEntryPoint):
275 jmp $