1/******************************************************************************
2 * hypercall-x86_32.h
3 *
4 * Copied from XenLinux.
5 *
6 * Copyright (c) 2002-2004, K A Fraser
7 *
8 * This file may be distributed separately from the Linux kernel, or
9 * incorporated into other software packages, subject to the following license:
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this source file (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use, copy, modify,
14 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
15 * and to permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * IN THE SOFTWARE.
28 */
29
30#ifndef __HYPERCALL_X86_32_H__
31#define __HYPERCALL_X86_32_H__
32
33#include <xen/xen.h>
34#include <xen/nmi.h>
35#include <xen/sched.h>
36#include <mini-os/mm.h>
37
38#define __STR(x) #x
39#define STR(x) __STR(x)
40
41extern char _minios_hypercall_page[PAGE_SIZE];
42
43#define _hypercall0(type, name)			\
44({						\
45	long __res;				\
46	asm volatile (				\
47		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
48		: "=a" (__res)			\
49		:				\
50		: "memory" );			\
51	(type)__res;				\
52})
53
54#define _hypercall1(type, name, a1)				\
55({								\
56	long __res, __ign1;					\
57	asm volatile (						\
58		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
59		: "=a" (__res), "=b" (__ign1)			\
60		: "1" ((long)(a1))				\
61		: "memory" );					\
62	(type)__res;						\
63})
64
65#define _hypercall2(type, name, a1, a2)				\
66({								\
67	long __res, __ign1, __ign2;				\
68	asm volatile (						\
69		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
70		: "=a" (__res), "=b" (__ign1), "=c" (__ign2)	\
71		: "1" ((long)(a1)), "2" ((long)(a2))		\
72		: "memory" );					\
73	(type)__res;						\
74})
75
76#define _hypercall3(type, name, a1, a2, a3)			\
77({								\
78	long __res, __ign1, __ign2, __ign3;			\
79	asm volatile (						\
80		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
81		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
82		"=d" (__ign3)					\
83		: "1" ((long)(a1)), "2" ((long)(a2)),		\
84		"3" ((long)(a3))				\
85		: "memory" );					\
86	(type)__res;						\
87})
88
89#define _hypercall4(type, name, a1, a2, a3, a4)			\
90({								\
91	long __res, __ign1, __ign2, __ign3, __ign4;		\
92	asm volatile (						\
93		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
94		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
95		"=d" (__ign3), "=S" (__ign4)			\
96		: "1" ((long)(a1)), "2" ((long)(a2)),		\
97		"3" ((long)(a3)), "4" ((long)(a4))		\
98		: "memory" );					\
99	(type)__res;						\
100})
101
102#define _hypercall5(type, name, a1, a2, a3, a4, a5)		\
103({								\
104	long __res, __ign1, __ign2, __ign3, __ign4, __ign5;	\
105	asm volatile (						\
106		"call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
107		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
108		"=d" (__ign3), "=S" (__ign4), "=D" (__ign5)	\
109		: "1" ((long)(a1)), "2" ((long)(a2)),		\
110		"3" ((long)(a3)), "4" ((long)(a4)),		\
111		"5" ((long)(a5))				\
112		: "memory" );					\
113	(type)__res;						\
114})
115
116static inline int
117HYPERVISOR_set_trap_table(
118	trap_info_t *table)
119{
120	return _hypercall1(int, set_trap_table, table);
121}
122
123static inline int
124HYPERVISOR_mmu_update(
125	mmu_update_t *req, int count, int *success_count, domid_t domid)
126{
127	return _hypercall4(int, mmu_update, req, count, success_count, domid);
128}
129
130static inline int
131HYPERVISOR_mmuext_op(
132	struct mmuext_op *op, int count, int *success_count, domid_t domid)
133{
134	return _hypercall4(int, mmuext_op, op, count, success_count, domid);
135}
136
137static inline int
138HYPERVISOR_set_gdt(
139	unsigned long *frame_list, int entries)
140{
141	return _hypercall2(int, set_gdt, frame_list, entries);
142}
143
144static inline int
145HYPERVISOR_stack_switch(
146	unsigned long ss, unsigned long esp)
147{
148	return _hypercall2(int, stack_switch, ss, esp);
149}
150
151static inline int
152HYPERVISOR_set_callbacks(
153	unsigned long event_selector, unsigned long event_address,
154	unsigned long failsafe_selector, unsigned long failsafe_address)
155{
156	return _hypercall4(int, set_callbacks,
157			   event_selector, event_address,
158			   failsafe_selector, failsafe_address);
159}
160
161static inline int
162HYPERVISOR_fpu_taskswitch(
163	int set)
164{
165	return _hypercall1(int, fpu_taskswitch, set);
166}
167
168static inline int
169HYPERVISOR_sched_op(
170	int cmd, void *arg)
171{
172	return _hypercall2(int, sched_op, cmd, arg);
173}
174
175static inline long
176HYPERVISOR_set_timer_op(
177	uint64_t timeout)
178{
179	unsigned long timeout_hi = (unsigned long)(timeout>>32);
180	unsigned long timeout_lo = (unsigned long)timeout;
181	return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
182}
183
184static inline int
185HYPERVISOR_set_debugreg(
186	int reg, unsigned long value)
187{
188	return _hypercall2(int, set_debugreg, reg, value);
189}
190
191static inline unsigned long
192HYPERVISOR_get_debugreg(
193	int reg)
194{
195	return _hypercall1(unsigned long, get_debugreg, reg);
196}
197
198static inline int
199HYPERVISOR_update_descriptor(
200	uint64_t ma, uint64_t desc)
201{
202	return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
203}
204
205static inline int
206HYPERVISOR_memory_op(
207	unsigned int cmd, void *arg)
208{
209	return _hypercall2(int, memory_op, cmd, arg);
210}
211
212static inline int
213HYPERVISOR_multicall(
214	void *call_list, int nr_calls)
215{
216	return _hypercall2(int, multicall, call_list, nr_calls);
217}
218
219static inline int
220HYPERVISOR_update_va_mapping(
221	unsigned long va, pte_t new_val, unsigned long flags)
222{
223	return _hypercall4(int, update_va_mapping, va,
224			   new_val.pte_low, new_val.pte_high, flags);
225}
226
227static inline int
228HYPERVISOR_event_channel_op(
229	int cmd, void *op)
230{
231	return _hypercall2(int, event_channel_op, cmd, op);
232}
233
234static inline int
235HYPERVISOR_xen_version(
236	int cmd, void *arg)
237{
238	return _hypercall2(int, xen_version, cmd, arg);
239}
240
241static inline int
242HYPERVISOR_console_io(
243	int cmd, int count, char *str)
244{
245	return _hypercall3(int, console_io, cmd, count, str);
246}
247
248static inline int
249HYPERVISOR_physdev_op(
250	void *physdev_op)
251{
252	return _hypercall1(int, physdev_op, physdev_op);
253}
254
255static inline int
256HYPERVISOR_grant_table_op(
257	unsigned int cmd, void *uop, unsigned int count)
258{
259	return _hypercall3(int, grant_table_op, cmd, uop, count);
260}
261
262static inline int
263HYPERVISOR_update_va_mapping_otherdomain(
264	unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
265{
266	return _hypercall5(int, update_va_mapping_otherdomain, va,
267			   new_val.pte_low, new_val.pte_high, flags, domid);
268}
269
270static inline int
271HYPERVISOR_vm_assist(
272	unsigned int cmd, unsigned int type)
273{
274	return _hypercall2(int, vm_assist, cmd, type);
275}
276
277static inline int
278HYPERVISOR_vcpu_op(
279	int cmd, int vcpuid, void *extra_args)
280{
281	return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
282}
283
284static inline int
285HYPERVISOR_suspend(
286	unsigned long srec)
287{
288	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
289			   SHUTDOWN_suspend, srec);
290}
291
292static inline int
293HYPERVISOR_nmi_op(
294	unsigned long op,
295	unsigned long arg)
296{
297	return _hypercall2(int, nmi_op, op, arg);
298}
299
300static inline int
301HYPERVISOR_sysctl(
302	unsigned long op)
303{
304	return _hypercall1(int, sysctl, op);
305}
306
307static inline int
308HYPERVISOR_domctl(
309	unsigned long op)
310{
311	return _hypercall1(int, domctl, op);
312}
313
314#endif /* __HYPERCALL_X86_32_H__ */
315
316/*
317 * Local variables:
318 *  c-file-style: "linux"
319 *  indent-tabs-mode: t
320 *  c-indent-level: 8
321 *  c-basic-offset: 8
322 *  tab-width: 8
323 * End:
324 */
325