]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Sec/StackX64.asm
We enabled X64 native version NT32, and made it works on Windows 7 X64 OS.
[mirror_edk2.git] / Nt32Pkg / Sec / StackX64.asm
CommitLineData
f66a43b2
JM
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
4; This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Module Name:\r
13;\r
14; Stack.asm\r
15;\r
16; Abstract:\r
17;\r
18; Switch the stack from temporary memory to permenent memory.\r
19;\r
20;------------------------------------------------------------------------------\r
21\r
22 .code\r
23 \r
24;------------------------------------------------------------------------------\r
25; VOID\r
26; EFIAPI\r
27; SecSwitchStack (\r
28; UINT32 TemporaryMemoryBase,\r
29; UINT32 PermenentMemoryBase\r
30; );\r
31;------------------------------------------------------------------------------ \r
32SecSwitchStack PROC\r
33 mov [rsp + 08h], rcx\r
34 mov [rsp + 10h], rdx\r
35\r
36 ;\r
37 ; Save three register: eax, ebx, ecx\r
38 ;\r
39 push rax\r
40 push rbx\r
41 push rcx\r
42 push rdx\r
43 \r
44 ;\r
45 ; !!CAUTION!! this function address's is pushed into stack after\r
46 ; migration of whole temporary memory, so need save it to permenent\r
47 ; memory at first!\r
48 ;\r
49 \r
50 mov rbx, [rsp + 28h] ; Save the first parameter\r
51 mov rcx, [rsp + 30h] ; Save the second parameter\r
52 \r
53 ;\r
54 ; Save this function's return address into permenent memory at first.\r
55 ; Then, Fixup the esp point to permenent memory\r
56 ;\r
57 mov rax, rsp\r
58 sub rax, rbx\r
59 add rax, rcx\r
60 mov rdx, qword ptr [rsp] ; copy pushed register's value to permenent memory\r
61 mov qword ptr [rax], rdx \r
62 mov rdx, qword ptr [rsp + 8]\r
63 mov qword ptr [rax + 8], rdx \r
64 mov rdx, qword ptr [rsp + 10h]\r
65 mov qword ptr [rax + 10h], rdx \r
66 mov rdx, qword ptr [rsp + 18h]\r
67 mov qword ptr [rax + 18h], rdx \r
68 mov rdx, qword ptr [rsp + 20h] ; Update this function's return address into permenent memory\r
69 mov qword ptr [rax + 20h], rdx \r
70 mov rsp, rax ; From now, esp is pointed to permenent memory\r
71 \r
72 ;\r
73 ; Fixup the ebp point to permenent memory\r
74 ;\r
75 mov rax, rbp\r
76 sub rax, rbx\r
77 add rax, rcx\r
78 mov rbp, rax ; From now, ebp is pointed to permenent memory\r
79 \r
80 pop rdx\r
81 pop rcx\r
82 pop rbx\r
83 pop rax\r
84 ret\r
85SecSwitchStack ENDP\r
86\r
87;------------------------------------------------------------------------------\r
88; VOID\r
89; EFIAPI\r
90; PeiSwitchStacks (\r
91; IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
92; IN VOID *Context1, OPTIONAL\r
93; IN VOID *Context2, OPTIONAL\r
94; IN VOID *Context3, OPTIONAL\r
95; IN VOID *NewStack\r
96; )\r
97;------------------------------------------------------------------------------\r
98PeiSwitchStacks PROC\r
99 mov rax, rcx\r
100 mov rcx, rdx\r
101 mov rdx, r8\r
102 mov r8, r9\r
103 mov rsp, [rsp + 28h]\r
104 sub rsp, 20h\r
105 call rax\r
106 jmp $\r
107 ret\r
108PeiSwitchStacks ENDP\r
109\r
110 END\r