]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspPkg/FspSecCore/Ia32/FspApiEntry.asm
rename XXXDflt to XXXDefault (expand for better readability)
[mirror_edk2.git] / IntelFspPkg / FspSecCore / Ia32 / FspApiEntry.asm
index 8ad9744ab43935d25b8a3a83dcb4733b1da86735..afe995c8bd011d1980047c5ae4df8b4eb6e639f5 100644 (file)
@@ -1,6 +1,7 @@
-;------------------------------------------------------------------------------\r
+;; @file\r
+;  Provide FSP API entry points.\r
 ;\r
-; Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -8,12 +9,7 @@
 ;\r
 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-;\r
-; Abstract:\r
-;\r
-;   Provide FSP API entry points.\r
-;\r
-;------------------------------------------------------------------------------\r
+;;\r
 \r
     .586p\r
     .model  flat,C\r
@@ -29,11 +25,12 @@ INCLUDE    UcodeLoad.inc
 EXTERN   PcdGet32(PcdTemporaryRamBase):DWORD\r
 EXTERN   PcdGet32(PcdTemporaryRamSize):DWORD\r
 EXTERN   PcdGet32(PcdFspTemporaryRamSize):DWORD\r
+EXTERN   PcdGet32(PcdFspAreaSize):DWORD\r
 \r
 ;\r
 ; Following functions will be provided in C\r
 ;\r
-EXTERN   FspImageSizeOffset:DWORD\r
+\r
 EXTERN   SecStartup:PROC\r
 EXTERN   FspApiCallingCheck:PROC\r
 \r
@@ -42,11 +39,11 @@ EXTERN   FspApiCallingCheck:PROC
 ;\r
 EXTERN   GetFspBaseAddress:PROC\r
 EXTERN   GetBootFirmwareVolumeOffset:PROC\r
-EXTERN   PlatformTempRamInit:PROC\r
 EXTERN   Pei2LoaderSwitchStack:PROC\r
-EXTERN   FspSelfCheck(FspSelfCheckDflt):PROC\r
-EXTERN   PlatformBasicInit(PlatformBasicInitDflt):PROC\r
-EXTERN   LoadUcode(LoadUcodeDflt):PROC\r
+EXTERN   FspSelfCheck(FspSelfCheckDefault):PROC\r
+EXTERN   LoadUcode(LoadUcodeDefault):PROC\r
+EXTERN   SecPlatformInit(SecPlatformInitDefault):PROC\r
+EXTERN   SecCarInit:PROC\r
 \r
 ;\r
 ; Define the data length that we saved on the stack top\r
@@ -55,8 +52,37 @@ DATA_LEN_OF_PER0         EQU   18h
 DATA_LEN_OF_MCUD         EQU   18h\r
 DATA_LEN_AT_STACK_TOP    EQU   (DATA_LEN_OF_PER0 + DATA_LEN_OF_MCUD + 4)\r
 \r
+;\r
+; Define SSE macros\r
+;\r
+LOAD_MMX_EXT MACRO   ReturnAddress, MmxRegister\r
+  mov     esi, ReturnAddress\r
+  movd    MmxRegister, esi              ; save ReturnAddress into MM7  \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
+  jmp     RoutineLabel\r
+ReturnAddress:\r
+ENDM\r
+\r
+RET_ESI_EXT  MACRO   MmxRegister\r
+  movd    esi, MmxRegister              ; restore ESP from MM7\r
+  jmp     esi\r
+ENDM\r
+\r
+CALL_MMX MACRO   RoutineLabel\r
+         CALL_MMX_EXT  RoutineLabel, mm7\r
+ENDM\r
+\r
+RET_ESI  MACRO\r
+         RET_ESI_EXT   mm7  \r
+ENDM\r
+\r
 ;------------------------------------------------------------------------------\r
-FspSelfCheckDflt PROC NEAR PUBLIC\r
+FspSelfCheckDefault PROC NEAR PUBLIC\r
    ; Inputs:\r
    ;   eax -> Return address\r
    ; Outputs:\r
@@ -71,10 +97,10 @@ FspSelfCheckDflt PROC NEAR PUBLIC
    xor   eax, eax\r
 exit:\r
    jmp   ebp\r
