]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/FspSecCore/X64/Stack.nasm
IntelFsp2Pkg: Adopt FSP 2.4 MultiPhase functions.
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / 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 ;------------------------------------------------------------------------------
15 ; VOID
16 ; EFIAPI
17 ; SecSwitchStack (
18 ; UINT64 TemporaryMemoryBase,
19 ; UINT64 PermanentMemoryBase
20 ; );
21 ;------------------------------------------------------------------------------
22 global ASM_PFX(SecSwitchStack)
23 ASM_PFX(SecSwitchStack):
24 ;
25 ; Save four register: rax, rbx, rcx, rdx
26 ;
27 push rax
28 push rbx
29 push rcx
30 push rdx
31
32 ;
33 ; !!CAUTION!! this function address's is pushed into stack after
34 ; migration of whole temporary memory, so need save it to permanent
35 ; memory at first!
36 ;
37
38 mov rbx, rcx ; Save the first parameter
39 mov rcx, rdx ; Save the second parameter
40
41 ;
42 ; Save this function's return address into permanent memory at first.
43 ; Then, Fixup the esp point to permanent memory
44 ;
45 mov rax, rsp
46 sub rax, rbx
47 add rax, rcx
48 mov rdx, qword [rsp] ; copy pushed register's value to permanent memory
49 mov qword [rax], rdx
50 mov rdx, qword [rsp + 8]
51 mov qword [rax + 8], rdx
52 mov rdx, qword [rsp + 16]
53 mov qword [rax + 16], rdx
54 mov rdx, qword [rsp + 24]
55 mov qword [rax + 24], rdx
56 mov rdx, qword [rsp + 32] ; Update this function's return address into permanent memory
57 mov qword [rax + 32], rdx
58 mov rsp, rax ; From now, rsp is pointed to permanent memory
59
60 ;
61 ; Fixup the rbp point to permanent memory
62 ;
63 mov rax, rbp
64 sub rax, rbx
65 add rax, rcx
66 mov rbp, rax ; From now, rbp is pointed to permanent memory
67
68 pop rdx
69 pop rcx
70 pop rbx
71 pop rax
72 ret
73