1 | ; $Id: SUPR0StackWrapper.mac 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; SUP - Support Library, ring-0 stack switching wrappers.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 | %ifndef ___VBox_SUPR0StackWrapper_mac
|
---|
38 | %define ___VBox_SUPR0StackWrapper_mac
|
---|
39 |
|
---|
40 | %include "VBox/asmdefs.mac"
|
---|
41 |
|
---|
42 | ;; VBox's own Stack
|
---|
43 | %define SUPR0STACKINFO_MAGIC0 0786f4256h ; VBox
|
---|
44 | %define SUPR0STACKINFO_MAGIC1 06f207327h ; 's o
|
---|
45 | %define SUPR0STACKINFO_MAGIC2 053206e77h ; wn S
|
---|
46 | %define SUPR0STACKINFO_MAGIC3 06b636174h ; tack
|
---|
47 |
|
---|
48 | ;;
|
---|
49 | ; Stack info located before the start of the stack, at the top of the page.
|
---|
50 | ;
|
---|
51 | struc SUPR0STACKINFO
|
---|
52 | .magic0 resd 1
|
---|
53 | .magic1 resd 1
|
---|
54 | .magic2 resd 1
|
---|
55 | .magic3 resd 1
|
---|
56 | .pResumeKernelStack resq 1
|
---|
57 | .pSelf resq 1
|
---|
58 | endstruc
|
---|
59 |
|
---|
60 | ;;
|
---|
61 | ; Number of parameters in GPRs and the spill area size.
|
---|
62 | %ifdef RT_ARCH_AMD64
|
---|
63 | %ifdef ASM_CALL64_MSC
|
---|
64 | %define SUPR0_GRP_PARAMS 4
|
---|
65 | %define SUPR0_SPILL_AREA 4
|
---|
66 | %else
|
---|
67 | %define SUPR0_GRP_PARAMS 6
|
---|
68 | %define SUPR0_SPILL_AREA 0
|
---|
69 | %endif
|
---|
70 | %else
|
---|
71 | %define SUPR0_GRP_PARAMS 0
|
---|
72 | %define SUPR0_SPILL_AREA 0
|
---|
73 | %endif
|
---|
74 |
|
---|
75 | ;;
|
---|
76 | ; Generic stack switching wrapper.
|
---|
77 | ;
|
---|
78 | ; @param %1 The name
|
---|
79 | ; @param %2 Number of arguments.
|
---|
80 | ;
|
---|
81 | %macro SUPR0StackWrapperGeneric 2
|
---|
82 | BEGINCODE
|
---|
83 | extern NAME(StkBack_ %+ %1)
|
---|
84 |
|
---|
85 | BEGINPROC %1
|
---|
86 | %ifdef RT_ARCH_AMD64 ; Only for amd64 for now.
|
---|
87 | ;
|
---|
88 | ; Check for the stack info.
|
---|
89 | ;
|
---|
90 | mov rax, rsp
|
---|
91 | or rax, 0fffh
|
---|
92 | sub rax, SUPR0STACKINFO_size - 1
|
---|
93 |
|
---|
94 | ; Check for the magic.
|
---|
95 | cmp dword [rax + SUPR0STACKINFO.magic0], SUPR0STACKINFO_MAGIC0
|
---|
96 | jne .regular
|
---|
97 | cmp dword [rax + SUPR0STACKINFO.magic1], SUPR0STACKINFO_MAGIC1
|
---|
98 | jne .regular
|
---|
99 | cmp dword [rax + SUPR0STACKINFO.magic2], SUPR0STACKINFO_MAGIC2
|
---|
100 | jne .regular
|
---|
101 | cmp dword [rax + SUPR0STACKINFO.magic3], SUPR0STACKINFO_MAGIC3
|
---|
102 | jne .regular
|
---|
103 |
|
---|
104 | ; Verify the self pointer.
|
---|
105 | cmp [rax + SUPR0STACKINFO.pSelf], rax
|
---|
106 | jne .regular
|
---|
107 |
|
---|
108 | ;
|
---|
109 | ; Perform a stack switch. We set up a RBP frame on the old stack so we
|
---|
110 | ; can use leave to restore the incoming stack upon return.
|
---|
111 | ;
|
---|
112 | push rbp
|
---|
113 | mov rbp, rsp
|
---|
114 |
|
---|
115 | ; The actual switch.
|
---|
116 | mov r10, 0ffffffffffffffe0h ; shuts up warning on 'and rsp, 0ffffffffffffffe0h'
|
---|
117 | and r10, [rax + SUPR0STACKINFO.pResumeKernelStack]
|
---|
118 | mov rsp, r10
|
---|
119 |
|
---|
120 | ;
|
---|
121 | ; Copy over stack arguments.
|
---|
122 | ;
|
---|
123 | ; Note! We always copy 2-3 extra arguments (%2 + 2) just in case someone got
|
---|
124 | ; the argument count wrong.
|
---|
125 | ;
|
---|
126 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 18
|
---|
127 | %error too many parameters
|
---|
128 | %fatal too many parameters
|
---|
129 | %endif
|
---|
130 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 16
|
---|
131 | push qword [rbp + 98h]
|
---|
132 | push qword [rbp + 90h]
|
---|
133 | %endif
|
---|
134 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 14
|
---|
135 | push qword [rbp + 88h]
|
---|
136 | push qword [rbp + 80h]
|
---|
137 | %endif
|
---|
138 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 12
|
---|
139 | push qword [rbp + 78h]
|
---|
140 | push qword [rbp + 70h]
|
---|
141 | %endif
|
---|
142 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 10
|
---|
143 | push qword [rbp + 68h]
|
---|
144 | push qword [rbp + 60h]
|
---|
145 | %endif
|
---|
146 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 8
|
---|
147 | push qword [rbp + 58h]
|
---|
148 | push qword [rbp + 50h]
|
---|
149 | %endif
|
---|
150 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 6
|
---|
151 | push qword [rbp + 48h]
|
---|
152 | push qword [rbp + 40h]
|
---|
153 | %endif
|
---|
154 | %if (%2 + 2) > SUPR0_GRP_PARAMS + 4
|
---|
155 | push qword [rbp + 38h]
|
---|
156 | push qword [rbp + 30h]
|
---|
157 | %endif
|
---|
158 | %if ((%2 + 2) > SUPR0_GRP_PARAMS + 2) || (SUPR0_SPILL_AREA > 2)
|
---|
159 | push qword [rbp + 28h]
|
---|
160 | push qword [rbp + 20h]
|
---|
161 | %endif
|
---|
162 | %if ((%2 + 2) > SUPR0_GRP_PARAMS) || (SUPR0_SPILL_AREA > 0)
|
---|
163 | push qword [rbp + 18h]
|
---|
164 | push qword [rbp + 10h]
|
---|
165 | %endif
|
---|
166 |
|
---|
167 | call NAME(StkBack_ %+ %1)
|
---|
168 |
|
---|
169 | leave
|
---|
170 | ret
|
---|
171 |
|
---|
172 | .regular:
|
---|
173 | %endif ; RT_ARCH_AMD64
|
---|
174 | jmp NAME(StkBack_ %+ %1)
|
---|
175 | ENDPROC %1
|
---|
176 | %endmacro
|
---|
177 |
|
---|
178 |
|
---|
179 | %endif
|
---|
180 |
|
---|