2 ; Provide FSP API entry points.
4 ; Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 ; This program and the accompanying materials
6 ; are licensed and made available under the terms and conditions of the BSD License
7 ; which accompanies this distribution. The full text of the license may be found at
8 ; http://opensource.org/licenses/bsd-license.php.
10 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 ; Following are fixed PCDs
19 extern ASM_PFX(PcdGet32(PcdTemporaryRamBase))
20 extern ASM_PFX(PcdGet32(PcdTemporaryRamSize))
21 extern ASM_PFX(PcdGet32(PcdFspTemporaryRamSize))
22 extern ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
34 .BootLoaderTolumSize: resd 1
42 ; Following functions will be provided in C
44 extern ASM_PFX(SecStartup)
45 extern ASM_PFX(FspApiCommon)
48 ; Following functions will be provided in PlatformSecLib
50 extern ASM_PFX(AsmGetFspBaseAddress)
51 extern ASM_PFX(AsmGetFspInfoHeader)
53 API_PARAM1_OFFSET EQU 34h ; ApiParam1 [ sub esp,8 + pushad + pushfd + push eax + call]
54 FSP_HEADER_IMGBASE_OFFSET EQU 1Ch
55 FSP_HEADER_CFGREG_OFFSET EQU 24h
57 ;----------------------------------------------------------------------------
60 ; This FSP API is called after TempRamInit and initializes the memory.
62 ;----------------------------------------------------------------------------
63 global ASM_PFX(FspMemoryInitApi)
64 ASM_PFX(FspMemoryInitApi):
65 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
66 jmp ASM_PFX(FspApiCommon)
68 ;----------------------------------------------------------------------------
71 ; This API tears down temporary RAM
73 ;----------------------------------------------------------------------------
74 global ASM_PFX(TempRamExitApi)
75 ASM_PFX(TempRamExitApi):
76 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
77 jmp ASM_PFX(FspApiCommon)
79 ;----------------------------------------------------------------------------
80 ; FspApiCommonContinue API
82 ; This is the FSP API common entry point to resume the FSP execution
84 ;----------------------------------------------------------------------------
85 global ASM_PFX(FspApiCommonContinue)
86 ASM_PFX(FspApiCommonContinue):
88 ; EAX holds the API index
92 ; FspMemoryInit API setup the initial stack frame
96 ; Place holder to store the FspInfoHeader pointer
101 ; Update the FspInfoHeader pointer
104 call ASM_PFX(AsmGetFspInfoHeader)
109 ; Create a Task Frame in the stack for the Boot Loader
111 pushfd ; 2 pushf for 4 byte alignment
115 ; Reserve 8 bytes for IDT save/restore
120 ; Get Stackbase and StackSize from FSPM_UPD Param
121 mov edx, [esp + API_PARAM1_OFFSET]
125 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
127 call ASM_PFX(AsmGetFspInfoHeader)
128 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
129 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
134 ; StackBase = temp memory base, StackSize = temp memory size
136 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
137 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
140 ; Keep using bootloader stack if heap size % is 0
142 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
147 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
151 ; Switch to new FSP stack
153 xchg edi, esp ; Exchange edi and esp, edi will be assigned to the current esp pointer and esp will be Stack base + Stack size
157 ; If heap size % is 0:
158 ; EDI is FSPM_UPD_COMMON.StackBase and will hold ESP later (boot loader stack pointer)
159 ; ECX is FSPM_UPD_COMMON.StackSize
160 ; ESP is boot loader stack pointer (no stack switch)
161 ; BL is 0 to indicate no stack switch (EBX will hold FSPM_UPD_COMMON.StackBase later)
163 ; If heap size % is not 0
164 ; EDI is boot loader stack pointer
165 ; ECX is FSPM_UPD_COMMON.StackSize
166 ; ESP is new stack (FSPM_UPD_COMMON.StackBase + FSPM_UPD_COMMON.StackSize)
167 ; BL is NOT 0 to indicate stack has switched
170 jnz StackHasBeenSwitched
172 mov ebx, edi ; Put FSPM_UPD_COMMON.StackBase to ebx as temp memory base
173 mov edi, esp ; Put boot loader stack pointer to edi
176 StackHasBeenSwitched:
177 mov ebx, esp ; Put Stack base + Stack size in ebx
178 sub ebx, ecx ; Stack base + Stack size - Stack size as temp memory base
183 ; Pass the API Idx to SecStartup
188 ; Pass the BootLoader stack to SecStartup
193 ; Pass entry point of the PEI core
195 call ASM_PFX(AsmGetFspBaseAddress)
197 call ASM_PFX(AsmGetPeiCoreOffset)
202 ; Pass BFV into the PEI Core
203 ; It uses relative address to calucate the actual boot FV base
204 ; For FSP implementation with single FV, PcdFspBootFirmwareVolumeBase and
205 ; PcdFspAreaBaseAddress are the same. For FSP with mulitple FVs,
206 ; they are different. The code below can handle both cases.
208 call ASM_PFX(AsmGetFspBaseAddress)
212 ; Pass stack base and size into the PEI Core
218 ; Pass Control into the PEI Core
220 call ASM_PFX(SecStartup)
225 global ASM_PFX(FspPeiCoreEntryOff)
226 ASM_PFX(FspPeiCoreEntryOff):
228 ; This value will be pached by the build script
232 global ASM_PFX(AsmGetPeiCoreOffset)
233 ASM_PFX(AsmGetPeiCoreOffset):
234 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
237 ;----------------------------------------------------------------------------
240 ; Empty function for WHOLEARCHIVE build option
242 ;----------------------------------------------------------------------------
243 global ASM_PFX(TempRamInitApi)
244 ASM_PFX(TempRamInitApi):
248 ;----------------------------------------------------------------------------
249 ; Module Entrypoint API
250 ;----------------------------------------------------------------------------
251 global ASM_PFX(_ModuleEntryPoint)
252 ASM_PFX(_ModuleEntryPoint):