2 ; Provide FSP API entry points.
4 ; Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>
5 ; SPDX-License-Identifier: BSD-2-Clause-Patent
11 ; Following are fixed PCDs
13 extern ASM_PFX(PcdGet32(PcdTemporaryRamBase))
14 extern ASM_PFX(PcdGet32(PcdTemporaryRamSize))
15 extern ASM_PFX(PcdGet32(PcdFspTemporaryRamSize))
16 extern ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
28 .BootLoaderTolumSize: resd 1
35 struc FSPM_UPD_COMMON_FSP24
46 .BootLoaderTolumSize: resd 1
48 .FspEventHandler resq 1
55 ; Following functions will be provided in C
57 extern ASM_PFX(SecStartup)
58 extern ASM_PFX(FspApiCommon)
61 ; Following functions will be provided in PlatformSecLib
63 extern ASM_PFX(AsmGetFspBaseAddress)
64 extern ASM_PFX(AsmGetFspInfoHeader)
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
70 ;----------------------------------------------------------------------------
73 ; This FSP API is called after TempRamInit and initializes the memory.
75 ;----------------------------------------------------------------------------
76 global ASM_PFX(FspMemoryInitApi)
77 ASM_PFX(FspMemoryInitApi):
78 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
79 jmp ASM_PFX(FspApiCommon)
81 ;----------------------------------------------------------------------------
84 ; This API tears down temporary RAM
86 ;----------------------------------------------------------------------------
87 global ASM_PFX(TempRamExitApi)
88 ASM_PFX(TempRamExitApi):
89 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
90 jmp ASM_PFX(FspApiCommon)
92 ;----------------------------------------------------------------------------
93 ; FspApiCommonContinue API
95 ; This is the FSP API common entry point to resume the FSP execution
97 ;----------------------------------------------------------------------------
98 global ASM_PFX(FspApiCommonContinue)
99 ASM_PFX(FspApiCommonContinue):
101 ; EAX holds the API index
105 ; FspMemoryInit API setup the initial stack frame
109 ; Place holder to store the FspInfoHeader pointer
114 ; Update the FspInfoHeader pointer
117 call ASM_PFX(AsmGetFspInfoHeader)
122 ; Create a Task Frame in the stack for the Boot Loader
124 pushfd ; 2 pushf for 4 byte alignment
128 ; Reserve 8 bytes for IDT save/restore
133 ; Get Stackbase and StackSize from FSPM_UPD Param
134 mov edx, [esp + API_PARAM1_OFFSET]
138 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
140 call ASM_PFX(AsmGetFspInfoHeader)
141 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
142 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
146 mov ecx, [edx + FSPM_UPD_COMMON.Revision]
151 ; StackBase = temp memory base, StackSize = temp memory size
153 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
154 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
158 mov edi, [edx + FSPM_UPD_COMMON_FSP24.StackBase]
159 mov ecx, [edx + FSPM_UPD_COMMON_FSP24.StackSize]
163 ; Keep using bootloader stack if heap size % is 0
165 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
170 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
174 ; Switch to new FSP stack
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
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)
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
193 jnz StackHasBeenSwitched
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
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
206 ; Pass the API Idx to SecStartup
211 ; Pass the BootLoader stack to SecStartup
216 ; Pass entry point of the PEI core
218 call ASM_PFX(AsmGetFspBaseAddress)
220 call ASM_PFX(AsmGetPeiCoreOffset)
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.
231 call ASM_PFX(AsmGetFspBaseAddress)
235 ; Pass stack base and size into the PEI Core
241 ; Pass Control into the PEI Core
243 call ASM_PFX(SecStartup)
248 global ASM_PFX(FspPeiCoreEntryOff)
249 ASM_PFX(FspPeiCoreEntryOff):
251 ; This value will be patched by the build script
255 global ASM_PFX(AsmGetPeiCoreOffset)
256 ASM_PFX(AsmGetPeiCoreOffset):
257 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
260 ;----------------------------------------------------------------------------
263 ; Empty function for WHOLEARCHIVE build option
265 ;----------------------------------------------------------------------------
266 global ASM_PFX(TempRamInitApi)
267 ASM_PFX(TempRamInitApi):
271 ;----------------------------------------------------------------------------
272 ; Module Entrypoint API
273 ;----------------------------------------------------------------------------
274 global ASM_PFX(_ModuleEntryPoint)
275 ASM_PFX(_ModuleEntryPoint):