-FspSelfCheckDflt   ENDP\r
+FspSelfCheckDefault   ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
-PlatformBasicInitDflt PROC NEAR PUBLIC\r
+SecPlatformInitDefault PROC NEAR PUBLIC\r
    ; Inputs:\r
    ;   eax -> Return address\r
    ; Outputs:\r
@@ -89,10 +115,10 @@ PlatformBasicInitDflt PROC NEAR PUBLIC
    xor   eax, eax\r
 exit:\r
    jmp   ebp\r
-PlatformBasicInitDflt   ENDP\r
+SecPlatformInitDefault   ENDP\r
 \r
 ;------------------------------------------------------------------------------\r
-LoadUcodeDflt   PROC  NEAR PUBLIC\r
+LoadUcodeDefault   PROC  NEAR PUBLIC\r
    ; Inputs:\r
    ;   esp -> LOAD_UCODE_PARAMS pointer\r
    ; Register Usage:\r
@@ -106,7 +132,7 @@ LoadUcodeDflt   PROC  NEAR PUBLIC
    ;\r
    ;\r
    ; Save return address to EBP\r
-   mov    ebp, eax\r
+   movd   ebp, mm7\r
 \r
    cmp    esp, 0\r
    jz     paramerror\r
@@ -214,16 +240,21 @@ advance_fixed_size:
 \r
 check_address:\r
    ; Is valid Microcode start point ?\r
-   cmp   dword ptr [esi], 0ffffffffh\r
+   cmp   dword ptr [esi].ucode_hdr.version, 0ffffffffh\r
    jz    done\r
 \r
+   ; Is automatic size detection ?\r
+   mov   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_size\r
+   cmp   eax, 0ffffffffh\r
+   jz    @f\r
+\r
    ; Address >= microcode region address + microcode region size?\r
-   mov   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_addr\r
-   add   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_size\r
+   add   eax, [esp].LOAD_UCODE_PARAMS.ucode_code_addr\r
    cmp   esi, eax\r
    jae   done        ;Jif address is outside of ucode region\r
    jmp   check_main_header\r
 \r
+@@:\r
 load_check:\r
    ; Get the revision of the current microcode update loaded\r
    mov   ecx, MSR_IA32_BIOS_SIGN_ID\r
@@ -269,7 +300,67 @@ done:
 exit:\r
    jmp   ebp\r
 \r
-LoadUcodeDflt   ENDP\r
+LoadUcodeDefault   ENDP\r
+\r
+EstablishStackFsp    PROC    NEAR    PRIVATE\r
+  ;\r
+  ; Save parameter pointer in edx  \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
+\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
+\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
+  push      DATA_LEN_OF_PER0     ; Size of the data region \r
+  push      30524550h            ; Signature of the  data region 'PER0'\r
+  LOAD_EDX\r
+  push      edx\r
+  LOAD_EAX\r
+  push      eax\r
+  rdtsc\r
+  push      edx\r
+  push      eax\r
+\r
+  ;\r
+  ; Terminator for the data on stack\r
+  ; \r
+  push      0\r
+\r
+  ;\r
+  ; Set ECX/EDX to the bootloader temporary memory range\r
+  ;\r
+  mov       ecx, PcdGet32 (PcdTemporaryRamBase)\r
+  mov       edx, ecx\r
+  add       edx, PcdGet32 (PcdTemporaryRamSize)\r
+  sub       edx, PcdGet32 (PcdFspTemporaryRamSize)\r
+\r
+  xor       eax, eax\r
+  \r
+  RET_ESI\r
+\r
+EstablishStackFsp    ENDP\r
+\r
 \r
 ;----------------------------------------------------------------------------\r
 ; TempRamInit API\r
@@ -314,82 +405,24 @@ TempRamInitApi   PROC    NEAR    PUBLIC
   cmp       eax, 0\r
   jnz       NemInitExit\r
 \r
-  ;\r
-  ; Platform Basic Init.\r
-  ;\r
-  mov       eax, @F\r
-  jmp       PlatformBasicInit\r
-@@:\r
+  CALL_MMX  SecPlatformInit\r
   cmp       eax, 0\r
   jnz       NemInitExit\r
-\r
-  ;\r
+  \r
   ; Load microcode\r
