]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspPkg/FspSecCore/Ia32/FspApiEntry.asm
Fix FSP GCC error on FspApiCallingCheck().
[mirror_edk2.git] / IntelFspPkg / FspSecCore / Ia32 / FspApiEntry.asm
index afe995c8bd011d1980047c5ae4df8b4eb6e639f5..a0c9b1ed7351a5911310283cc9e0560472a733ba 100644 (file)
@@ -17,7 +17,7 @@
     .xmm\r
 \r
 INCLUDE    SaveRestoreSse.inc\r
-INCLUDE    UcodeLoad.inc\r
+INCLUDE    MicrocodeLoad.inc\r
 \r
 ;\r
 ; Following are fixed PCDs\r
@@ -37,11 +37,11 @@ EXTERN   FspApiCallingCheck:PROC
 ;\r
 ; Following functions will be provided in PlatformSecLib\r
 ;\r
-EXTERN   GetFspBaseAddress:PROC\r
+EXTERN   AsmGetFspBaseAddress:PROC\r
+EXTERN   AsmGetFspInfoHeader:PROC\r
 EXTERN   GetBootFirmwareVolumeOffset:PROC\r
-EXTERN   Pei2LoaderSwitchStack:PROC\r
-EXTERN   FspSelfCheck(FspSelfCheckDefault):PROC\r
-EXTERN   LoadUcode(LoadUcodeDefault):PROC\r
+EXTERN   Loader2PeiSwitchStack:PROC\r
+EXTERN   LoadMicrocode(LoadMicrocodeDefault):PROC\r
 EXTERN   SecPlatformInit(SecPlatformInitDefault):PROC\r
 EXTERN   SecCarInit:PROC\r
 \r
@@ -57,19 +57,19 @@ DATA_LEN_AT_STACK_TOP    EQU   (DATA_LEN_OF_PER0 + DATA_LEN_OF_MCUD + 4)
 ;\r
 LOAD_MMX_EXT MACRO   ReturnAddress, MmxRegister\r
   mov     esi, ReturnAddress\r
-  movd    MmxRegister, esi              ; save ReturnAddress into MM7  \r
+  movd    MmxRegister, esi              ; save ReturnAddress into MMX\r
 ENDM\r
 \r
 CALL_MMX_EXT MACRO   RoutineLabel, MmxRegister\r
   local   ReturnAddress\r
   mov     esi, offset ReturnAddress\r
-  movd    MmxRegister, esi              ; save ReturnAddress into MM7\r
+  movd    MmxRegister, esi              ; save ReturnAddress into MMX\r
   jmp     RoutineLabel\r
 ReturnAddress:\r
 ENDM\r
 \r
 RET_ESI_EXT  MACRO   MmxRegister\r
-  movd    esi, MmxRegister              ; restore ESP from MM7\r
+  movd    esi, MmxRegister              ; move ReturnAddress from MMX to ESI\r
   jmp     esi\r
 ENDM\r
 \r
@@ -78,39 +78,21 @@ CALL_MMX MACRO   RoutineLabel
 ENDM\r
 \r
 RET_ESI  MACRO\r
-         RET_ESI_EXT   mm7  \r
+         RET_ESI_EXT   mm7\r
 ENDM\r
 \r
-;------------------------------------------------------------------------------\r
-FspSelfCheckDefault PROC NEAR PUBLIC\r
-   ; Inputs:\r
-   ;   eax -> Return address\r
-   ; Outputs:\r
-   ;   eax -> 0 - Successful, Non-zero - Failed.\r
-   ; Register Usage:\r
-   ;   eax is cleared and ebp is used for return address.\r
-   ;   All others reserved.\r
-\r
-   ; Save return address to EBP\r
-   mov   ebp, eax\r
-\r
-   xor   eax, eax\r
-exit:\r
-   jmp   ebp\r
-FspSelfCheckDefault   ENDP\r
-\r
 ;------------------------------------------------------------------------------\r
 SecPlatformInitDefault PROC NEAR PUBLIC\r
    ; Inputs:\r
