win-pvdrivers

changeset 301:7879ec15f2a1 wdm

add some bits for building with mingw -- just focusing on xenpci to start
author Andy Grover <andy.grover@oracle.com>
date Tue Jun 10 20:13:48 2008 -0700 (2008-06-10)
parents b2f5af0c80d2
children af768b0bca2c
files common/include/xen_public.h common/include/xen_windows.h xenpci/hypercall.h xenpci/hypercall_x86_mingw.h xenpci/makefile.mingw
line diff
     1.1 --- a/common/include/xen_public.h	Tue Jun 10 20:12:10 2008 -0700
     1.2 +++ b/common/include/xen_public.h	Tue Jun 10 20:13:48 2008 -0700
     1.3 @@ -199,7 +199,9 @@ static __inline VOID
     1.4  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
     1.5  {
     1.6  //  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
     1.7 -  RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     1.8 +  //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     1.9 +  // using strcpy instead of above needed for mingw32
    1.10 +  strcpy((char *)ptr, val);
    1.11    *ptr += strlen(val) + 1;
    1.12  }
    1.13  
     2.1 --- a/common/include/xen_windows.h	Tue Jun 10 20:12:10 2008 -0700
     2.2 +++ b/common/include/xen_windows.h	Tue Jun 10 20:13:48 2008 -0700
     2.3 @@ -9,12 +9,23 @@
     2.4    #define __x86_64__
     2.5  #elif defined(_IA64_)
     2.6    #define __ia64__
     2.7 +#elif defined(__MINGW32__)
     2.8 +  /* __i386__ already defined */
     2.9  #elif defined(_X86_)
    2.10    #define __i386__
    2.11  #else
    2.12    #error Unknown architecture
    2.13  #endif
    2.14  
    2.15 +#ifdef __MINGW32__
    2.16 +typedef signed char int8_t;
    2.17 +typedef unsigned char uint8_t;
    2.18 +typedef signed short int16_t;
    2.19 +typedef unsigned short uint16_t;
    2.20 +typedef signed int int32_t;
    2.21 +typedef unsigned int uint32_t;
    2.22 +typedef unsigned long long uint64_t;
    2.23 +#else
    2.24  typedef INT8 int8_t;
    2.25  typedef UINT8 uint8_t;
    2.26  typedef INT16 int16_t;
    2.27 @@ -22,6 +33,7 @@ typedef UINT16 uint16_t;
    2.28  typedef INT32 int32_t;
    2.29  typedef UINT32 uint32_t;
    2.30  typedef UINT64 uint64_t;
    2.31 +#endif
    2.32  
    2.33  #include <xen.h>
    2.34  
     3.1 --- a/xenpci/hypercall.h	Tue Jun 10 20:12:10 2008 -0700
     3.2 +++ b/xenpci/hypercall.h	Tue Jun 10 20:13:48 2008 -0700
     3.3 @@ -17,8 +17,12 @@ along with this program; if not, write t
     3.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     3.5  */
     3.6  
     3.7 -#if defined(_X86_)
     3.8 -  #include "hypercall_x86.h"
     3.9 +#if defined(_X86_)
    3.10 +  #if defined(__MINGW32__)
    3.11 +    #include "hypercall_x86_mingw.h"
    3.12 +  #else
    3.13 +    #include "hypercall_x86.h"
    3.14 +  #endif
    3.15  #else
    3.16    #if defined(_AMD64_)
    3.17      #include "hypercall_amd64.h"
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xenpci/hypercall_x86_mingw.h	Tue Jun 10 20:13:48 2008 -0700
     4.3 @@ -0,0 +1,139 @@
     4.4 +/*
     4.5 +PV Drivers for Windows Xen HVM Domains
     4.6 +Copyright (C) 2007 James Harper
     4.7 +
     4.8 +This program is free software; you can redistribute it and/or
     4.9 +modify it under the terms of the GNU General Public License
    4.10 +as published by the Free Software Foundation; either version 2
    4.11 +of the License, or (at your option) any later version.
    4.12 +
    4.13 +This program is distributed in the hope that it will be useful,
    4.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 +GNU General Public License for more details.
    4.17 +
    4.18 +You should have received a copy of the GNU General Public License
    4.19 +along with this program; if not, write to the Free Software
    4.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.21 +*/
    4.22 +
    4.23 +#define __STR(x) #x
    4.24 +#define STR(x) __STR(x)
    4.25 +
    4.26 +#define HYPERCALL_STR(name)					\
    4.27 +	"mov $xpdd->hypercall_stubs,%%eax; "				\
    4.28 +	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
    4.29 +	"call *%%eax"
    4.30 +
    4.31 +#define _hypercall2(type, name, a1, a2)                         \
    4.32 +({                                                              \
    4.33 +        long __res, __ign1, __ign2;                             \
    4.34 +        asm volatile (                                          \
    4.35 +                HYPERCALL_STR(name)                             \
    4.36 +                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
    4.37 +                : "1" ((long)(a1)), "2" ((long)(a2))            \
    4.38 +                : "memory" );                                   \
    4.39 +        (type)__res;                                            \
    4.40 +})
    4.41 +
    4.42 +#define _hypercall3(type, name, a1, a2, a3)			\
    4.43 +({								\
    4.44 +	long __res, __ign1, __ign2, __ign3;			\
    4.45 +	asm volatile (						\
    4.46 +		HYPERCALL_STR(name)				\
    4.47 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    4.48 +		"=d" (__ign3)					\
    4.49 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    4.50 +		"3" ((long)(a3))				\
    4.51 +		: "memory" );					\
    4.52 +	(type)__res;						\
    4.53 +})
    4.54 +
    4.55 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
    4.56 +({								\
    4.57 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
    4.58 +	asm volatile (						\
    4.59 +		HYPERCALL_STR(name)				\
    4.60 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    4.61 +		"=d" (__ign3), "=S" (__ign4)			\
    4.62 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    4.63 +		"3" ((long)(a3)), "4" ((long)(a4))		\
    4.64 +		: "memory" );					\
    4.65 +	(type)__res;						\
    4.66 +})
    4.67 +
    4.68 +static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
    4.69 +                         unsigned int *ecx, unsigned int *edx)
    4.70 +{
    4.71 +  __asm__("cpuid"
    4.72 +          : "=a" (*eax),
    4.73 +            "=b" (*ebx),
    4.74 +            "=c" (*ecx),
    4.75 +            "=d" (*edx)
    4.76 +          : "0" (op));
    4.77 +}
    4.78 +
    4.79 +static __inline void __cpuid(uint32_t output[4], uint32_t op)
    4.80 +{
    4.81 +  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
    4.82 +}
    4.83 +
    4.84 +static __inline void __writemsr(uint32_t msr, uint64_t value)
    4.85 +{
    4.86 +  uint32_t hi, lo;
    4.87 +  hi = value >> 32;
    4.88 +  lo = value & 0xFFFFFFFF;
    4.89 +
    4.90 +  __asm__ __volatile__("wrmsr" \
    4.91 +                       : /* no outputs */ \
    4.92 +                       : "c" (msr), "a" (lo), "d" (hi));
    4.93 +}
    4.94 +
    4.95 +static __inline int
    4.96 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    4.97 +{
    4.98 +  return _hypercall2(int, memory_op, cmd, arg);
    4.99 +}
   4.100 +
   4.101 +static __inline int
   4.102 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   4.103 +{
   4.104 +  return _hypercall2(int, sched_op, cmd, arg);
   4.105 +}
   4.106 +
   4.107 +static __inline int
   4.108 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   4.109 +{
   4.110 +  return _hypercall2(int, xen_version, cmd, arg);
   4.111 +}
   4.112 +
   4.113 +static __inline int
   4.114 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   4.115 +{
   4.116 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   4.117 +}
   4.118 +
   4.119 +static __inline int
   4.120 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   4.121 +{
   4.122 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   4.123 +}
   4.124 +
   4.125 +static __inline int
   4.126 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   4.127 +{
   4.128 +	return _hypercall3(int, console_io, cmd, count, string);
   4.129 +}
   4.130 +
   4.131 +static __inline int
   4.132 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   4.133 +{
   4.134 +  return _hypercall2(unsigned long, hvm_op, op, arg);
   4.135 +}
   4.136 +
   4.137 +static __inline int
   4.138 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   4.139 +{
   4.140 +	return _hypercall2(int, event_channel_op, cmd, arg);
   4.141 +}
   4.142 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xenpci/makefile.mingw	Tue Jun 10 20:13:48 2008 -0700
     5.3 @@ -0,0 +1,9 @@
     5.4 +CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public
     5.5 +
     5.6 +xenpci.sys: xenpci.c 
     5.7 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal
     5.8 +
     5.9 +test.exe: test.c kexec.h
    5.10 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s $^ -lkernel32
    5.11 +
    5.12 +all: xenpci.sys