]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
1ea1220608ef51a91c33ad2cc341a48b74e2dd56
[mirror_edk2.git] / IntelFsp2Pkg / Library / BaseFspSwitchStackLib / X64 / Stack.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Abstract:
7 ;
8 ; Switch the stack from temporary memory to permanent memory.
9 ;
10 ;------------------------------------------------------------------------------
11
12 SECTION .text
13
14 %include "PushPopRegsNasm.inc"
15
16 extern ASM_PFX(SwapStack)
17
18 ;------------------------------------------------------------------------------
19 ; UINT32
20 ; EFIAPI
21 ; Pei2LoaderSwitchStack (
22 ; VOID
23 ; )
24 ;------------------------------------------------------------------------------
25 global ASM_PFX(Pei2LoaderSwitchStack)
26 ASM_PFX(Pei2LoaderSwitchStack):
27 xor rax, rax
28 jmp ASM_PFX(FspSwitchStack)
29
30 ;------------------------------------------------------------------------------
31 ; UINT32
32 ; EFIAPI
33 ; Loader2PeiSwitchStack (
34 ; VOID
35 ; )
36 ;------------------------------------------------------------------------------
37 global ASM_PFX(Loader2PeiSwitchStack)
38 ASM_PFX(Loader2PeiSwitchStack):
39 jmp ASM_PFX(FspSwitchStack)
40
41 ;------------------------------------------------------------------------------
42 ; UINT32
43 ; EFIAPI
44 ; FspSwitchStack (
45 ; VOID
46 ; )
47 ;------------------------------------------------------------------------------
48 global ASM_PFX(FspSwitchStack)
49 ASM_PFX(FspSwitchStack):
50 ; Save current contexts. The format must align with CONTEXT_STACK_64.
51 push rdx ; Reserved QWORD for stack alignment
52 push rdx ; ApiParam2
53 push rcx ; ApiParam1
54 push rax ; FspInfoHeader
55 pushfq
56 cli
57 PUSHA_64
58 sub rsp, 16
59 sidt [rsp]
60
61 ; Load new stack
62 mov rcx, rsp
63 call ASM_PFX(SwapStack)
64 mov rsp, rax
65
66 ; Restore previous contexts
67 lidt [rsp]
68 add rsp, 16
69 POPA_64
70 popfq
71 add rsp, 32 ; FspInfoHeader + ApiParam[2] + Reserved QWORD
72 ret
73