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