summaryrefslogtreecommitdiff
path: root/usr/src/uts/intel/ia32/ml/hypersubr.s
blob: f427aaff3107f8a3153f91727c6f8b6a69616cb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <sys/asm_linkage.h>
#ifndef __xpv
#include <sys/xpv_support.h>
#endif
#include <sys/hypervisor.h>

/*
 * Hypervisor "system calls"
 *
 * i386
 * 	%eax == call number
 * 	args in registers (%ebx, %ecx, %edx, %esi, %edi)
 *
 * amd64
 * 	%rax == call number
 * 	args in registers (%rdi, %rsi, %rdx, %r10, %r8, %r9)
 *
 * Note that for amd64 we use %r10 instead of %rcx for passing 4th argument
 * as in C calling convention since the "syscall" instruction clobbers %rcx.
 *
 * (These calls can be done more efficiently as gcc-style inlines, but
 * for simplicity and help with initial debugging, we use these primitives
 * to build the hypervisor calls up from C wrappers.)
 */

#if defined(__lint)

/*ARGSUSED*/
long
__hypercall0(int callnum)
{ return (0); }

/*ARGSUSED*/
long
__hypercall1(int callnum, ulong_t a1)
{ return (0); }

/*ARGSUSED*/
long
__hypercall2(int callnum, ulong_t a1, ulong_t a2)
{ return (0); }

/*ARGSUSED*/
long
__hypercall3(int callnum, ulong_t a1, ulong_t a2, ulong_t a3)
{ return (0); }

/*ARGSUSED*/
long
__hypercall4(int callnum, ulong_t a1, ulong_t a2, ulong_t a3, ulong_t a4)
{ return (0); }

/*ARGSUSED*/
long
__hypercall5(int callnum,
    ulong_t a1, ulong_t a2, ulong_t a3, ulong_t a4, ulong_t a5)
{ return (0); }

/*ARGSUSED*/
int
__hypercall0_int(int callnum)
{ return (0); }

/*ARGSUSED*/
int
__hypercall1_int(int callnum, ulong_t a1)
{ return (0); }

/*ARGSUSED*/
int
__hypercall2_int(int callnum, ulong_t a1, ulong_t a2)
{ return (0); }

/*ARGSUSED*/
int
__hypercall3_int(int callnum, ulong_t a1, ulong_t a2, ulong_t a3)
{ return (0); }

/*ARGSUSED*/
int
__hypercall4_int(int callnum, ulong_t a1, ulong_t a2, ulong_t a3, ulong_t a4)
{ return (0); }

/*ARGSUSED*/
int
__hypercall5_int(int callnum,
    ulong_t a1, ulong_t a2, ulong_t a3, ulong_t a4, ulong_t a5)
{ return (0); }

#else	/* __lint */

/*
 * XXPV grr - assembler can't deal with an instruction in a quoted string
 */
#undef	TRAP_INSTR	/* cause it's currently "int $0x82" */

/*
 * The method for issuing a hypercall (i.e. a system call to the
 * hypervisor) varies from platform to platform.  In 32-bit PV domains, an
 * 'int 82' triggers the call.  In 64-bit PV domains, a 'syscall' does the
 * trick.
 *
 * HVM domains are more complicated.  In all cases, we want to issue a
 * VMEXIT instruction, but AMD and Intel use different opcodes to represent
 * that instruction.  Rather than build CPU-specific modules with the
 * different opcodes, we use the 'hypercall page' provided by Xen.  This
 * page contains a collection of code stubs that do nothing except issue
 * hypercalls using the proper instructions for this machine.  To keep the
 * wrapper code as simple and efficient as possible, we preallocate that
 * page below.  When the module is loaded, we ask Xen to remap the
 * underlying PFN to that of the hypercall page.
 *
 * Note: this same mechanism could be used in PV domains, but using
 * hypercall page requires a call and several more instructions than simply
 * issuing the proper trap.
 */
#if !defined(__xpv)

#define	HYPERCALL_PAGESIZE		0x1000
#define	HYPERCALL_SHINFO_PAGESIZE	0x1000

	.data
	.align	HYPERCALL_SHINFO_PAGESIZE
	.globl	hypercall_shared_info_page
	.type	hypercall_shared_info_page, @object
	.size	hypercall_shared_info_page, HYPERCALL_SHINFO_PAGESIZE
hypercall_shared_info_page:
	.skip	HYPERCALL_SHINFO_PAGESIZE

	.text
	.align	HYPERCALL_PAGESIZE
	.globl	hypercall_page
	.type	hypercall_page, @function
