1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
8 ; Switch the stack from temporary memory to permanent memory.
10 ;------------------------------------------------------------------------------
14 ;------------------------------------------------------------------------------
18 ; UINT64 TemporaryMemoryBase,
19 ; UINT64 PermanentMemoryBase
21 ;------------------------------------------------------------------------------
22 global ASM_PFX(SecSwitchStack)
23 ASM_PFX(SecSwitchStack):
25 ; Save four register: rax, rbx, rcx, rdx
33 ; !!CAUTION!! this function address's is pushed into stack after
34 ; migration of whole temporary memory, so need save it to permanent
38 mov rbx, rcx ; Save the first parameter
39 mov rcx, rdx ; Save the second parameter
42 ; Save this function's return address into permanent memory at first.
43 ; Then, Fixup the esp point to permanent memory
48 mov rdx, qword [rsp] ; copy pushed register's value to permanent memory
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
61 ; Fixup the rbp point to permanent memory
66 mov rbp, rax ; From now, rbp is pointed to permanent memory