]>
Commit | Line | Data |
---|---|---|
91a03f78 TK |
1 | ;------------------------------------------------------------------------------\r |
2 | ;\r | |
3 | ; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r | |
4 | ; SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
5 | ;\r | |
6 | ; Abstract:\r | |
7 | ;\r | |
8 | ; Switch the stack from temporary memory to permanent memory.\r | |
9 | ;\r | |
10 | ;------------------------------------------------------------------------------\r | |
11 | \r | |
12 | SECTION .text\r | |
13 | \r | |
14 | ;------------------------------------------------------------------------------\r | |
15 | ; VOID\r | |
16 | ; EFIAPI\r | |
17 | ; SecSwitchStack (\r | |
18 | ; UINT32 TemporaryMemoryBase,\r | |
19 | ; UINT32 PermanentMemoryBase\r | |
20 | ; );\r | |
21 | ;------------------------------------------------------------------------------\r | |
22 | global ASM_PFX(SecSwitchStack)\r | |
23 | ASM_PFX(SecSwitchStack):\r | |
24 | ;\r | |
25 | ; Save four register: rax, rbx, rcx, rdx\r | |
26 | ;\r | |
27 | push rax\r | |
28 | push rbx\r | |
29 | push rcx\r | |
30 | push rdx\r | |
31 | \r | |
32 | ;\r | |
33 | ; !!CAUTION!! this function address's is pushed into stack after\r | |
34 | ; migration of whole temporary memory, so need save it to permanent\r | |
35 | ; memory at first!\r | |
36 | ;\r | |
37 | \r | |
38 | mov rbx, rcx ; Save the first parameter\r | |
39 | mov rcx, rdx ; Save the second parameter\r | |
40 | \r | |
41 | ;\r | |
42 | ; Save this function's return address into permanent memory at first.\r | |
43 | ; Then, Fixup the esp point to permanent memory\r | |
44 | ;\r | |
45 | mov rax, rsp\r | |
46 | sub rax, rbx\r | |
47 | add rax, rcx\r | |
48 | mov rdx, qword [rsp] ; copy pushed register's value to permanent memory\r | |
49 | mov qword [rax], rdx\r | |
50 | mov rdx, qword [rsp + 8]\r | |
51 | mov qword [rax + 8], rdx\r | |
52 | mov rdx, qword [rsp + 16]\r | |
53 | mov qword [rax + 16], rdx\r | |
54 | mov rdx, qword [rsp + 24]\r | |
55 | mov qword [rax + 24], rdx\r | |
56 | mov rdx, qword [rsp + 32] ; Update this function's return address into permanent memory\r | |
57 | mov qword [rax + 32], rdx\r | |
58 | mov rsp, rax ; From now, rsp is pointed to permanent memory\r | |
59 | \r | |
60 | ;\r | |
61 | ; Fixup the rbp point to permanent memory\r | |
62 | ;\r | |
63 | mov rax, rbp\r | |
64 | sub rax, rbx\r | |
65 | add rax, rcx\r | |
66 | mov rbp, rax ; From now, rbp is pointed to permanent memory\r | |
67 | \r | |
68 | pop rdx\r | |
69 | pop rcx\r | |
70 | pop rbx\r | |
71 | pop rax\r | |
72 | ret\r | |
73 | \r |