]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
IntelFsp2Pkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / Ia32 / FspApiEntryM.nasm
1 ;; @file
2 ; Provide FSP API entry points.
3 ;
4 ; Copyright (c) 2016 - 2019, 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 ;
36 ; Following functions will be provided in C
37 ;
38 extern ASM_PFX(SecStartup)
39 extern ASM_PFX(FspApiCommon)
40
41 ;
42 ; Following functions will be provided in PlatformSecLib
43 ;
44 extern ASM_PFX(AsmGetFspBaseAddress)
45 extern ASM_PFX(AsmGetFspInfoHeader)
46
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
50
51 ;----------------------------------------------------------------------------
52 ; FspMemoryInit API
53 ;
54 ; This FSP API is called after TempRamInit and initializes the memory.
55 ;
56 ;----------------------------------------------------------------------------
57 global ASM_PFX(FspMemoryInitApi)
58 ASM_PFX(FspMemoryInitApi):
59 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
60 jmp ASM_PFX(FspApiCommon)
61
62 ;----------------------------------------------------------------------------
63 ; TempRamExitApi API
64 ;
65 ; This API tears down temporary RAM
66 ;
67 ;----------------------------------------------------------------------------
68 global ASM_PFX(TempRamExitApi)
69 ASM_PFX(TempRamExitApi):
70 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
71 jmp ASM_PFX(FspApiCommon)
72
73 ;----------------------------------------------------------------------------
74 ; FspApiCommonContinue API
75 ;
76 ; This is the FSP API common entry point to resume the FSP execution
77 ;
78 ;----------------------------------------------------------------------------
79 global ASM_PFX(FspApiCommonContinue)
80 ASM_PFX(FspApiCommonContinue):
81 ;
82 ; EAX holds the API index
83 ;
84
85 ;
86 ; FspMemoryInit API setup the initial stack frame
87 ;
88
89 ;
90 ; Place holder to store the FspInfoHeader pointer
91 ;
92 push eax
93
94 ;
95 ; Update the FspInfoHeader pointer
96 ;
97 push eax
98 call ASM_PFX(AsmGetFspInfoHeader)
99 mov [esp + 4], eax
100 pop eax
101
102 ;
103 ; Create a Task Frame in the stack for the Boot Loader
104 ;
105 pushfd ; 2 pushf for 4 byte alignment
106 cli
107 pushad
108
109 ; Reserve 8 bytes for IDT save/restore
110 sub esp, 8
111 sidt [esp]
112
113
114 ; Get Stackbase and StackSize from FSPM_UPD Param
115 mov edx, [esp + API_PARAM1_OFFSET]
116 cmp edx, 0
117 jnz FspStackSetup
118
119 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
120 push eax
121 call ASM_PFX(AsmGetFspInfoHeader)
122 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
123 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
124 pop eax
125
126 FspStackSetup:
127 ;
128 ; StackBase = temp memory base, StackSize = temp memory size
129 ;
130 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
131 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
132
133 ;
134 ; Keep using bootloader stack if heap size % is 0
135 ;
136 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
137 cmp bl, 0
138 jz SkipStackSwitch
139
140 ;
141 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
142 ;
143 add edi, ecx
144 ;
145 ; Switch to new FSP stack
146 ;
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
148
149 SkipStackSwitch:
150 ;
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)
156 ;
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
162 ;
163 cmp bl, 0
164 jnz StackHasBeenSwitched
165
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
168 jmp StackSetupDone
169
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
173
174 StackSetupDone:
175
176 ;
177 ; Pass the API Idx to SecStartup
178 ;
179 push eax
180
181 ;
182 ; Pass the BootLoader stack to SecStartup
183 ;
184 push edi
185
186 ;
187 ; Pass entry point of the PEI core
188 ;
189 call ASM_PFX(AsmGetFspBaseAddress)
190 mov edi, eax
191 call ASM_PFX(AsmGetPeiCoreOffset)
192 add edi, eax
193 push edi
194
195 ;
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.
201 ;
202 call ASM_PFX(AsmGetFspBaseAddress)
203 push eax
204
205 ;
206 ; Pass stack base and size into the PEI Core
207 ;
208 push ebx
209 push ecx
210
211 ;
212 ; Pass Control into the PEI Core
213 ;
214 call ASM_PFX(SecStartup)
215 add esp, 4
216 exit:
217 ret
218
219 global ASM_PFX(FspPeiCoreEntryOff)
220 ASM_PFX(FspPeiCoreEntryOff):
221 ;
222 ; This value will be pached by the build script
223 ;
224 DD 0x12345678
225
226 global ASM_PFX(AsmGetPeiCoreOffset)
227 ASM_PFX(AsmGetPeiCoreOffset):
228 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
229 ret
230
231 ;----------------------------------------------------------------------------
232 ; TempRamInit API
233 ;
234 ; Empty function for WHOLEARCHIVE build option
235 ;
236 ;----------------------------------------------------------------------------
237 global ASM_PFX(TempRamInitApi)
238 ASM_PFX(TempRamInitApi):
239 jmp $
240 ret
241
242 ;----------------------------------------------------------------------------
243 ; Module Entrypoint API
244 ;----------------------------------------------------------------------------
245 global ASM_PFX(_ModuleEntryPoint)
246 ASM_PFX(_ModuleEntryPoint):
247 jmp $