]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
916ad4ff0d7b32a0e0d77920c79c438b4d8857f4
[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 ; 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.
9 ;
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.
12 ;;
13
14 SECTION .text
15
16 ;
17 ; Following are fixed PCDs
18 ;
19 extern ASM_PFX(PcdGet32(PcdTemporaryRamBase))
20 extern ASM_PFX(PcdGet32(PcdTemporaryRamSize))
21 extern ASM_PFX(PcdGet32(PcdFspTemporaryRamSize))
22 extern ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
23
24 struc FSPM_UPD_COMMON
25 ; FSP_UPD_HEADER {
26 .FspUpdHeader: resd 8
27 ; }
28 ; FSPM_ARCH_UPD {
29 .Revision: resb 1
30 .Reserved: resb 3
31 .NvsBufferPtr: resd 1
32 .StackBase: resd 1
33 .StackSize: resd 1
34 .BootLoaderTolumSize: resd 1
35 .BootMode: resd 1
36 .Reserved1: resb 8
37 ; }
38 .size:
39 endstruc
40
41 ;
42 ; Following functions will be provided in C
43 ;
44 extern ASM_PFX(SecStartup)
45 extern ASM_PFX(FspApiCommon)
46
47 ;
48 ; Following functions will be provided in PlatformSecLib
49 ;
50 extern ASM_PFX(AsmGetFspBaseAddress)
51 extern ASM_PFX(AsmGetFspInfoHeader)
52
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
56
57 ;----------------------------------------------------------------------------
58 ; FspMemoryInit API
59 ;
60 ; This FSP API is called after TempRamInit and initializes the memory.
61 ;
62 ;----------------------------------------------------------------------------
63 global ASM_PFX(FspMemoryInitApi)
64 ASM_PFX(FspMemoryInitApi):
65 mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
66 jmp ASM_PFX(FspApiCommon)
67
68 ;----------------------------------------------------------------------------
69 ; TempRamExitApi API
70 ;
71 ; This API tears down temporary RAM
72 ;
73 ;----------------------------------------------------------------------------
74 global ASM_PFX(TempRamExitApi)
75 ASM_PFX(TempRamExitApi):
76 mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
77 jmp ASM_PFX(FspApiCommon)
78
79 ;----------------------------------------------------------------------------
80 ; FspApiCommonContinue API
81 ;
82 ; This is the FSP API common entry point to resume the FSP execution
83 ;
84 ;----------------------------------------------------------------------------
85 global ASM_PFX(FspApiCommonContinue)
86 ASM_PFX(FspApiCommonContinue):
87 ;
88 ; EAX holds the API index
89 ;
90
91 ;
92 ; FspMemoryInit API setup the initial stack frame
93 ;
94
95 ;
96 ; Place holder to store the FspInfoHeader pointer
97 ;
98 push eax
99
100 ;
101 ; Update the FspInfoHeader pointer
102 ;
103 push eax
104 call ASM_PFX(AsmGetFspInfoHeader)
105 mov [esp + 4], eax
106 pop eax
107
108 ;
109 ; Create a Task Frame in the stack for the Boot Loader
110 ;
111 pushfd ; 2 pushf for 4 byte alignment
112 cli
113 pushad
114
115 ; Reserve 8 bytes for IDT save/restore
116 sub esp, 8
117 sidt [esp]
118
119
120 ; Get Stackbase and StackSize from FSPM_UPD Param
121 mov edx, [esp + API_PARAM1_OFFSET]
122 cmp edx, 0
123 jnz FspStackSetup
124
125 ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
126 push eax
127 call ASM_PFX(AsmGetFspInfoHeader)
128 mov edx, [eax + FSP_HEADER_IMGBASE_OFFSET]
129 add edx, [eax + FSP_HEADER_CFGREG_OFFSET]
130 pop eax
131
132 FspStackSetup:
133 ;
134 ; StackBase = temp memory base, StackSize = temp memory size
135 ;
136 mov edi, [edx + FSPM_UPD_COMMON.StackBase]
137 mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
138
139 ;
140 ; Keep using bootloader stack if heap size % is 0
141 ;
142 mov bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]
143 cmp bl, 0
144 jz SkipStackSwitch
145
146 ;
147 ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
148 ;
149 add edi, ecx
150 ;
151 ; Switch to new FSP stack
152 ;
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
154
155 SkipStackSwitch:
156 ;
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)
162 ;
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
168 ;
169 cmp bl, 0
170 jnz StackHasBeenSwitched
171
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
174 jmp StackSetupDone
175
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
179
180 StackSetupDone:
181
182 ;
183 ; Pass the API Idx to SecStartup
184 ;
185 push eax
186
187 ;
188 ; Pass the BootLoader stack to SecStartup
189 ;
190 push edi
191
192 ;
193 ; Pass entry point of the PEI core
194 ;
195 call ASM_PFX(AsmGetFspBaseAddress)
196 mov edi, eax
197 call ASM_PFX(AsmGetPeiCoreOffset)
198 add edi, eax
199 push edi
200
201 ;
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.
207 ;
208 call ASM_PFX(AsmGetFspBaseAddress)
209 push eax
210
211 ;
212 ; Pass stack base and size into the PEI Core
213 ;
214 push ebx
215 push ecx
216
217 ;
218 ; Pass Control into the PEI Core
219 ;
220 call ASM_PFX(SecStartup)
221 add esp, 4
222 exit:
223 ret
224
225 global ASM_PFX(FspPeiCoreEntryOff)
226 ASM_PFX(FspPeiCoreEntryOff):
227 ;
228 ; This value will be pached by the build script
229 ;
230 DD 0x12345678
231
232 global ASM_PFX(AsmGetPeiCoreOffset)
233 ASM_PFX(AsmGetPeiCoreOffset):
234 mov eax, dword [ASM_PFX(FspPeiCoreEntryOff)]
235 ret
236
237 ;----------------------------------------------------------------------------
238 ; TempRamInit API
239 ;
240 ; Empty function for WHOLEARCHIVE build option
241 ;
242 ;----------------------------------------------------------------------------
243 global ASM_PFX(TempRamInitApi)
244 ASM_PFX(TempRamInitApi):
245 jmp $
246 ret
247
248 ;----------------------------------------------------------------------------
249 ; Module Entrypoint API
250 ;----------------------------------------------------------------------------
251 global ASM_PFX(_ModuleEntryPoint)
252 ASM_PFX(_ModuleEntryPoint):
253 jmp $