-   ;   eax -> Return address\r
+   ;   mm7 -> Return address\r
    ; Outputs:\r
    ;   eax -> 0 - Successful, Non-zero - Failed.\r
    ; Register Usage:\r
    ;   eax is cleared and ebp is used for return address.\r
    ;   All others reserved.\r
-\r
+   \r
    ; Save return address to EBP\r
-   mov   ebp, eax\r
+   movd  ebp, mm7\r
 \r
    xor   eax, eax\r
 exit:\r
@@ -118,9 +100,9 @@ exit:
 SecPlatformInitDefault   ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
-LoadUcodeDefault   PROC  NEAR PUBLIC\r
+LoadMicrocodeDefault   PROC  NEAR PUBLIC\r
    ; Inputs:\r
-   ;   esp -> LOAD_UCODE_PARAMS pointer\r
+   ;   esp -> LoadMicrocodeParams pointer\r
    ; Register Usage:\r
    ;   esp  Preserved\r
    ;   All others destroyed\r
@@ -136,11 +118,11 @@ LoadUcodeDefault   PROC  NEAR PUBLIC
 \r
    cmp    esp, 0\r
    jz     paramerror\r
-   mov    eax, dword ptr [esp]    ; Parameter pointer\r
+   mov    eax, dword ptr [esp + 4]    ; Parameter pointer\r
    cmp    eax, 0\r
    jz     paramerror\r
    mov    esp, eax\r
-   mov    esi, [esp].LOAD_UCODE_PARAMS.ucode_code_addr\r
+   mov    esi, [esp].LoadMicrocodeParams.MicrocodeCodeAddr\r
    cmp    esi, 0\r
    jnz    check_main_header\r
 \r
@@ -148,7 +130,7 @@ paramerror:
    mov    eax, 080000002h\r
    jmp    exit\r
 \r
-   mov    esi, [esp].LOAD_UCODE_PARAMS.ucode_code_addr\r
+   mov    esi, [esp].LoadMicrocodeParams.MicrocodeCodeAddr\r
 \r
 check_main_header:\r
    ; Get processor signature and platform ID from the installed processor\r
@@ -175,60 +157,60 @@ check_main_header:
    ; Check for valid microcode header\r
    ; Minimal test checking for header version and loader version as 1\r
    mov   eax, dword ptr 1\r
-   cmp   [esi].ucode_hdr.version, eax\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrVersion, eax\r
    jne   advance_fixed_size\r
-   cmp   [esi].ucode_hdr.loader, eax\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrLoader, eax\r
    jne   advance_fixed_size\r
 \r
    ; Check if signature and plaform ID match\r
-   cmp   ebx, [esi].ucode_hdr.processor\r
+   cmp   ebx, [esi].MicrocodeHdr.MicrocodeHdrProcessor\r
    jne   @f\r
-   test  edx, [esi].ucode_hdr.flags\r
+   test  edx, [esi].MicrocodeHdr.MicrocodeHdrFlags\r
    jnz   load_check  ; Jif signature and platform ID match\r
 \r
 @@:\r
    ; Check if extended header exists\r
-   ; First check if total_size and data_size are valid\r
+   ; First check if MicrocodeHdrTotalSize and MicrocodeHdrDataSize are valid\r
    xor   eax, eax\r
-   cmp   [esi].ucode_hdr.total_size, eax\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrTotalSize, eax\r
    je    next_microcode\r
-   cmp   [esi].ucode_hdr.data_size, eax\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrDataSize, eax\r
    je    next_microcode\r
 \r
    ; Then verify total size - sizeof header > data size\r
