]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
IntelFsp2Pkg: FSP can utilize bootloader stack
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / Ia32 / FspApiEntryM.nasm
index 9c9a84db0a3e1aa4a9663d587739b6d1a8d0455d..916ad4ff0d7b32a0e0d77920c79c438b4d8857f4 100644 (file)
@@ -1,7 +1,7 @@
 ;; @file\r
 ;  Provide FSP API entry points.\r
 ;\r
-; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2016 - 2019, 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
@@ -19,6 +19,7 @@
 extern   ASM_PFX(PcdGet32(PcdTemporaryRamBase))\r
 extern   ASM_PFX(PcdGet32(PcdTemporaryRamSize))\r
 extern   ASM_PFX(PcdGet32(PcdFspTemporaryRamSize))\r
+extern   ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))\r
 \r
 struc FSPM_UPD_COMMON\r
     ; FSP_UPD_HEADER {\r
@@ -128,15 +129,55 @@ ASM_PFX(FspApiCommonContinue):
   add    edx, [eax + FSP_HEADER_CFGREG_OFFSET]\r
   pop    eax\r
 \r
-  FspStackSetup:\r
+FspStackSetup:\r
+  ;\r
+  ; StackBase = temp memory base, StackSize = temp memory size\r
+  ;\r
   mov    edi, [edx + FSPM_UPD_COMMON.StackBase]\r
   mov    ecx, [edx + FSPM_UPD_COMMON.StackSize]\r
+\r
+  ;\r
+  ; Keep using bootloader stack if heap size % is 0\r
+  ;\r
+  mov    bl, BYTE [ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))]\r
+  cmp    bl, 0\r
+  jz     SkipStackSwitch\r
+\r
+  ;\r
+  ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0\r
+  ;\r
   add    edi, ecx\r
   ;\r
-  ; Setup new FSP stack\r
+  ; Switch to new FSP stack\r
   ;\r
-  xchg    edi, esp                                ; Exchange edi and esp, edi will be assigned to the current esp pointer and esp will be Stack base + Stack size\r
-  mov     ebx, esp                                ; Put Stack base + Stack size in ebx\r
+  xchg   edi, esp                                ; Exchange edi and esp, edi will be assigned to the current esp pointer and esp will be Stack base + Stack size\r
+\r
+SkipStackSwitch:\r
+  ;\r
+  ; If heap size % is 0:\r
+  ;   EDI is FSPM_UPD_COMMON.StackBase and will hold ESP later (boot loader stack pointer)\r
+  ;   ECX is FSPM_UPD_COMMON.StackSize\r
+  ;   ESP is boot loader stack pointer (no stack switch)\r
+  ;   BL  is 0 to indicate no stack switch (EBX will hold FSPM_UPD_COMMON.StackBase later)\r
+  ;\r
+  ; If heap size % is not 0\r
+  ;   EDI is boot loader stack pointer\r
+  ;   ECX is FSPM_UPD_COMMON.StackSize\r
+  ;   ESP is new stack (FSPM_UPD_COMMON.StackBase + FSPM_UPD_COMMON.StackSize)\r
+  ;   BL  is NOT 0 to indicate stack has switched\r
+  ;\r
+  cmp    bl, 0\r
+  jnz    StackHasBeenSwitched\r
+\r
+  mov    ebx, edi                                ; Put FSPM_UPD_COMMON.StackBase to ebx as temp memory base\r
+  mov    edi, esp                                ; Put boot loader stack pointer to edi\r
+  jmp    StackSetupDone\r
+\r
+StackHasBeenSwitched:\r
+  mov    ebx, esp                                ; Put Stack base + Stack size in ebx\r
+  sub    ebx, ecx                                ; Stack base + Stack size - Stack size as temp memory base\r
+\r
+StackSetupDone:\r
 \r
   ;\r
   ; Pass the API Idx to SecStartup\r
@@ -170,7 +211,6 @@ ASM_PFX(FspApiCommonContinue):
   ;\r
   ; Pass stack base and size into the PEI Core\r
   ;\r
-  sub     ebx, ecx            ; Stack base + Stack size - Stack size\r
   push    ebx\r
   push    ecx\r
 \r