2 ; Provide FSP API entry points.
4 ; Copyright (c) 2016 - 2019, 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
36 ; Following functions will be provided in C
38 extern ASM_PFX(SecStartup)
39 extern ASM_PFX(FspApiCommon)
42 ; Following functions will be provided in PlatformSecLib
44 extern ASM_PFX(AsmGetFspBaseAddress)
45 extern ASM_PFX(AsmGetFspInfoHeader)
47 API_PARAM1_OFFSET EQU 34h ; ApiParam1 [ sub esp,8 + pushad + pushfd + push eax + call]
48 FSP_HEADER_IMGBASE_OFFSET EQU 1Ch
49 FSP_HEADER_CFGREG_OFFSET EQU 24h
51 ;----------------------------------------------------------------------------
54 ; This FSP API is called after TempRamInit and initializes the memory.
56 ;----------------------------------------------------------------------------
57 global ASM_PFX(FspMemoryInitApi)
58 ASM_PFX(FspMemoryInitApi):
59 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
60 jmp ASM_PFX(FspApiCommon)
62 ;----------------------------------------------------------------------------
65 ; This API tears down temporary RAM
67 ;----------------------------------------------------------------------------
68 global ASM_PFX(TempRamExitApi)
69 ASM_PFX(TempRamExitApi):
70 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
71 jmp ASM_PFX(FspApiCommon)
73 ;----------------------------------------------------------------------------
74 ; FspApiCommonContinue API
76 ; This is the FSP API common entry point to resume the FSP execution
78 ;----------------------------------------------------------------------------
79 global ASM_PFX(FspApiCommonContinue)
80 ASM_PFX(FspApiCommonContinue):
82 ; EAX holds the API index
86 ; FspMemoryInit API setup the initial stack frame
90 ; Place holder to store the FspInfoHeader pointer
95 ; Update the FspInfoHeader pointer
98 call ASM_PFX(AsmGetFspInfoHeader)
103 ; Create a Task Frame in the stack for the Boot Loader
105 pushfd ; 2 pushf for 4 byte alignment
109 ; Reserve 8 bytes for IDT save/restore
114 ; Get Stackbase and StackSize from FSPM_UPD Param
115 mov edx, [esp + API_PARAM1_OFFSET]
119 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
121 call ASM_PFX(AsmGetFspInfoHeader)
122 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
123 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
128 ; StackBase = temp memory base, StackSize = temp memory size
130 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
131 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
134 ; Keep using bootloader stack if heap size % is 0
136 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
141 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
145 ; Switch to new FSP stack
147 xchg edi, esp ; Exchange edi and esp, edi will be assigned to the current esp pointer and esp will be Stack base + Stack size
151 ; If heap size % is 0:
152 ; EDI is FSPM_UPD_COMMON.StackBase and will hold ESP later (boot loader stack pointer)
153 ; ECX is FSPM_UPD_COMMON.StackSize
154 ; ESP is boot loader stack pointer (no stack switch)
155 ; BL is 0 to indicate no stack switch (EBX will hold FSPM_UPD_COMMON.StackBase later)
157 ; If heap size % is not 0
158 ; EDI is boot loader stack pointer
159 ; ECX is FSPM_UPD_COMMON.StackSize
160 ; ESP is new stack (FSPM_UPD_COMMON.StackBase + FSPM_UPD_COMMON.StackSize)
161 ; BL is NOT 0 to indicate stack has switched
164 jnz StackHasBeenSwitched
166 mov ebx, edi ; Put FSPM_UPD_COMMON.StackBase to ebx as temp memory base
167 mov edi, esp ; Put boot loader stack pointer to edi
170 StackHasBeenSwitched:
171 mov ebx, esp ; Put Stack base + Stack size in ebx
172 sub ebx, ecx ; Stack base + Stack size - Stack size as temp memory base
177 ; Pass the API Idx to SecStartup
182 ; Pass the BootLoader stack to SecStartup
187 ; Pass entry point of the PEI core
189 call ASM_PFX(AsmGetFspBaseAddress)
191 call ASM_PFX(AsmGetPeiCoreOffset)
196 ; Pass BFV into the PEI Core
197 ; It uses relative address to calucate the actual boot FV base
198 ; For FSP implementation with single FV, PcdFspBootFirmwareVolumeBase and
199 ; PcdFspAreaBaseAddress are the same. For FSP with mulitple FVs,
200 ; they are different. The code below can handle both cases.
202 call ASM_PFX(AsmGetFspBaseAddress)
206 ; Pass stack base and size into the PEI Core
212 ; Pass Control into the PEI Core
214 call ASM_PFX(SecStartup)
219 global ASM_PFX(FspPeiCoreEntryOff)
220 ASM_PFX(FspPeiCoreEntryOff):
222 ; This value will be pached by the build script
226 global ASM_PFX(AsmGetPeiCoreOffset)
227 ASM_PFX(AsmGetPeiCoreOffset):
228 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
231 ;----------------------------------------------------------------------------
234 ; Empty function for WHOLEARCHIVE build option
236 ;----------------------------------------------------------------------------
237 global ASM_PFX(TempRamInitApi)
238 ASM_PFX(TempRamInitApi):
242 ;----------------------------------------------------------------------------
243 ; Module Entrypoint API
244 ;----------------------------------------------------------------------------
245 global ASM_PFX(_ModuleEntryPoint)
246 ASM_PFX(_ModuleEntryPoint):