-   mov   ecx, [esi].ucode_hdr.total_size\r
-   sub   ecx, sizeof ucode_hdr\r
-   cmp   ecx, [esi].ucode_hdr.data_size\r
+   mov   ecx, [esi].MicrocodeHdr.MicrocodeHdrTotalSize\r
+   sub   ecx, sizeof MicrocodeHdr\r
+   cmp   ecx, [esi].MicrocodeHdr.MicrocodeHdrDataSize\r
    jng   next_microcode    ; Jif extended header does not exist\r
 \r
    ; Set edi -> extended header\r
    mov   edi, esi\r
-   add   edi, sizeof ucode_hdr\r
-   add   edi, [esi].ucode_hdr.data_size\r
+   add   edi, sizeof MicrocodeHdr\r
+   add   edi, [esi].MicrocodeHdr.MicrocodeHdrDataSize\r
 \r
    ; Get count of extended structures\r
-   mov   ecx, [edi].ext_sig_hdr.count\r
+   mov   ecx, [edi].ExtSigHdr.ExtSigHdrCount\r
 \r
    ; Move pointer to first signature structure\r
-   add   edi, sizeof ext_sig_hdr\r
+   add   edi, sizeof ExtSigHdr\r
 \r
 check_ext_sig:\r
    ; Check if extended signature and platform ID match\r
-   cmp   [edi].ext_sig.processor, ebx\r
+   cmp   [edi].ExtSig.ExtSigProcessor, ebx\r
    jne   @f\r
-   test  [edi].ext_sig.flags, edx\r
+   test  [edi].ExtSig.ExtSigFlags, edx\r
    jnz   load_check     ; Jif signature and platform ID match\r
 @@:\r
    ; Check if any more extended signatures exist\r
-   add   edi, sizeof ext_sig\r
+   add   edi, sizeof ExtSig\r
    loop  check_ext_sig\r
 \r
 next_microcode:\r
    ; Advance just after end of this microcode\r
    xor   eax, eax\r
-   cmp   [esi].ucode_hdr.total_size, eax\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrTotalSize, eax\r
    je    @f\r
-   add   esi, [esi].ucode_hdr.total_size\r
+   add   esi, [esi].MicrocodeHdr.MicrocodeHdrTotalSize\r
    jmp   check_address\r
 @@:\r
    add   esi, dword ptr 2048\r
@@ -240,18 +222,18 @@ advance_fixed_size:
 \r
 check_address:\r
    ; Is valid Microcode start point ?\r
-   cmp   dword ptr [esi].ucode_hdr.version, 0ffffffffh\r
+   cmp   dword ptr [esi].MicrocodeHdr.MicrocodeHdrVersion, 0ffffffffh\r
    jz    done\r
 \r
    ; Is automatic size detection ?\r
-   mov   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_size\r
+   mov   eax, [esp].LoadMicrocodeParams.MicrocodeCodeSize\r
    cmp   eax, 0ffffffffh\r
    jz    @f\r
 \r
    ; Address >= microcode region address + microcode region size?\r
-   add   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_addr\r
+   add   eax, [esp].LoadMicrocodeParams.MicrocodeCodeAddr\r
    cmp   esi, eax\r
-   jae   done        ;Jif address is outside of ucode region\r
+   jae   done        ;Jif address is outside of microcode region\r
    jmp   check_main_header\r
 \r
 @@:\r
@@ -268,7 +250,7 @@ load_check:
    rdmsr                         ; Get current microcode signature\r
 \r
    ; Verify this microcode update is not already loaded\r
-   cmp   [esi].ucode_hdr.revision, edx\r
+   cmp   [esi].MicrocodeHdr.MicrocodeHdrRevision, edx\r
    je    continue\r
 \r
 load_microcode:\r
@@ -277,7 +259,7 @@ load_microcode:
    ; ECX contains 79h (IA32_BIOS_UPDT_TRIG)\r
    ; Start microcode load with wrmsr\r
    mov   eax, esi\r
-   add   eax, sizeof ucode_hdr\r
+   add   eax, sizeof MicrocodeHdr\r
    xor   edx, edx\r
    mov   ecx, MSR_IA32_BIOS_UPDT_TRIG\r
    wrmsr\r
