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
45 .BootLoaderTolumSize: resd 1
47 .FspEventHandler resq 1
54 ; Following functions will be provided in C
56 extern ASM_PFX(SecStartup)
57 extern ASM_PFX(FspApiCommon)
60 ; Following functions will be provided in PlatformSecLib
62 extern ASM_PFX(AsmGetFspBaseAddress)
63 extern ASM_PFX(AsmGetFspInfoHeader)
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
69 ;----------------------------------------------------------------------------
72 ; This FSP API is called after TempRamInit and initializes the memory.
74 ;----------------------------------------------------------------------------
75 global ASM_PFX(FspMemoryInitApi)
76 ASM_PFX(FspMemoryInitApi):
77 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
78 jmp ASM_PFX(FspApiCommon)
80 ;----------------------------------------------------------------------------
83 ; This API tears down temporary RAM
85 ;----------------------------------------------------------------------------
86 global ASM_PFX(TempRamExitApi)
87 ASM_PFX(TempRamExitApi):
88 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
89 jmp ASM_PFX(FspApiCommon)
91 ;----------------------------------------------------------------------------
92 ; FspApiCommonContinue API
94 ; This is the FSP API common entry point to resume the FSP execution
96 ;----------------------------------------------------------------------------
97 global ASM_PFX(FspApiCommonContinue)
98 ASM_PFX(FspApiCommonContinue):
100 ; EAX holds the API index
104 ; FspMemoryInit API setup the initial stack frame
108 ; Place holder to store the FspInfoHeader pointer
113 ; Update the FspInfoHeader pointer
116 call ASM_PFX(AsmGetFspInfoHeader)
121 ; Create a Task Frame in the stack for the Boot Loader
123 pushfd ; 2 pushf for 4 byte alignment
127 ; Reserve 8 bytes for IDT save/restore
132 ; Get Stackbase and StackSize from FSPM_UPD Param
133 mov edx, [esp + API_PARAM1_OFFSET]
137 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
139 call ASM_PFX(AsmGetFspInfoHeader)
140 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
141 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
145 mov ecx, [edx + FSPM_UPD_COMMON.Revision]
150 ; StackBase = temp memory base, StackSize = temp memory size
152 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
153 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
157 mov edi, [edx + FSPM_UPD_COMMON_FSP24.StackBase]
158 mov ecx, [edx + FSPM_UPD_COMMON_FSP24.StackSize]
162 ; Keep using bootloader stack if heap size % is 0
164 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
169 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
173 ; Switch to new FSP stack
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
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)
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
192 jnz StackHasBeenSwitched
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
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
205 ; Pass the API Idx to SecStartup
210 ; Pass the BootLoader stack to SecStartup
215 ; Pass entry point of the PEI core
217 call ASM_PFX(AsmGetFspBaseAddress)
219 call ASM_PFX(AsmGetPeiCoreOffset)
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.
230 call ASM_PFX(AsmGetFspBaseAddress)
234 ; Pass stack base and size into the PEI Core
240 ; Pass Control into the PEI Core
242 call ASM_PFX(SecStartup)
247 global ASM_PFX(FspPeiCoreEntryOff)
248 ASM_PFX(FspPeiCoreEntryOff):
250 ; This value will be patched by the build script
254 global ASM_PFX(AsmGetPeiCoreOffset)
255 ASM_PFX(AsmGetPeiCoreOffset):
256 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
259 ;----------------------------------------------------------------------------
262 ; Empty function for WHOLEARCHIVE build option
264 ;----------------------------------------------------------------------------
265 global ASM_PFX(TempRamInitApi)
266 ASM_PFX(TempRamInitApi):
270 ;----------------------------------------------------------------------------
271 ; Module Entrypoint API
272 ;----------------------------------------------------------------------------
273 global ASM_PFX(_ModuleEntryPoint)
274 ASM_PFX(_ModuleEntryPoint):