1 #------------------------------------------------------------------------------
3 # Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
4 # This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php.
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 # Provide FSP API entry points.
16 #------------------------------------------------------------------------------
18 #.INCLUDE "UcodeLoad.inc"
21 # Following are fixed PCDs
24 .equ MSR_IA32_PLATFORM_ID, 0x000000017
25 .equ MSR_IA32_BIOS_UPDT_TRIG, 0x000000079
26 .equ MSR_IA32_BIOS_SIGN_ID, 0x00000008b
28 ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamBase)
29 ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamSize)
30 ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdFspTemporaryRamSize)
31 ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdFspAreaSize)
35 # Following functions will be provided in C
37 #EXTERNDEF SecStartup:PROC
38 #EXTERNDEF FspApiCallingCheck:PROC
41 # Following functions will be provided in PlatformSecLib
43 #EXTERNDEF GetFspBaseAddress:PROC
44 #EXTERNDEF GetBootFirmwareVolumeOffset:PROC
45 #EXTERNDEF PlatformTempRamInit:PROC
46 #EXTERNDEF Pei2LoaderSwitchStack:PROC
47 #EXTERN FspSelfCheck(FspSelfCheckDflt):PROC
48 #EXTERN PlatformBasicInit(PlatformBasicInitDflt):PROC
51 # Define the data length that we saved on the stack top
53 .equ DATA_LEN_OF_PER0, 0x018
54 .equ DATA_LEN_OF_MCUD, 0x018
55 .equ DATA_LEN_AT_STACK_TOP, (DATA_LEN_OF_PER0 + DATA_LEN_OF_MCUD + 4)
62 orl $0x00000600,%eax # Set OSFXSR bit (bit #9) & OSXMMEXCPT bit (bit #10)
68 pshufd $0x93, %xmm7, %xmm7
71 pshufd $0x93, %xmm7, %xmm7
74 pshufd $0x93, %xmm7, %xmm7
83 pshufd $0x39,%xmm7, %xmm7
85 pshufd $0x39,%xmm7, %xmm7
87 pshufd $0x39, %xmm7, %xmm7
95 #------------------------------------------------------------------------------
96 ASM_GLOBAL ASM_PFX(FspSelfCheckDflt)
97 ASM_PFX(FspSelfCheckDflt):
99 # eax -> Return address
101 # eax -> 0 - Successful, Non-zero - Failed.
103 # eax is cleared and ebp is used for return address.
104 # All others reserved.
106 # Save return address to EBP
111 #FspSelfCheckDflt ENDP
113 #------------------------------------------------------------------------------
114 ASM_GLOBAL ASM_PFX(PlatformBasicInitDflt)
115 ASM_PFX(PlatformBasicInitDflt):
117 # eax -> Return address
119 # eax -> 0 - Successful, Non-zero - Failed.
121 # eax is cleared and ebp is used for return address.
122 # All others reserved.
124 # Save return address to EBP
129 #PlatformBasicInitDflt ENDP
131 #------------------------------------------------------------------------------
132 ASM_GLOBAL ASM_PFX(LoadUcode)
135 # esp -> LOAD_UCODE_PARAMS pointer
138 # All others destroyed
140 # No memory available, stack is hard-coded and used for return address
141 # Executed by SBSP and NBSP
142 # Beginning of microcode update region starts on paragraph boundary
146 # Save return address to EBP
150 movl (%esp), %eax #dword ptr [] Parameter pointer
154 movl (%esp), %esi #LOAD_UCODE_PARAMS.ucode_code_addr
159 movl $0x080000002, %eax
162 movl (%esp), %esi #.LOAD_UCODE_PARAMS.ucode_code_addr
165 # Get processor signature and platform ID from the installed processor
166 # and save into registers for later use
167 # ebx = processor signature
172 movl MSR_IA32_PLATFORM_ID, %ecx
175 #--------------------------------------------------------------------------------------------------------------------
176 shrl $18, %ecx #($50-$32)
181 # Current register usage
182 # esp -> stack with paramters
183 # esi -> microcode update to check
184 # ebx = processor signature
187 # Check for valid microcode header
188 # Minimal test checking for header version and loader version as 1
190 cmpl %eax, (%esi) #.ucode_hdr.version
191 jne advance_fixed_size
192 cmpl %eax, 0x18(%esi) #.ucode_hdr.loader
193 jne advance_fixed_size
195 # Check if signature and plaform ID match
196 #--------------------------------------------------------------------------------------------------------------------------
197 cmpl 0x10(%esi), %ebx #(%esi).ucode_hdr.processor
199 testl 0x1c(%esi) , %edx #(%esi).ucode_hdr.flags
200 jnz load_check # Jif signature and platform ID match
203 # Check if extended header exists
204 # First check if total_size and data_size are valid
206 cmpl %eax,0x24(%esi) #(%esi).ucode_hdr.total_size
208 cmpl %eax,0x20(%esi) #(%esi) .ucode_hdr.data_size
211 # Then verify total size - sizeof header > data size
212 movl 0x24(%esi), %ecx #(%esi).ucode_hdr.total_size
213 subl $0x30, %ecx #sizeof ucode_hdr = 48
214 cmpl 0x20(%esi), %ecx #(%esi).ucode_hdr.data_size
216 jb next_microcode # Jif extended header does not exist
218 # Check if total size fits in microcode region
220 addl 0x24(%esi), %edi # (%esi).ucode_hdr.total_size
221 movl (%esp), %ecx # (%esp).LOAD_UCODE_PARAMS.ucode_code_addr
222 addl 4(%esp), %ecx #.LOAD_UCODE_PARAMS.ucode_code_size
225 ja exit4 # Jif address is outside of ucode region
227 # Set edi -> extended header
229 addl $0x30 , %edi #sizeof ucode_hdr = 48
230 addl 0x20(%esi), %edi #%esi.ucode_hdr.data_size
232 # Get count of extended structures
233 movl (%edi), %ecx #(%edi).ext_sig_hdr.count
235 # Move pointer to first signature structure
236 addl $0x20, %edi # sizeof ext_sig_hdr = 20
239 # Check if extended signature and platform ID match
240 cmpl %ebx, (%edi) #[edi].ext_sig.processor
242 test %edx, 4(%edi) #[edi].ext_sig.flags
243 jnz load_check # Jif signature and platform ID match
245 # Check if any more extended signatures exist
246 addl $0xc, %edi #sizeof ext_sig = 12
250 # Advance just after end of this microcode
252 cmpl %eax, 0x24(%esi) #(%esi).ucode_hdr.total_size
254 add 0x24(%esi) , %esi #(%esi).ucode_hdr.total_size
261 # Advance by 4X dwords
265 # Is valid Microcode start point ?
266 cmp $0x0ffffffff , %esi
269 # Address >= microcode region address + microcode region size?
270 movl (%esp), %eax #(%esp).LOAD_UCODE_PARAMS.ucode_code_addr
271 addl 4(%esp), %eax #(%esp).LOAD_UCODE_PARAMS.ucode_code_size
273 jae done #Jif address is outside of ucode region
274 jmp check_main_header
277 # Get the revision of the current microcode update loaded
278 movl MSR_IA32_BIOS_SIGN_ID, %ecx
279 xorl %eax, %eax # Clear EAX
280 xorl %edx, %edx # Clear EDX
281 wrmsr # Load 0 to MSR at 8Bh
285 movl MSR_IA32_BIOS_SIGN_ID, %ecx
286 rdmsr # Get current microcode signature
288 # Verify this microcode update is not already loaded
289 cmpl %edx, 4(%esi) #(%esi).ucode_hdr.revision
293 # EAX contains the linear address of the start of the Update Data
295 # ECX contains 79h (IA32_BIOS_UPDT_TRIG)
296 # Start microcode load with wrmsr
298 add $0x30, %eax #sizeof ucode_hdr = 48
300 mov MSR_IA32_BIOS_UPDT_TRIG,%ecx
311 mov MSR_IA32_BIOS_SIGN_ID, %ecx
312 rdmsr # Get current microcode signature
316 mov $0x08000000E, %eax
323 #----------------------------------------------------------------------------
326 # This FSP API will load the microcode update, enable code caching for the
327 # region specified by the boot loader and also setup a temporary stack to be
328 # used till main memory is initialized.
330 #----------------------------------------------------------------------------
331 ASM_GLOBAL ASM_PFX(TempRamInitApi)
332 ASM_PFX(TempRamInitApi):
334 # Ensure SSE is enabled
339 # Save EBP, EBX, ESI, EDI & ESP in XMM7 & XMM6
344 # Save timestamp into XMM4 & XMM5
351 # CPUID/DeviceID check
354 jmp ASM_PFX(FspSelfCheck) # Note: ESP can not be changed.
360 # Platform Basic Init.
363 jmp ASM_PFX(PlatformBasicInitDflt)
380 # Call platform NEM init
381 #-------------------------------------------------------------------------------------------------------------------------
384 jmp ASM_PFX(PlatformTempRamInit)
391 # Save parameter pointer in edx
398 movl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamBase), %esp
399 addl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamSize), %esp
401 pushl $DATA_LEN_OF_MCUD # Size of the data region
402 pushl 0x4455434D # Signature of the data region 'MCUD'
403 pushl 12(%edx) # Code size
404 pushl 8(%edx) # Code base
405 cmpl $0, %edx # Is parameter pointer valid ?
406 jz InvalidMicrocodeRegion
407 pushl 4(%edx) # Microcode size
408 pushl (%edx) # Microcode base
411 InvalidMicrocodeRegion:
412 pushl $0 # Microcode size
413 pushl $0 # Microcode base
417 # Save API entry/exit timestamp into stack
419 pushl DATA_LEN_OF_PER0 # Size of the data region
420 pushl 0x30524550 # Signature of the data region 'PER0'
430 # Terminator for the data on stack
435 # Set ECX/EDX to the bootloader temporary memory range
437 movl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamBase), %ecx
439 addl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamSize), %edx
440 subl ASM_PFX(_gPcd_FixedAtBuild_PcdFspTemporaryRamSize), %edx
446 # Load EBP, EBX, ESI, EDI & ESP from XMM7 & XMM6
452 #----------------------------------------------------------------------------
455 # This FSP API will perform the processor and chipset initialization.
456 # This API will not return. Instead, it transfers the control to the
457 # ContinuationFunc provided in the parameter.
459 #----------------------------------------------------------------------------
460 ASM_GLOBAL ASM_PFX(FspInitApi)
463 # Stack must be ready
467 cmpl $0x087654321, %eax
469 movl $0x080000003, %eax
478 call ASM_PFX(FspApiCallingCheck)
488 # Save the Platform Data Pointer in EDI
493 # Store the address in FSP which will return control to the BL
498 # Create a Task Frame in the stack for the Boot Loader
501 pushfl # 2 pushf for 4 byte alignment
505 # Reserve 8 bytes for IDT save/restore
511 # Setup new FSP stack
514 movl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamBase), %esp
515 addl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamSize) , %esp
516 subl DATA_LEN_AT_STACK_TOP, %esp
517 addl $0x0FFFFFFC0, %esp
520 # Save the bootloader's stack pointer
525 # Pass entry point of the PEI core
527 call ASM_PFX(GetFspBaseAddress)
529 addl ASM_PFX(_gPcd_FixedAtBuild_PcdFspAreaSize), %edi
531 addl %ds:(%edi), %eax
535 # Pass BFV into the PEI Core
536 # It uses relative address to calucate the actual boot FV base
537 # For FSP impleantion with single FV, PcdFlashFvRecoveryBase and
538 # PcdFspAreaBaseAddress are the same. For FSP with mulitple FVs,
539 # they are different. The code below can handle both cases.
541 call ASM_PFX(GetFspBaseAddress)
543 call ASM_PFX(GetBootFirmwareVolumeOffset)
548 # Pass stack base and size into the PEI Core
550 movl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamBase), %eax
551 addl ASM_PFX(_gPcd_FixedAtBuild_PcdTemporaryRamSize), %eax
552 subl ASM_PFX(_gPcd_FixedAtBuild_PcdFspTemporaryRamSize), %eax
554 pushl ASM_PFX(_gPcd_FixedAtBuild_PcdFspTemporaryRamSize)
557 # Pass Control into the PEI Core
559 call ASM_PFX(SecStartup)
566 #----------------------------------------------------------------------------
569 # This FSP API will notify the FSP about the different phases in the boot
572 #----------------------------------------------------------------------------
573 ASM_GLOBAL ASM_PFX(NotifyPhaseApi)
574 ASM_PFX(NotifyPhaseApi):
576 # Stack must be ready
580 cmpl $0x087654321, %eax
582 movl $0x080000003, %eax
587 # Verify the calling condition
591 call ASM_PFX(FspApiCallingCheck)
606 jmp ASM_PFX(Pei2LoaderSwitchStack)