-  ;\r
-  mov       eax, @F\r
-  add       esp, 4\r
-  jmp       LoadUcode\r
-@@:\r
   LOAD_ESP\r
+  CALL_MMX  LoadUcode\r
   cmp       eax, 0\r
   jnz       NemInitExit\r
 \r
-  ;\r
-  ; Call platform NEM init\r
-  ;\r
-  mov       eax, @F\r
-  add       esp, 4\r
-  jmp       PlatformTempRamInit\r
-@@:\r
+  ; Call Sec CAR Init\r
   LOAD_ESP\r
+  CALL_MMX  SecCarInit\r
   cmp       eax, 0\r
   jnz       NemInitExit\r
 \r
-  ;\r
-  ; Save parameter pointer in edx\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
-\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 +  4] ; Microcode size\r
-  push      dword ptr [edx +  0] ; Microcode base\r
-  push      dword ptr [edx + 12] ; Code size\r
-  push      dword ptr [edx + 8]  ; Code base\r
-\r
-  ;\r
-  ; Save API entry/exit timestamp into stack\r
-  ;\r
-  push      DATA_LEN_OF_PER0     ; Size of the data region\r
-  push      30524550h            ; Signature of the  data region 'PER0'\r
-  rdtsc\r
-  push      edx\r
-  push      eax\r
-  LOAD_EAX\r
-  LOAD_EDX\r
-  push      edx\r
-  push      eax\r
-\r
-  ;\r
-  ; Terminator for the data on stack\r
-  ;\r
-  push      0\r
-\r
-  ;\r
-  ; Set ECX/EDX to the bootloader temporary memory range\r
-  ;\r
-  mov       ecx, PcdGet32(PcdTemporaryRamBase)\r
-  mov       edx, ecx\r
-  add       edx, PcdGet32(PcdTemporaryRamSize)\r
-  sub       edx, PcdGet32(PcdFspTemporaryRamSize)\r
-\r
-  xor       eax, eax\r
+  LOAD_ESP\r
+  CALL_MMX  EstablishStackFsp\r
 \r
 NemInitExit:\r
   ;\r
@@ -408,31 +441,106 @@ TempRamInitApi   ENDP
 ;\r
 ;----------------------------------------------------------------------------\r
 FspInitApi   PROC    NEAR    PUBLIC\r
+  mov    eax,  1\r
+  jmp    FspApiCommon\r
+  FspInitApi   ENDP\r
+\r
+;----------------------------------------------------------------------------\r
+; NotifyPhase API\r
+;\r
+; This FSP API will notify the FSP about the different phases in the boot\r
+; process\r
+;\r
+;----------------------------------------------------------------------------\r
+NotifyPhaseApi   PROC C PUBLIC\r
+  mov    eax,  2\r
+  jmp    FspApiCommon\r
+NotifyPhaseApi   ENDP\r
+\r
+;----------------------------------------------------------------------------\r
+; FspMemoryInit API\r
+;\r
+; This FSP API is called after TempRamInit and initializes the memory.\r
+;\r
+;----------------------------------------------------------------------------\r
+FspMemoryInitApi   PROC    NEAR    PUBLIC\r
+  mov    eax,  3\r
+  jmp    FspApiCommon\r
+FspMemoryInitApi   ENDP\r
+\r
+\r
+;----------------------------------------------------------------------------\r
+; TempRamExitApi API\r
+;\r
+; This API tears down temporary RAM\r
+;\r
+;----------------------------------------------------------------------------\r
+TempRamExitApi   PROC C PUBLIC\r
+  mov    eax,  4\r
+  jmp    FspApiCommon\r
+TempRamExitApi   ENDP\r
+\r
+\r
+;----------------------------------------------------------------------------\r
+; FspSiliconInit API\r
+;\r
+; This FSP API initializes the CPU and the chipset including the IO\r
+; controllers in the chipset to enable normal operation of these devices.\r
+;\r
+;----------------------------------------------------------------------------\r
+FspSiliconInitApi   PROC C PUBLIC\r
+  mov    eax,  5\r
+  jmp    FspApiCommon\r
+FspSiliconInitApi   ENDP\r
+\r
+;----------------------------------------------------------------------------\r
+; FspApiCommon API\r
+;\r
+; This is the FSP API common entry point to resume the FSP execution\r
+;\r
+;----------------------------------------------------------------------------\r
+FspApiCommon   PROC C PUBLIC\r
   ;\r