hypercall_page:
	.skip	HYPERCALL_PAGESIZE
	.size	hypercall_page, HYPERCALL_PAGESIZE
#if defined(__amd64)
#define	TRAP_INSTR			\
	shll	$5, %eax;		\
	addq	$hypercall_page, %rax;	\
	jmp	*%rax
#else
#define	TRAP_INSTR			\
	shll	$5, %eax;		\
	addl	$hypercall_page, %eax;	\
	call	*%eax
#endif

#else /* !_xpv */

#if defined(__amd64)
#define	TRAP_INSTR	syscall
#elif defined(__i386)
#define	TRAP_INSTR	int $0x82
#endif
#endif /* !__xpv */


#if defined(__amd64) 

	ENTRY_NP(__hypercall0)
	ALTENTRY(__hypercall0_int)
	movl	%edi, %eax
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall0)

	ENTRY_NP(__hypercall1)
	ALTENTRY(__hypercall1_int)
	movl	%edi, %eax
	movq	%rsi, %rdi		/* arg 1 */
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall1)

	ENTRY_NP(__hypercall2)
	ALTENTRY(__hypercall2_int)
	movl	%edi, %eax
	movq	%rsi, %rdi		/* arg 1 */
	movq	%rdx, %rsi		/* arg 2 */
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall2)

	ENTRY_NP(__hypercall3)
	ALTENTRY(__hypercall3_int)
	movl	%edi, %eax
	movq	%rsi, %rdi		/* arg 1 */
	movq	%rdx, %rsi		/* arg 2 */
	movq	%rcx, %rdx		/* arg 3 */
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall3)

	ENTRY_NP(__hypercall4)
	ALTENTRY(__hypercall4_int)
	movl	%edi, %eax
	movq	%rsi, %rdi		/* arg 1 */
	movq	%rdx, %rsi		/* arg 2 */
	movq	%rcx, %rdx		/* arg 3 */
	movq	%r8, %r10		/* r10 = 4th arg */
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall4)

	ENTRY_NP(__hypercall5)
	ALTENTRY(__hypercall5_int)
	movl	%edi, %eax
	movq	%rsi, %rdi		/* arg 1 */
	movq	%rdx, %rsi		/* arg 2 */
	movq	%rcx, %rdx		/* arg 3 */
	movq	%r8, %r10		/* r10 = 4th arg */
	movq	%r9, %r8		/* arg 5 */
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall5)

#elif defined(__i386)

	ENTRY_NP(__hypercall0)
	ALTENTRY(__hypercall0_int)
	movl	4(%esp), %eax
	TRAP_INSTR
	ret
	SET_SIZE(__hypercall0)

	ENTRY_NP(__hypercall1)
	ALTENTRY(__hypercall1_int)
	pushl	%ebx
	movl	8(%esp), %eax
	movl	12(%esp), %ebx
	TRAP_INSTR
	popl	%ebx
	ret
	SET_SIZE(__hypercall1)

	ENTRY_NP(__hypercall2)
	ALTENTRY(__hypercall2_int)
	pushl	%ebx
	movl	8(%esp), %eax
	movl	12(%esp), %ebx
	movl	16(%esp), %ecx
	TRAP_INSTR
	popl	%ebx
	ret
	SET_SIZE(__hypercall2)

	ENTRY_NP(__hypercall3)
	ALTENTRY(__hypercall3_int)
	pushl	%ebx
	movl	8(%esp), %eax
	movl	12(%esp), %ebx
	movl	16(%esp), %ecx
	movl	20(%esp), %edx
	TRAP_INSTR
	popl	%ebx
	ret
	SET_SIZE(__hypercall3)

	ENTRY_NP(__hypercall4)
	ALTENTRY(__hypercall4_int)
	pushl	%ebx
	pushl	%esi
	movl	12(%esp), %eax
	movl	16(%esp), %ebx
	movl	20(%esp), %ecx
	movl	24(%esp), %edx
	movl	28(%esp), %esi
	TRAP_INSTR
	popl	%esi
	popl	%ebx
	ret
	SET_SIZE(__hypercall4)

	ENTRY_NP(__hypercall5)
	ALTENTRY(__hypercall5_int)
	pushl	%ebx
	pushl	%esi
	pushl	%edi
	movl	16(%esp), %eax
	movl	20(%esp), %ebx
	movl	24(%esp), %ecx
	movl	28(%esp), %edx
	movl	32(%esp), %esi
	movl	36(%esp), %edi
	TRAP_INSTR
	popl	%edi
	popl	%esi
	popl	%ebx
	ret
	SET_SIZE(__hypercall5)

#endif	/* __i386 */

#endif	/* lint */