@@ -300,35 +282,27 @@ done:
 exit:\r
    jmp   ebp\r
 \r
-LoadUcodeDefault   ENDP\r
+LoadMicrocodeDefault   ENDP\r
 \r
 EstablishStackFsp    PROC    NEAR    PRIVATE\r
   ;\r
-  ; Save parameter pointer in edx  \r
+  ; Save parameter pointer in edx\r
   ;\r
-  mov       edx, dword ptr [esp + 4]  \r
-              \r
+  mov       edx, dword ptr [esp + 4]\r
+\r
   ;\r
   ; Enable FSP STACK\r
   ;\r
   mov       esp, PcdGet32 (PcdTemporaryRamBase)\r
-  add       esp, PcdGet32 (PcdTemporaryRamSize) \r
+  add       esp, PcdGet32 (PcdTemporaryRamSize)\r
 \r
-  push      DATA_LEN_OF_MCUD     ; Size of the data region \r
+  push      DATA_LEN_OF_MCUD     ; Size of the data region\r
   push      4455434Dh            ; Signature of the  data region 'MCUD'\r
   push      dword ptr [edx + 12] ; Code size\r
   push      dword ptr [edx + 8]  ; Code base\r
-  cmp       edx, 0               ; Is parameter pointer valid ?\r
-  jz        InvalidMicrocodeRegion\r
   push      dword ptr [edx + 4]  ; Microcode size\r
-  push      dword ptr [edx]      ; Microcode base   \r
-  jmp       @F\r
+  push      dword ptr [edx]      ; Microcode base\r
 \r
-InvalidMicrocodeRegion:\r
-  push      0                    ; Microcode size\r
-  push      0                    ; Microcode base\r
-    \r
-@@:\r
   ;\r
   ; Save API entry/exit timestamp into stack\r
   ;\r
@@ -348,7 +322,7 @@ InvalidMicrocodeRegion:
   push      0\r
 \r
   ;\r
-  ; Set ECX/EDX to the bootloader temporary memory range\r
+  ; Set ECX/EDX to the BootLoader temporary memory range\r
   ;\r
   mov       ecx, PcdGet32 (PcdTemporaryRamBase)\r
   mov       edx, ecx\r
@@ -356,7 +330,7 @@ InvalidMicrocodeRegion:
   sub       edx, PcdGet32 (PcdFspTemporaryRamSize)\r
 \r
   xor       eax, eax\r
-  \r
+\r
   RET_ESI\r
 \r
 EstablishStackFsp    ENDP\r
@@ -382,7 +356,7 @@ TempRamInitApi   PROC    NEAR    PUBLIC
   SAVE_REGS\r
 \r
   ;\r
-  ; Save timestamp into XMM4 & XMM5\r
+  ; Save timestamp into XMM6\r
   ;\r
   rdtsc\r
   SAVE_EAX\r
@@ -397,23 +371,17 @@ TempRamInitApi   PROC    NEAR    PUBLIC
   jz        NemInitExit\r
 \r
   ;\r
-  ; CPUID/DeviceID check\r
+  ; Sec Platform Init\r
   ;\r
-  mov       eax, @F\r
-  jmp       FspSelfCheck  ; Note: ESP can not be changed.\r
-@@:\r
-  cmp       eax, 0\r
-  jnz       NemInitExit\r
-\r
   CALL_MMX  SecPlatformInit\r
   cmp       eax, 0\r
   jnz       NemInitExit\r
   \r
   ; Load microcode\r
   LOAD_ESP\r
-  CALL_MMX  LoadUcode\r
-  cmp       eax, 0\r
-  jnz       NemInitExit\r
+  CALL_MMX  LoadMicrocode\r
+  SXMMN     xmm6, 3, eax            ;Save microcode return status in ECX-SLOT 3 in xmm6.\r
+  ;@note If return value eax is not 0, microcode did not load, but continue and attempt to boot.\r
 \r
   ; Call Sec CAR Init\r
   LOAD_ESP\r