-  ; Stack must be ready\r
+  ; EAX holds the API index\r
+  ;\r
+\r
   ;\r
-  push   087654321h\r
-  pop    eax\r
-  cmp    eax, 087654321h\r
+  ; Stack must be ready\r
+  ;  \r
+  push   eax\r
+  add    esp, 4\r
+  cmp    eax, dword ptr [esp - 4]\r
   jz     @F\r
   mov    eax, 080000003h\r
   jmp    exit\r
 \r
 @@:\r
   ;\r
-  ; Additional check\r
+  ; Verify the calling condition\r
   ;\r
   pushad\r
-  push   1\r
+  push   eax\r
   call   FspApiCallingCheck\r
   add    esp, 4\r
-  mov    dword ptr [esp + 4 * 7],  eax\r
-  popad\r
   cmp    eax, 0\r
   jz     @F\r
-  jmp    exit\r
+  mov    dword ptr [esp + 4 * 7], eax\r
+  popad\r
+  ret\r
 \r
 @@:\r
+  popad\r
+  cmp    eax, 1   ; FspInit API\r
+  jz     @F\r
+  cmp    eax, 3   ; FspMemoryInit API\r
+  jz     @F\r
+  jmp    Pei2LoaderSwitchStack\r
+\r
+@@:  \r
+  ;\r
+  ; FspInit and FspMemoryInit APIs, setup the initial stack frame\r
+  ;  \r
+  \r
   ;\r
   ; Store the address in FSP which will return control to the BL\r
   ;\r
@@ -447,30 +555,34 @@ FspInitApi   PROC    NEAR    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
   ;\r
-  mov     eax, esp\r
+  mov     edi, esp\r
   mov     esp, PcdGet32(PcdTemporaryRamBase)\r
   add     esp, PcdGet32(PcdTemporaryRamSize)\r
   sub     esp, (DATA_LEN_AT_STACK_TOP + 40h)\r
 \r
   ;\r
-  ; Save the bootloader's stack pointer\r
+  ; Pass the API Idx to SecStartup\r
   ;\r
   push    eax\r
+  \r
+  ;\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
-  mov     edi, FspImageSizeOffset\r
-  mov     edi, DWORD PTR [eax + edi]\r
-  add     edi, eax\r
+  mov     edi, eax\r
+  add     edi, PcdGet32 (PcdFspAreaSize) \r
   sub     edi, 20h\r
-  add     eax, DWORD PTR [edi]\r
+  add     eax, DWORD PTR ds:[edi]\r
   push    eax\r
 \r
   ;\r
@@ -500,53 +612,9 @@ FspInitApi   PROC    NEAR    PUBLIC
   ;\r
   call    SecStartup\r
 \r
-exit:\r
+exit:  \r
   ret\r
 \r
-FspInitApi   ENDP\r
-\r
-;----------------------------------------------------------------------------\r
-; NotifyPhase API\r
-;\r
-; This FSP API will notify the FSP about the different phases in the boot\r
-; process\r
-;\r
-;----------------------------------------------------------------------------\r
-NotifyPhaseApi   PROC C PUBLIC\r
-  ;\r
-  ; Stack must be ready\r
-  ;\r
-  push   087654321h\r
-  pop    eax\r
-  cmp    eax, 087654321h\r
-  jz     @F\r
-  mov    eax, 080000003h\r
-  jmp    err_exit\r
-\r
-@@:\r
-  ;\r
-  ; Verify the calling condition\r
-  ;\r
-  pushad\r
-  push   2\r
-  call   FspApiCallingCheck\r
-  add    esp, 4\r
-  mov    dword ptr [esp + 4 * 7],  eax\r
-  popad\r
-\r
-  cmp    eax, 0\r
-  jz     @F\r
-\r
-  ;\r
-  ; Error return\r
-  ;\r
-err_exit:\r
-  ret\r
-\r
-@@:\r
-  jmp    Pei2LoaderSwitchStack\r
-\r
-NotifyPhaseApi   ENDP\r
-\r
+FspApiCommon   ENDP\r
 \r
 END\r