]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFsp2Pkg: BaseFspSwitchStackLib Support for X64
authorKuo, Ted <ted.kuo@intel.com>
Mon, 14 Mar 2022 02:48:00 +0000 (10:48 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 17 Mar 2022 13:23:28 +0000 (13:23 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3832
Add BaseFspSwitchStackLib Support for X64.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
IntelFsp2Pkg/Include/PushPopRegsNasm.inc [new file with mode: 0644]
IntelFsp2Pkg/Library/BaseFspSwitchStackLib/BaseFspSwitchStackLib.inf
IntelFsp2Pkg/Library/BaseFspSwitchStackLib/FspSwitchStackLib.c
IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm [new file with mode: 0644]

diff --git a/IntelFsp2Pkg/Include/PushPopRegsNasm.inc b/IntelFsp2Pkg/Include/PushPopRegsNasm.inc
new file mode 100644 (file)
index 0000000..ec10394
--- /dev/null
@@ -0,0 +1,67 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+; Abstract:\r
+;\r
+;   Provide macro to push/pop registers in X64\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+;-----------------------------------------------------------------------------\r
+;  Macro:        PUSHA_64\r
+;\r
+;  Description:  Saves all registers on stack\r
+;\r
+;  Input:        None\r
+;\r
+;  Output:       None\r
+;-----------------------------------------------------------------------------\r
+%macro PUSHA_64   0\r
+  push    r8\r
+  push    r9\r
+  push    r10\r
+  push    r11\r
+  push    r12\r
+  push    r13\r
+  push    r14\r
+  push    r15\r
+  push    rax\r
+  push    rcx\r
+  push    rdx\r
+  push    rbx\r
+  push    rsp\r
+  push    rbp\r
+  push    rsi\r
+  push    rdi\r
+%endmacro\r
+\r
+;-----------------------------------------------------------------------------\r
+;  Macro:        POPA_64\r
+;\r
+;  Description:  Restores all registers from stack\r
+;\r
+;  Input:        None\r
+;\r
+;  Output:       None\r
+;-----------------------------------------------------------------------------\r
+%macro POPA_64   0\r
+  pop    rdi\r
+  pop    rsi\r
+  pop    rbp\r
+  pop    rsp\r
+  pop    rbx\r
+  pop    rdx\r
+  pop    rcx\r
+  pop    rax\r
+  pop    r15\r
+  pop    r14\r
+  pop    r13\r
+  pop    r12\r
+  pop    r11\r
+  pop    r10\r
+  pop    r9\r
+  pop    r8\r
+%endmacro\r
+\r
index 3dcf3b95983d6c0abb93714abc1033d5e5f64dc8..6909aec651b0a1fd6e78f65b1b857fcb9dc6db88 100644 (file)
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = FspSwitchStackLib\r
 \r
-[Sources.IA32]\r
+[Sources]\r
   FspSwitchStackLib.c\r
 \r
 [Sources.IA32]\r
   Ia32/Stack.nasm\r
 \r
+[Sources.X64]\r
+  X64/Stack.nasm\r
+\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   IntelFsp2Pkg/IntelFsp2Pkg.dec\r
index 618c25c3b028ceefd4b20b6a950e99dff72776ca..dae4e27172382ecf80f524b3e1d646e167fd4def 100644 (file)
 \r
 \r
 **/\r
-UINT32\r
+UINTN\r
 SwapStack (\r
-  IN  UINT32  NewStack\r
+  IN  UINTN  NewStack\r
   )\r
 {\r
   FSP_GLOBAL_DATA  *FspData;\r
-  UINT32           OldStack;\r
+  UINT           OldStack;\r
 \r
   FspData            = GetFspGlobalDataPointer ();\r
   OldStack           = FspData->CoreStack;\r
-  FspData->CoreStack = NewStack;\r
+  FspData->CoreStack = (UINTN) NewStack;\r
   return OldStack;\r
 }\r
diff --git a/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm b/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
new file mode 100644 (file)
index 0000000..bd36fe4
--- /dev/null
@@ -0,0 +1,72 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+; Abstract:\r
+;\r
+;   Switch the stack from temporary memory to permanent memory.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    SECTION .text\r
+\r
+%include    "PushPopRegsNasm.inc"\r
+\r
+extern ASM_PFX(SwapStack)\r
+\r
+;------------------------------------------------------------------------------\r
+; UINT32\r
+; EFIAPI\r
+; Pei2LoaderSwitchStack (\r
+;   VOID\r
+;   )\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(Pei2LoaderSwitchStack)\r
+ASM_PFX(Pei2LoaderSwitchStack):\r
+    xor     rax, rax\r
+    jmp     ASM_PFX(FspSwitchStack)\r
+\r
+;------------------------------------------------------------------------------\r
+; UINT32\r
+; EFIAPI\r
+; Loader2PeiSwitchStack (\r
+;   VOID\r
+;   )\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(Loader2PeiSwitchStack)\r
+ASM_PFX(Loader2PeiSwitchStack):\r
+    jmp     ASM_PFX(FspSwitchStack)\r
+\r
+;------------------------------------------------------------------------------\r
+; UINT32\r
+; EFIAPI\r
+; FspSwitchStack (\r
+;   VOID\r
+;   )\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(FspSwitchStack)\r
+ASM_PFX(FspSwitchStack):\r
+    ; Save current contexts\r
+    push    rdx     ; ApiParam2\r
+    push    rcx     ; ApiParam1\r
+    push    rax     ; FspInfoHeader\r
+    pushfq\r
+    cli\r
+    PUSHA_64\r
+    sub     rsp, 16\r
+    sidt    [rsp]\r
+\r
+    ; Load new stack\r
+    mov     rcx, rsp\r
+    call    ASM_PFX(SwapStack)\r
+    mov     rsp, rax\r
+\r
+    ; Restore previous contexts\r
+    lidt    [rsp]\r
+    add     rsp, 16\r
+    POPA_64\r
+    popfq\r
+    add     rsp, 24 ; FspInfoHeader + ApiParam[2]\r
+    ret\r
+\r