@@ -424,6 +392,8 @@ TempRamInitApi   PROC    NEAR    PUBLIC
   LOAD_ESP\r
   CALL_MMX  EstablishStackFsp\r
 \r
+  LXMMN      xmm6, eax, 3  ;Restore microcode status if no CAR init error from ECX-SLOT 3 in xmm6.\r
+\r
 NemInitExit:\r
   ;\r
   ; Load EBP, EBX, ESI, EDI & ESP from XMM7 & XMM6\r
@@ -519,9 +489,10 @@ FspApiCommon   PROC C PUBLIC
   ; Verify the calling condition\r
   ;\r
   pushad\r
-  push   eax\r
+  push   [esp + 4 * 8 + 4]  ; push ApiParam\r
+  push   eax                ; push ApiIdx\r
   call   FspApiCallingCheck\r
-  add    esp, 4\r
+  add    esp, 8\r
   cmp    eax, 0\r
   jz     @F\r
   mov    dword ptr [esp + 4 * 7], eax\r
@@ -534,17 +505,27 @@ FspApiCommon   PROC C PUBLIC
   jz     @F\r
   cmp    eax, 3   ; FspMemoryInit API\r
   jz     @F\r
-  jmp    Pei2LoaderSwitchStack\r
 \r
-@@:  \r
+  call   AsmGetFspInfoHeader\r
+  jmp    Loader2PeiSwitchStack\r
+\r
+@@:\r
   ;\r
   ; FspInit and FspMemoryInit APIs, setup the initial stack frame\r
-  ;  \r
+  ;\r
   \r
   ;\r
-  ; Store the address in FSP which will return control to the BL\r
+  ; Place holder to store the FspInfoHeader pointer\r
   ;\r
-  push   offset exit\r
+  push   eax\r
+\r
+  ;\r
+  ; Update the FspInfoHeader pointer\r
+  ;\r
+  push   eax\r
+  call   AsmGetFspInfoHeader\r
+  mov    [esp + 4], eax\r
+  pop    eax\r
 \r
   ;\r
   ; Create a Task Frame in the stack for the Boot Loader\r
@@ -555,7 +536,7 @@ FspApiCommon   PROC C PUBLIC
 \r
   ; Reserve 8 bytes for IDT save/restore\r
   sub     esp, 8\r
-  sidt    fword ptr [esp]  \r
+  sidt    fword ptr [esp]\r
 \r
   ;\r
   ; Setup new FSP stack\r
@@ -571,14 +552,14 @@ FspApiCommon   PROC C PUBLIC
   push    eax\r
   \r
   ;\r
-  ; Pass the bootloader stack to SecStartup\r
+  ; Pass the BootLoader stack to SecStartup\r
   ;\r
   push    edi\r
 \r
   ;\r
   ; Pass entry point of the PEI core\r
   ;\r
-  call    GetFspBaseAddress\r
+  call    AsmGetFspBaseAddress\r
   mov     edi, eax\r
   add     edi, PcdGet32 (PcdFspAreaSize) \r
   sub     edi, 20h\r
@@ -592,7 +573,7 @@ FspApiCommon   PROC C PUBLIC
   ; PcdFspAreaBaseAddress are the same. For FSP with mulitple FVs,\r
   ; they are different. The code below can handle both cases.\r
   ;\r
-  call    GetFspBaseAddress\r
+  call    AsmGetFspBaseAddress\r
   mov     edi, eax\r
   call    GetBootFirmwareVolumeOffset\r
   add     eax, edi\r
@@ -611,8 +592,8 @@ FspApiCommon   PROC C PUBLIC
   ; Pass Control into the PEI Core\r
   ;\r
   call    SecStartup\r
-\r
-exit:  \r
+  add     esp, 4\r
+exit:\r
   ret\r
 \r
 FspApiCommon   ENDP\r