win-pvdrivers

changeset 303:47ec69c1046c

Merge
author Andy Grover <andy.grover@oracle.com>
date Tue Jun 10 20:18:05 2008 -0700 (2008-06-10)
parents 3673f1f07746 af768b0bca2c
children 5a7bfc1827a7
files
line diff
     1.1 --- a/common/include/public/arch-x86/xen.h	Mon Jun 09 21:54:42 2008 -0700
     1.2 +++ b/common/include/public/arch-x86/xen.h	Tue Jun 10 20:18:05 2008 -0700
     1.3 @@ -209,4 +209,5 @@ typedef struct arch_shared_info arch_sha
     1.4   * tab-width: 4
     1.5   * indent-tabs-mode: nil
     1.6   * End:
     1.7 - */
     1.8 \ No newline at end of file
     1.9 + */
    1.10 +
     2.1 --- a/common/include/xen_public.h	Mon Jun 09 21:54:42 2008 -0700
     2.2 +++ b/common/include/xen_public.h	Tue Jun 10 20:18:05 2008 -0700
     2.3 @@ -199,7 +199,9 @@ static __inline VOID
     2.4  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
     2.5  {
     2.6  //  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
     2.7 -  RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     2.8 +  //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     2.9 +  // using strcpy instead of above needed for mingw32
    2.10 +  strcpy((char *)ptr, val);
    2.11    *ptr += strlen(val) + 1;
    2.12  }
    2.13  
     3.1 --- a/common/include/xen_windows.h	Mon Jun 09 21:54:42 2008 -0700
     3.2 +++ b/common/include/xen_windows.h	Tue Jun 10 20:18:05 2008 -0700
     3.3 @@ -9,12 +9,23 @@
     3.4    #define __x86_64__
     3.5  #elif defined(_IA64_)
     3.6    #define __ia64__
     3.7 +#elif defined(__MINGW32__)
     3.8 +  /* __i386__ already defined */
     3.9  #elif defined(_X86_)
    3.10    #define __i386__
    3.11  #else
    3.12    #error Unknown architecture
    3.13  #endif
    3.14  
    3.15 +#ifdef __MINGW32__
    3.16 +typedef signed char int8_t;
    3.17 +typedef unsigned char uint8_t;
    3.18 +typedef signed short int16_t;
    3.19 +typedef unsigned short uint16_t;
    3.20 +typedef signed int int32_t;
    3.21 +typedef unsigned int uint32_t;
    3.22 +typedef unsigned long long uint64_t;
    3.23 +#else
    3.24  typedef INT8 int8_t;
    3.25  typedef UINT8 uint8_t;
    3.26  typedef INT16 int16_t;
    3.27 @@ -22,6 +33,7 @@ typedef UINT16 uint16_t;
    3.28  typedef INT32 int32_t;
    3.29  typedef UINT32 uint32_t;
    3.30  typedef UINT64 uint64_t;
    3.31 +#endif
    3.32  
    3.33  #include <xen.h>
    3.34  
     4.1 --- a/xenpci/hypercall.h	Mon Jun 09 21:54:42 2008 -0700
     4.2 +++ b/xenpci/hypercall.h	Tue Jun 10 20:18:05 2008 -0700
     4.3 @@ -17,8 +17,12 @@ along with this program; if not, write t
     4.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     4.5  */
     4.6  
     4.7 -#if defined(_X86_)
     4.8 -  #include "hypercall_x86.h"
     4.9 +#if defined(_X86_)
    4.10 +  #if defined(__MINGW32__)
    4.11 +    #include "hypercall_x86_mingw.h"
    4.12 +  #else
    4.13 +    #include "hypercall_x86.h"
    4.14 +  #endif
    4.15  #else
    4.16    #if defined(_AMD64_)
    4.17      #include "hypercall_amd64.h"
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xenpci/hypercall_x86_mingw.h	Tue Jun 10 20:18:05 2008 -0700
     5.3 @@ -0,0 +1,139 @@
     5.4 +/*
     5.5 +PV Drivers for Windows Xen HVM Domains
     5.6 +Copyright (C) 2007 James Harper
     5.7 +
     5.8 +This program is free software; you can redistribute it and/or
     5.9 +modify it under the terms of the GNU General Public License
    5.10 +as published by the Free Software Foundation; either version 2
    5.11 +of the License, or (at your option) any later version.
    5.12 +
    5.13 +This program is distributed in the hope that it will be useful,
    5.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.16 +GNU General Public License for more details.
    5.17 +
    5.18 +You should have received a copy of the GNU General Public License
    5.19 +along with this program; if not, write to the Free Software
    5.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    5.21 +*/
    5.22 +
    5.23 +#define __STR(x) #x
    5.24 +#define STR(x) __STR(x)
    5.25 +
    5.26 +#define HYPERCALL_STR(name)					\
    5.27 +	"mov $xpdd->hypercall_stubs,%%eax; "				\
    5.28 +	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
    5.29 +	"call *%%eax"
    5.30 +
    5.31 +#define _hypercall2(type, name, a1, a2)                         \
    5.32 +({                                                              \
    5.33 +        long __res, __ign1, __ign2;                             \
    5.34 +        asm volatile (                                          \
    5.35 +                HYPERCALL_STR(name)                             \
    5.36 +                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
    5.37 +                : "1" ((long)(a1)), "2" ((long)(a2))            \
    5.38 +                : "memory" );                                   \
    5.39 +        (type)__res;                                            \
    5.40 +})
    5.41 +
    5.42 +#define _hypercall3(type, name, a1, a2, a3)			\
    5.43 +({								\
    5.44 +	long __res, __ign1, __ign2, __ign3;			\
    5.45 +	asm volatile (						\
    5.46 +		HYPERCALL_STR(name)				\
    5.47 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    5.48 +		"=d" (__ign3)					\
    5.49 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    5.50 +		"3" ((long)(a3))				\
    5.51 +		: "memory" );					\
    5.52 +	(type)__res;						\
    5.53 +})
    5.54 +
    5.55 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
    5.56 +({								\
    5.57 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
    5.58 +	asm volatile (						\
    5.59 +		HYPERCALL_STR(name)				\
    5.60 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    5.61 +		"=d" (__ign3), "=S" (__ign4)			\
    5.62 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    5.63 +		"3" ((long)(a3)), "4" ((long)(a4))		\
    5.64 +		: "memory" );					\
    5.65 +	(type)__res;						\
    5.66 +})
    5.67 +
    5.68 +static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
    5.69 +                         unsigned int *ecx, unsigned int *edx)
    5.70 +{
    5.71 +  __asm__("cpuid"
    5.72 +          : "=a" (*eax),
    5.73 +            "=b" (*ebx),
    5.74 +            "=c" (*ecx),
    5.75 +            "=d" (*edx)
    5.76 +          : "0" (op));
    5.77 +}
    5.78 +
    5.79 +static __inline void __cpuid(uint32_t output[4], uint32_t op)
    5.80 +{
    5.81 +  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
    5.82 +}
    5.83 +
    5.84 +static __inline void __writemsr(uint32_t msr, uint64_t value)
    5.85 +{
    5.86 +  uint32_t hi, lo;
    5.87 +  hi = value >> 32;
    5.88 +  lo = value & 0xFFFFFFFF;
    5.89 +
    5.90 +  __asm__ __volatile__("wrmsr" \
    5.91 +                       : /* no outputs */ \
    5.92 +                       : "c" (msr), "a" (lo), "d" (hi));
    5.93 +}
    5.94 +
    5.95 +static __inline int
    5.96 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    5.97 +{
    5.98 +  return _hypercall2(int, memory_op, cmd, arg);
    5.99 +}
   5.100 +
   5.101 +static __inline int
   5.102 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   5.103 +{
   5.104 +  return _hypercall2(int, sched_op, cmd, arg);
   5.105 +}
   5.106 +
   5.107 +static __inline int
   5.108 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   5.109 +{
   5.110 +  return _hypercall2(int, xen_version, cmd, arg);
   5.111 +}
   5.112 +
   5.113 +static __inline int
   5.114 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   5.115 +{
   5.116 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   5.117 +}
   5.118 +
   5.119 +static __inline int
   5.120 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   5.121 +{
   5.122 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   5.123 +}
   5.124 +
   5.125 +static __inline int
   5.126 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   5.127 +{
   5.128 +	return _hypercall3(int, console_io, cmd, count, string);
   5.129 +}
   5.130 +
   5.131 +static __inline int
   5.132 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   5.133 +{
   5.134 +  return _hypercall2(unsigned long, hvm_op, op, arg);
   5.135 +}
   5.136 +
   5.137 +static __inline int
   5.138 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   5.139 +{
   5.140 +	return _hypercall2(int, event_channel_op, cmd, arg);
   5.141 +}
   5.142 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/xenpci/makefile.mingw	Tue Jun 10 20:18:05 2008 -0700
     6.3 @@ -0,0 +1,9 @@
     6.4 +CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public
     6.5 +
     6.6 +xenpci.sys: xenpci.c 
     6.7 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal
     6.8 +
     6.9 +test.exe: test.c kexec.h
    6.10 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s $^ -lkernel32
    6.11 +
    6.12 +all: xenpci.sys
     7.1 --- a/xenpci/xenpci.h	Mon Jun 09 21:54:42 2008 -0700
     7.2 +++ b/xenpci/xenpci.h	Tue Jun 10 20:18:05 2008 -0700
     7.3 @@ -24,14 +24,16 @@ Foundation, Inc., 51 Franklin Street, Fi
     7.4  #define EISCONN 127
     7.5  
     7.6  #include <ntddk.h>
     7.7 +
     7.8 +#ifndef __MINGW32__
     7.9  #include <wdm.h>
    7.10  //#include <wdf.h>
    7.11  #include <initguid.h>
    7.12  #include <wdmguid.h>
    7.13  #include <errno.h>
    7.14 -
    7.15  #define NTSTRSAFE_LIB
    7.16  #include <ntstrsafe.h>
    7.17 +#endif
    7.18  
    7.19  #define __DRIVER_NAME "XenPCI"
    7.20  
    7.21 @@ -133,19 +135,19 @@ typedef struct
    7.22    ULONG device_usage_hibernation;
    7.23  } XENPCI_COMMON, *PXENPCI_COMMON;
    7.24  
    7.25 -static __inline INIT_PNP_STATE(PXENPCI_COMMON common)
    7.26 +static __inline void INIT_PNP_STATE(PXENPCI_COMMON common)
    7.27  {
    7.28    common->current_pnp_state = NotStarted;
    7.29    common->previous_pnp_state = NotStarted;
    7.30  }
    7.31  
    7.32 -static __inline SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
    7.33 +static __inline void SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
    7.34  {
    7.35    common->previous_pnp_state = common->current_pnp_state;
    7.36    common->current_pnp_state = state;
    7.37  }
    7.38  
    7.39 -static __inline REVERT_PNP_STATE(PXENPCI_COMMON common)
    7.40 +static __inline void REVERT_PNP_STATE(PXENPCI_COMMON common)
    7.41  {
    7.42    common->current_pnp_state = common->previous_pnp_state;
    7.43  }
    7.44 @@ -200,7 +202,7 @@ typedef struct {
    7.45    KSPIN_LOCK WatchLock;
    7.46    KSPIN_LOCK grant_lock;
    7.47  
    7.48 -  KGUARDED_MUTEX WatchHandlerMutex;
    7.49 +  //KGUARDED_MUTEX WatchHandlerMutex;
    7.50  
    7.51    LIST_ENTRY child_list;
    7.52    
    7.53 @@ -246,50 +248,27 @@ typedef struct
    7.54    PXENPCI_PDO_DEVICE_DATA context;
    7.55  } XEN_CHILD, *PXEN_CHILD;
    7.56  
    7.57 -#define SWINT(x) case x: __asm { int x } break;
    7.58 -
    7.59  #if defined(_X86_)
    7.60  static __inline VOID
    7.61  sw_interrupt(UCHAR intno)
    7.62  {
    7.63    //KdPrint((__DRIVER_NAME "     Calling interrupt %02X\n", intno));
    7.64 -  switch (intno)
    7.65 +  if (intno >= 0x10)
    7.66    {
    7.67 -  SWINT(0x10) SWINT(0x11) SWINT(0x12) SWINT(0x13) SWINT(0x14) SWINT(0x15) SWINT(0x16) SWINT(0x17)
    7.68 -  SWINT(0x18) SWINT(0x19) SWINT(0x1A) SWINT(0x1B) SWINT(0x1C) SWINT(0x1D) SWINT(0x1E) SWINT(0x1F)
    7.69 -  SWINT(0x20) SWINT(0x21) SWINT(0x22) SWINT(0x23) SWINT(0x24) SWINT(0x25) SWINT(0x26) SWINT(0x27)
    7.70 -  SWINT(0x28) SWINT(0x29) SWINT(0x2A) SWINT(0x2B) SWINT(0x2C) SWINT(0x2D) SWINT(0x2E) SWINT(0x2F)
    7.71 -  SWINT(0x30) SWINT(0x31) SWINT(0x32) SWINT(0x33) SWINT(0x34) SWINT(0x35) SWINT(0x36) SWINT(0x37)
    7.72 -  SWINT(0x38) SWINT(0x39) SWINT(0x3A) SWINT(0x3B) SWINT(0x3C) SWINT(0x3D) SWINT(0x3E) SWINT(0x3F)
    7.73 -  SWINT(0x40) SWINT(0x41) SWINT(0x42) SWINT(0x43) SWINT(0x44) SWINT(0x45) SWINT(0x46) SWINT(0x47)
    7.74 -  SWINT(0x48) SWINT(0x49) SWINT(0x4A) SWINT(0x4B) SWINT(0x4C) SWINT(0x4D) SWINT(0x4E) SWINT(0x4F)
    7.75 -  SWINT(0x50) SWINT(0x51) SWINT(0x52) SWINT(0x53) SWINT(0x54) SWINT(0x55) SWINT(0x56) SWINT(0x57)
    7.76 -  SWINT(0x58) SWINT(0x59) SWINT(0x5A) SWINT(0x5B) SWINT(0x5C) SWINT(0x5D) SWINT(0x5E) SWINT(0x5F)
    7.77 -  SWINT(0x60) SWINT(0x61) SWINT(0x62) SWINT(0x63) SWINT(0x64) SWINT(0x65) SWINT(0x66) SWINT(0x67)
    7.78 -  SWINT(0x68) SWINT(0x69) SWINT(0x6A) SWINT(0x6B) SWINT(0x6C) SWINT(0x6D) SWINT(0x6E) SWINT(0x6F)
    7.79 -  SWINT(0x70) SWINT(0x71) SWINT(0x72) SWINT(0x73) SWINT(0x74) SWINT(0x75) SWINT(0x76) SWINT(0x77)
    7.80 -  SWINT(0x78) SWINT(0x79) SWINT(0x7A) SWINT(0x7B) SWINT(0x7C) SWINT(0x7D) SWINT(0x7E) SWINT(0x7F)
    7.81 -  SWINT(0x80) SWINT(0x81) SWINT(0x82) SWINT(0x83) SWINT(0x84) SWINT(0x85) SWINT(0x86) SWINT(0x87)
    7.82 -  SWINT(0x88) SWINT(0x89) SWINT(0x8A) SWINT(0x8B) SWINT(0x8C) SWINT(0x8D) SWINT(0x8E) SWINT(0x8F)
    7.83 -  SWINT(0x90) SWINT(0x91) SWINT(0x92) SWINT(0x93) SWINT(0x94) SWINT(0x95) SWINT(0x96) SWINT(0x97)
    7.84 -  SWINT(0x98) SWINT(0x99) SWINT(0x9A) SWINT(0x9B) SWINT(0x9C) SWINT(0x9D) SWINT(0x9E) SWINT(0x9F)
    7.85 -  SWINT(0xA0) SWINT(0xA1) SWINT(0xA2) SWINT(0xA3) SWINT(0xA4) SWINT(0xA5) SWINT(0xA6) SWINT(0xA7)
    7.86 -  SWINT(0xA8) SWINT(0xA9) SWINT(0xAA) SWINT(0xAB) SWINT(0xAC) SWINT(0xAD) SWINT(0xAE) SWINT(0xAF)
    7.87 -  SWINT(0xB0) SWINT(0xB1) SWINT(0xB2) SWINT(0xB3) SWINT(0xB4) SWINT(0xB5) SWINT(0xB6) SWINT(0xB7)
    7.88 -  SWINT(0xB8) SWINT(0xB9) SWINT(0xBA) SWINT(0xBB) SWINT(0xBC) SWINT(0xBD) SWINT(0xBE) SWINT(0xBF)
    7.89 -  SWINT(0xC0) SWINT(0xC1) SWINT(0xC2) SWINT(0xC3) SWINT(0xC4) SWINT(0xC5) SWINT(0xC6) SWINT(0xC7)
    7.90 -  SWINT(0xC8) SWINT(0xC9) SWINT(0xCA) SWINT(0xCB) SWINT(0xCC) SWINT(0xCD) SWINT(0xCE) SWINT(0xCF)
    7.91 -  SWINT(0xD0) SWINT(0xD1) SWINT(0xD2) SWINT(0xD3) SWINT(0xD4) SWINT(0xD5) SWINT(0xD6) SWINT(0xD7)
    7.92 -  SWINT(0xD8) SWINT(0xD9) SWINT(0xDA) SWINT(0xDB) SWINT(0xDC) SWINT(0xDD) SWINT(0xDE) SWINT(0xDF)
    7.93 -  SWINT(0xE0) SWINT(0xE1) SWINT(0xE2) SWINT(0xE3) SWINT(0xE4) SWINT(0xE5) SWINT(0xE6) SWINT(0xE7)
    7.94 -  SWINT(0xE8) SWINT(0xE9) SWINT(0xEA) SWINT(0xEB) SWINT(0xEC) SWINT(0xED) SWINT(0xEE) SWINT(0xEF)
    7.95 -  SWINT(0xF0) SWINT(0xF1) SWINT(0xF2) SWINT(0xF3) SWINT(0xF4) SWINT(0xF5) SWINT(0xF6) SWINT(0xF7)
    7.96 -  SWINT(0xF8) SWINT(0xF9) SWINT(0xFA) SWINT(0xFB) SWINT(0xFC) SWINT(0xFD) SWINT(0xFE) SWINT(0xFF)
    7.97 -
    7.98 -  default:
    7.99 +#ifdef __GNUC__
   7.100 +    /* TODO this gcc asm is wrong, need to use gcc asm extended template :( */
   7.101 +    __asm__("int $intno");
   7.102 +#elif defined (_MSC_VER)
   7.103 +    /* James, would this work? */
   7.104 +    __asm {int intno}
   7.105 +#else
   7.106 +  #error unknown compiler, what inline asm format to use?
   7.107 +#endif
   7.108 +  }
   7.109 +  else
   7.110 +  {
   7.111      KdPrint((__DRIVER_NAME "     interrupt %02X not set up. Blame James.\n", intno));
   7.112      KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, (ULONG)intno, 0x00000000, 0x00000000);
   7.113 -    break;
   7.114    }
   7.115  }    
   7.116  #else