VirtualBox

source: vbox/trunk/include/VBox/SUPR0StackWrapper.mac@ 94230

Last change on this file since 94230 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette