win-pvdrivers

view xenpci/hypercall_x86_mingw.h @ 380:5b2a37528899

using hypercall3's again, add support in mingw. remove duplicate code from evtchn.c
author Andy Grover <andy.grover@oracle.com>
date Wed Jul 09 12:33:23 2008 -0700 (2008-07-09)
parents 429f282ecbb3
children ecfd4ddaaf3d
line source
1 /* Code/license from Xen's include/asm/hypercall.h: */
2 /*
3 * Copyright (c) 2002-2004, K A Fraser
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation; or, when distributed
8 * separately from the Linux kernel or incorporated into other
9 * 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 /* Also Copyright (C) 2008 Andy Grover */
23 #define __STR(x) #x
24 #define STR(x) __STR(x)
26 #if 0
27 #define HYPERCALL_STR(name) \
28 "mov $stub_addr,%%eax; " \
29 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \
30 "call *%%eax"
31 #endif
33 #define HYPERCALL_STR(name) \
34 "mov %3,%%eax; " \
35 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \
36 "call *%%eax"
38 #define _hypercall2(type, name, a1, a2) \
39 ({ \
40 long __res, __ign1, __ign2; \
41 asm volatile ( \
42 "mov %3,%%eax; " \
43 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \
44 "call *%%eax" \
45 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \
46 : "1" ((long)(a1)), "2" ((long)(a2)), "r" (xpdd->hypercall_stubs) \
47 : "memory" ); \
48 (type)__res; \
49 })
51 #define _hypercall3(type, name, a1, a2, a3) \
52 ({ \
53 long __res, __ign1, __ign2, __ign3; \
54 asm volatile ( \
55 "mov %4,%%eax; " \
56 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \
57 "call *%%eax" \
58 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
59 "=d" (__ign3) \
60 : "1" ((long)(a1)), "2" ((long)(a2)), \
61 "3" ((long)(a3)), "r" (xpdd->hypercall_stubs) \
62 : "memory" ); \
63 (type)__res; \
64 })
67 static __inline void __cpuid(uint32_t output[4], uint32_t op)
68 {
69 __asm__("cpuid"
70 : "=a" (output[0]),
71 "=b" (output[1]),
72 "=c" (output[2]),
73 "=d" (output[3])
74 : "0" (op));
75 }
77 static __inline void __writemsr(uint32_t msr, uint64_t value)
78 {
79 uint32_t hi, lo;
80 hi = value >> 32;
81 lo = value & 0xFFFFFFFF;
83 __asm__ __volatile__("wrmsr"
84 : /* no outputs */
85 : "c" (msr), "a" (lo), "d" (hi));
86 }
88 static __inline int
89 HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
90 {
91 return _hypercall2(int, memory_op, cmd, arg);
92 }
94 static __inline int
95 HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
96 {
97 return _hypercall2(int, sched_op, cmd, arg);
98 }
100 static __inline int
101 HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
102 {
103 return _hypercall2(unsigned long, hvm_op, op, arg);
104 }
106 static __inline int
107 HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
108 {
109 return _hypercall2(int, event_channel_op, cmd, arg);
110 }
112 static inline int
113 HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, unsigned int cmd, void *uop,
114 unsigned int count)
115 {
116 return _hypercall3(int, grant_table_op, cmd, uop, count);
117 }