]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Sec/StackX64.asm
UefiCpuPkg: Remove double \r
[mirror_edk2.git] / Nt32Pkg / Sec / StackX64.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; Stack.asm
9 ;
10 ; Abstract:
11 ;
12 ; Switch the stack from temporary memory to permenent memory.
13 ;
14 ;------------------------------------------------------------------------------
15
16 .code
17
18 ;------------------------------------------------------------------------------
19 ; VOID
20 ; EFIAPI
21 ; SecSwitchStack (
22 ; UINT32 TemporaryMemoryBase,
23 ; UINT32 PermenentMemoryBase
24 ; );
25 ;------------------------------------------------------------------------------
26 SecSwitchStack PROC
27 mov [rsp + 08h], rcx
28 mov [rsp + 10h], rdx
29
30 ;
31 ; Save three register: eax, ebx, ecx
32 ;
33 push rax
34 push rbx
35 push rcx
36 push rdx
37
38 ;
39 ; !!CAUTION!! this function address's is pushed into stack after
40 ; migration of whole temporary memory, so need save it to permenent
41 ; memory at first!
42 ;
43
44 mov rbx, [rsp + 28h] ; Save the first parameter
45 mov rcx, [rsp + 30h] ; Save the second parameter
46
47 ;
48 ; Save this function's return address into permenent memory at first.
49 ; Then, Fixup the esp point to permenent memory
50 ;
51 mov rax, rsp
52 sub rax, rbx
53 add rax, rcx
54 mov rdx, qword ptr [rsp] ; copy pushed register's value to permenent memory
55 mov qword ptr [rax], rdx
56 mov rdx, qword ptr [rsp + 8]
57 mov qword ptr [rax + 8], rdx
58 mov rdx, qword ptr [rsp + 10h]
59 mov qword ptr [rax + 10h], rdx
60 mov rdx, qword ptr [rsp + 18h]
61 mov qword ptr [rax + 18h], rdx
62 mov rdx, qword ptr [rsp + 20h] ; Update this function's return address into permenent memory
63 mov qword ptr [rax + 20h], rdx
64 mov rsp, rax ; From now, esp is pointed to permenent memory
65
66 ;
67 ; Fixup the ebp point to permenent memory
68 ;
69 mov rax, rbp
70 sub rax, rbx
71 add rax, rcx
72 mov rbp, rax ; From now, ebp is pointed to permenent memory
73
74 pop rdx
75 pop rcx
76 pop rbx
77 pop rax
78 ret
79 SecSwitchStack ENDP
80
81 ;------------------------------------------------------------------------------
82 ; VOID
83 ; EFIAPI
84 ; PeiSwitchStacks (
85 ; IN SWITCH_STACK_ENTRY_POINT EntryPoint,
86 ; IN VOID *Context1, OPTIONAL
87 ; IN VOID *Context2, OPTIONAL
88 ; IN VOID *Context3, OPTIONAL
89 ; IN VOID *NewStack
90 ; )
91 ;------------------------------------------------------------------------------
92 PeiSwitchStacks PROC
93 mov rax, rcx
94 mov rcx, rdx
95 mov rdx, r8
96 mov r8, r9
97 mov rsp, [rsp + 28h]
98 sub rsp, 20h
99 call rax
100 jmp $
101 ret
102 PeiSwitchStacks ENDP
103
104 END