win-pvdrivers

changeset 336:d7a848ae1a39

merge with head
author James Harper <james.harper@bendigoit.com.au>
date Sun Jun 22 19:51:47 2008 +1000 (2008-06-22)
parents 2fcbd37634a3 52533409dbbd
children e69e4d79ee3f
files xenpci/xenbus.c
line diff
     1.1 --- a/common/include/public/io/xs_wire.h	Sun Jun 22 19:40:44 2008 +1000
     1.2 +++ b/common/include/public/io/xs_wire.h	Sun Jun 22 19:51:47 2008 +1000
     1.3 @@ -25,6 +25,7 @@
     1.4  
     1.5  #ifndef _XS_WIRE_H
     1.6  #define _XS_WIRE_H
     1.7 +#include <errno.h>
     1.8  
     1.9  enum xsd_sockmsg_type
    1.10  {
     2.1 --- a/common/include/public/memory.h	Sun Jun 22 19:40:44 2008 +1000
     2.2 +++ b/common/include/public/memory.h	Sun Jun 22 19:51:47 2008 +1000
     2.3 @@ -278,4 +278,5 @@ DEFINE_XEN_GUEST_HANDLE(xen_foreign_memo
     2.4   * tab-width: 4
     2.5   * indent-tabs-mode: nil
     2.6   * End:
     2.7 - */
     2.8 \ No newline at end of file
     2.9 + */
    2.10 +
     3.1 --- a/common/include/xen_windows.h	Sun Jun 22 19:40:44 2008 +1000
     3.2 +++ b/common/include/xen_windows.h	Sun Jun 22 19:51:47 2008 +1000
     3.3 @@ -35,8 +35,11 @@ typedef UINT32 uint32_t;
     3.4  typedef UINT64 uint64_t;
     3.5  #endif
     3.6  
     3.7 -#ifdef __MINGW32__
     3.8 -#define RtlStringCbCopyA(dst, dst_len, src) strncpy(dst, src, dst_len)
     3.9 +#ifdef __MINGW32__
    3.10 +#include <stdio.h>
    3.11 +#define RtlStringCbCopyA(dst, dst_len, src) strncpy(dst, src, dst_len)
    3.12 +#define RtlStringCbPrintfA(args...) snprintf(args)
    3.13 +#define RtlStringCbVPrintfA(args...) vsnprintf(args)
    3.14  #endif
    3.15  #include <xen.h>
    3.16  
    3.17 @@ -56,7 +59,6 @@ typedef UINT64 uint64_t;
    3.18  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    3.19  
    3.20  typedef unsigned long xenbus_transaction_t;
    3.21 -typedef uint32_t XENSTORE_RING_IDX;
    3.22  
    3.23  #define XBT_NIL ((xenbus_transaction_t)0)
    3.24  
    3.25 @@ -65,7 +67,7 @@ typedef uint32_t XENSTORE_RING_IDX;
    3.26  #define wmb() KeMemoryBarrier()
    3.27  #define mb() KeMemoryBarrier()
    3.28  
    3.29 -static char **
    3.30 +static __inline char **
    3.31  SplitString(char *String, char Split, int MaxParts, int *Count)
    3.32  {
    3.33    char **RetVal;
    3.34 @@ -100,7 +102,7 @@ SplitString(char *String, char Split, in
    3.35    return RetVal;
    3.36  }
    3.37  
    3.38 -static VOID
    3.39 +static __inline VOID
    3.40  FreeSplitString(char **Bits, int Count)
    3.41  {
    3.42    int i;
    3.43 @@ -140,19 +142,19 @@ AllocatePagesExtra(int Pages, int ExtraS
    3.44    return Mdl;
    3.45  }
    3.46  
    3.47 -static PMDL
    3.48 +static __inline PMDL
    3.49  AllocatePages(int Pages)
    3.50  {
    3.51    return AllocatePagesExtra(Pages, 0);
    3.52  }
    3.53  
    3.54 -static PMDL
    3.55 +static __inline PMDL
    3.56  AllocatePage()
    3.57  {
    3.58    return AllocatePagesExtra(1, 0);
    3.59  }
    3.60  
    3.61 -static PMDL
    3.62 +static __inline PMDL
    3.63  AllocateUncachedPage()
    3.64  {
    3.65    PMDL mdl;
    3.66 @@ -165,7 +167,7 @@ AllocateUncachedPage()
    3.67    return mdl;
    3.68  }  
    3.69  
    3.70 -static VOID
    3.71 +static __inline VOID
    3.72  FreeUncachedPage(PMDL mdl)
    3.73  {
    3.74    PVOID buf = MmGetMdlVirtualAddress(mdl);
    3.75 @@ -174,7 +176,7 @@ FreeUncachedPage(PMDL mdl)
    3.76    MmFreeNonCachedMemory(buf, PAGE_SIZE);
    3.77  }
    3.78  
    3.79 -static VOID
    3.80 +static __inline VOID
    3.81  FreePages(PMDL Mdl)
    3.82  {
    3.83    PVOID Buf = MmGetMdlVirtualAddress(Mdl);
     4.1 --- a/xenpci/hypercall.h	Sun Jun 22 19:40:44 2008 +1000
     4.2 +++ b/xenpci/hypercall.h	Sun Jun 22 19:51:47 2008 +1000
     4.3 @@ -17,11 +17,11 @@ 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 -  #if defined(__MINGW32__)
     4.9 -    #include "hypercall_x86_mingw.h"
    4.10 +#if defined(_X86_)
    4.11 +  #if defined(__MINGW32__)
    4.12 +    #include "hypercall_x86_mingw.h"
    4.13    #else
    4.14 -    #include "hypercall_x86.h"
    4.15 +    #include "hypercall_x86.h"
    4.16    #endif
    4.17  #else
    4.18    #if defined(_AMD64_)
    4.19 @@ -29,49 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    4.20    #endif
    4.21  #endif
    4.22  
    4.23 -static NTSTATUS
    4.24 -hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
    4.25 -{
    4.26 -  DWORD32 cpuid_output[4];
    4.27 -  char xensig[13];
    4.28 -  ULONG i;
    4.29 -  ULONG pages;
    4.30 -  ULONG msr;  
    4.31 -
    4.32 -  __cpuid(cpuid_output, 0x40000000);
    4.33 -  *(ULONG*)(xensig + 0) = cpuid_output[1];
    4.34 -  *(ULONG*)(xensig + 4) = cpuid_output[2];
    4.35 -  *(ULONG*)(xensig + 8) = cpuid_output[3];
    4.36 -  xensig[12] = '\0';
    4.37 -  KdPrint((__DRIVER_NAME " Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
    4.38 -
    4.39 -  __cpuid(cpuid_output, 0x40000002);
    4.40 -  pages = cpuid_output[0];
    4.41 -  msr = cpuid_output[1];
    4.42 -  //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
    4.43 -
    4.44 -  xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
    4.45 -  KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
    4.46 -
    4.47 -  if (!xpdd->hypercall_stubs)
    4.48 -    return 1;
    4.49 -  for (i = 0; i < pages; i++) {
    4.50 -    ULONGLONG pfn;
    4.51 -    pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
    4.52 -    KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
    4.53 -    __writemsr(msr, (pfn << PAGE_SHIFT) + i);
    4.54 -  }
    4.55 -  return STATUS_SUCCESS;
    4.56 -}
    4.57 -
    4.58 -static NTSTATUS
    4.59 -hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
    4.60 -{
    4.61 -  ExFreePoolWithTag(xpdd->hypercall_stubs, XENPCI_POOL_TAG);
    4.62 -
    4.63 -  return STATUS_SUCCESS;
    4.64 -}
    4.65 -
    4.66  static __inline ULONGLONG
    4.67  hvm_get_parameter(PXENPCI_DEVICE_DATA xpdd, int hvm_param)
    4.68  {
     5.1 --- a/xenpci/hypercall_x86.h	Sun Jun 22 19:40:44 2008 +1000
     5.2 +++ b/xenpci/hypercall_x86.h	Sun Jun 22 19:51:47 2008 +1000
     5.3 @@ -1,3 +1,5 @@
     5.4 +#ifndef HYPERCALL_X86_H
     5.5 +#define HYPERCALL_X86_H
     5.6  /*
     5.7  PV Drivers for Windows Xen HVM Domains
     5.8  Copyright (C) 2007 James Harper
     5.9 @@ -150,3 +152,4 @@ HYPERVISOR_event_channel_op(PXENPCI_DEVI
    5.10    return __res;
    5.11  }
    5.12  
    5.13 +#endif
     6.1 --- a/xenpci/hypercall_x86_mingw.h	Sun Jun 22 19:40:44 2008 +1000
     6.2 +++ b/xenpci/hypercall_x86_mingw.h	Sun Jun 22 19:51:47 2008 +1000
     6.3 @@ -1,139 +1,144 @@
     6.4 -/*
     6.5 -PV Drivers for Windows Xen HVM Domains
     6.6 -Copyright (C) 2007 James Harper
     6.7 -
     6.8 -This program is free software; you can redistribute it and/or
     6.9 -modify it under the terms of the GNU General Public License
    6.10 -as published by the Free Software Foundation; either version 2
    6.11 -of the License, or (at your option) any later version.
    6.12 -
    6.13 -This program is distributed in the hope that it will be useful,
    6.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 -GNU General Public License for more details.
    6.17 -
    6.18 -You should have received a copy of the GNU General Public License
    6.19 -along with this program; if not, write to the Free Software
    6.20 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    6.21 -*/
    6.22 -
    6.23 -#define __STR(x) #x
    6.24 -#define STR(x) __STR(x)
    6.25 -
    6.26 -#define HYPERCALL_STR(name)					\
    6.27 -	"mov $xpdd->hypercall_stubs,%%eax; "				\
    6.28 -	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
    6.29 -	"call *%%eax"
    6.30 -
    6.31 -#define _hypercall2(type, name, a1, a2)                         \
    6.32 -({                                                              \
    6.33 +/* Code/license from Xen's include/asm/hypercall.h: */
    6.34 +/*
    6.35 + * Copyright (c) 2002-2004, K A Fraser
    6.36 + * 
    6.37 + * This program is free software; you can redistribute it and/or
    6.38 + * modify it under the terms of the GNU General Public License version 2
    6.39 + * as published by the Free Software Foundation; or, when distributed
    6.40 + * separately from the Linux kernel or incorporated into other
    6.41 + * software packages, subject to the following license:
    6.42 + * 
    6.43 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    6.44 + * of this source file (the "Software"), to deal in the Software without
    6.45 + * restriction, including without limitation the rights to use, copy, modify,
    6.46 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
    6.47 + * and to permit persons to whom the Software is furnished to do so, subject to
    6.48 + * the following conditions:
    6.49 + * 
    6.50 + * The above copyright notice and this permission notice shall be included in
    6.51 + * all copies or substantial portions of the Software.
    6.52 + */
    6.53 +/* Also Copyright (C) 2008 Andy Grover */
    6.54 +
    6.55 +#define __STR(x) #x
    6.56 +#define STR(x) __STR(x)
    6.57 +
    6.58 +#define HYPERCALL_STR(name)					\
    6.59 +	"mov $stub_addr,%%eax; "			    \
    6.60 +	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
    6.61 +	"call *%%eax"
    6.62 +
    6.63 +#define _hypercall2(type, name, a1, a2)                         \
    6.64 +({                                                              \
    6.65          long __res, __ign1, __ign2;                             \
    6.66 -        asm volatile (                                          \
    6.67 -                HYPERCALL_STR(name)                             \
    6.68 -                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
    6.69 -                : "1" ((long)(a1)), "2" ((long)(a2))            \
    6.70 -                : "memory" );                                   \
    6.71 -        (type)__res;                                            \
    6.72 -})
    6.73 -
    6.74 -#define _hypercall3(type, name, a1, a2, a3)			\
    6.75 -({								\
    6.76 -	long __res, __ign1, __ign2, __ign3;			\
    6.77 -	asm volatile (						\
    6.78 -		HYPERCALL_STR(name)				\
    6.79 -		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    6.80 -		"=d" (__ign3)					\
    6.81 -		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    6.82 -		"3" ((long)(a3))				\
    6.83 -		: "memory" );					\
    6.84 -	(type)__res;						\
    6.85 -})
    6.86 -
    6.87 -#define _hypercall4(type, name, a1, a2, a3, a4)			\
    6.88 -({								\
    6.89 -	long __res, __ign1, __ign2, __ign3, __ign4;		\
    6.90 -	asm volatile (						\
    6.91 -		HYPERCALL_STR(name)				\
    6.92 -		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    6.93 -		"=d" (__ign3), "=S" (__ign4)			\
    6.94 -		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    6.95 -		"3" ((long)(a3)), "4" ((long)(a4))		\
    6.96 -		: "memory" );					\
    6.97 -	(type)__res;						\
    6.98 -})
    6.99 -
   6.100 -static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
   6.101 -                         unsigned int *ecx, unsigned int *edx)
   6.102 -{
   6.103 -  __asm__("cpuid"
   6.104 -          : "=a" (*eax),
   6.105 -            "=b" (*ebx),
   6.106 -            "=c" (*ecx),
   6.107 -            "=d" (*edx)
   6.108 -          : "0" (op));
   6.109 -}
   6.110 -
   6.111 -static __inline void __cpuid(uint32_t output[4], uint32_t op)
   6.112 -{
   6.113 -  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
   6.114 -}
   6.115 -
   6.116 -static __inline void __writemsr(uint32_t msr, uint64_t value)
   6.117 -{
   6.118 -  uint32_t hi, lo;
   6.119 -  hi = value >> 32;
   6.120 -  lo = value & 0xFFFFFFFF;
   6.121 -
   6.122 -  __asm__ __volatile__("wrmsr" \
   6.123 -                       : /* no outputs */ \
   6.124 -                       : "c" (msr), "a" (lo), "d" (hi));
   6.125 -}
   6.126 -
   6.127 -static __inline int
   6.128 -HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.129 -{
   6.130 -  return _hypercall2(int, memory_op, cmd, arg);
   6.131 -}
   6.132 -
   6.133 -static __inline int
   6.134 -HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.135 -{
   6.136 -  return _hypercall2(int, sched_op, cmd, arg);
   6.137 -}
   6.138 -
   6.139 -static __inline int
   6.140 -HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.141 -{
   6.142 -  return _hypercall2(int, xen_version, cmd, arg);
   6.143 -}
   6.144 -
   6.145 -static __inline int
   6.146 -HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   6.147 -{
   6.148 -	return _hypercall3(int, grant_table_op, cmd, uop, count);
   6.149 -}
   6.150 -
   6.151 -static __inline int
   6.152 -HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   6.153 -{
   6.154 -	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   6.155 -}
   6.156 -
   6.157 -static __inline int
   6.158 -HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   6.159 -{
   6.160 -	return _hypercall3(int, console_io, cmd, count, string);
   6.161 -}
   6.162 -
   6.163 -static __inline int
   6.164 -HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   6.165 -{
   6.166 -  return _hypercall2(unsigned long, hvm_op, op, arg);
   6.167 -}
   6.168 -
   6.169 -static __inline int
   6.170 -HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.171 -{
   6.172 -	return _hypercall2(int, event_channel_op, cmd, arg);
   6.173 -}
   6.174 -
   6.175 +        char *stub_addr;                                        \
   6.176 +        stub_addr = xpdd->hypercall_stubs;                      \
   6.177 +        asm volatile (                                          \
   6.178 +                HYPERCALL_STR(name)                             \
   6.179 +                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
   6.180 +                : "1" ((long)(a1)), "2" ((long)(a2))            \
   6.181 +                : "memory" );                                   \
   6.182 +        (type)__res;                                            \
   6.183 +})
   6.184 +
   6.185 +#define _hypercall3(type, name, a1, a2, a3)			\
   6.186 +({								\
   6.187 +	long __res, __ign1, __ign2, __ign3;			\
   6.188 +	asm volatile (						\
   6.189 +		HYPERCALL_STR(name)				\
   6.190 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
   6.191 +		"=d" (__ign3)					\
   6.192 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   6.193 +		"3" ((long)(a3))				\
   6.194 +		: "memory" );					\
   6.195 +	(type)__res;						\
   6.196 +})
   6.197 +
   6.198 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
   6.199 +({								\
   6.200 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
   6.201 +	asm volatile (						\
   6.202 +		HYPERCALL_STR(name)				\
   6.203 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
   6.204 +		"=d" (__ign3), "=S" (__ign4)			\
   6.205 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   6.206 +		"3" ((long)(a3)), "4" ((long)(a4))		\
   6.207 +		: "memory" );					\
   6.208 +	(type)__res;						\
   6.209 +})
   6.210 +
   6.211 +static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
   6.212 +                         unsigned int *ecx, unsigned int *edx)
   6.213 +{
   6.214 +  __asm__("cpuid"
   6.215 +          : "=a" (*eax),
   6.216 +            "=b" (*ebx),
   6.217 +            "=c" (*ecx),
   6.218 +            "=d" (*edx)
   6.219 +          : "0" (op));
   6.220 +}
   6.221 +
   6.222 +static __inline void __cpuid(uint32_t output[4], uint32_t op)
   6.223 +{
   6.224 +  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
   6.225 +}
   6.226 +
   6.227 +static __inline void __writemsr(uint32_t msr, uint64_t value)
   6.228 +{
   6.229 +  uint32_t hi, lo;
   6.230 +  hi = value >> 32;
   6.231 +  lo = value & 0xFFFFFFFF;
   6.232 +
   6.233 +  __asm__ __volatile__("wrmsr"
   6.234 +                       : /* no outputs */
   6.235 +                       : "c" (msr), "a" (lo), "d" (hi));
   6.236 +}
   6.237 +
   6.238 +static __inline int
   6.239 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.240 +{
   6.241 +  return _hypercall2(int, memory_op, cmd, arg);
   6.242 +}
   6.243 +
   6.244 +static __inline int
   6.245 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.246 +{
   6.247 +  return _hypercall2(int, sched_op, cmd, arg);
   6.248 +}
   6.249 +
   6.250 +static __inline int
   6.251 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.252 +{
   6.253 +  return _hypercall2(int, xen_version, cmd, arg);
   6.254 +}
   6.255 +
   6.256 +static __inline int
   6.257 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   6.258 +{
   6.259 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   6.260 +}
   6.261 +
   6.262 +static __inline int
   6.263 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   6.264 +{
   6.265 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   6.266 +}
   6.267 +
   6.268 +static __inline int
   6.269 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   6.270 +{
   6.271 +	return _hypercall3(int, console_io, cmd, count, string);
   6.272 +}
   6.273 +
   6.274 +static __inline int
   6.275 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   6.276 +{
   6.277 +  return _hypercall2(unsigned long, hvm_op, op, arg);
   6.278 +}
   6.279 +
   6.280 +static __inline int
   6.281 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   6.282 +{
   6.283 +	return _hypercall2(int, event_channel_op, cmd, arg);
   6.284 +}
   6.285 +
     7.1 --- a/xenpci/makefile.mingw	Sun Jun 22 19:40:44 2008 +1000
     7.2 +++ b/xenpci/makefile.mingw	Sun Jun 22 19:51:47 2008 +1000
     7.3 @@ -1,9 +1,10 @@
     7.4 -CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public
     7.5 +CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public -Wno-multichar -Wno-unknown-pragmas
     7.6  
     7.7 -xenpci.sys: xenpci.c 
     7.8 +xenpci.sys: xenpci.c xenbus.c evtchn.c
     7.9  	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal
    7.10  
    7.11  test.exe: test.c kexec.h
    7.12  	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s $^ -lkernel32
    7.13  
    7.14  all: xenpci.sys
    7.15 +
     8.1 --- a/xenpci/memory.c	Sun Jun 22 19:40:44 2008 +1000
     8.2 +++ b/xenpci/memory.c	Sun Jun 22 19:51:47 2008 +1000
     8.3 @@ -1,9 +1,52 @@
     8.4  #include "xenpci.h"
     8.5 -#include <hypercall.h>
     8.6  
     8.7 -static pgentry_t *demand_map_pgt;
     8.8 +//static pgentry_t *demand_map_pgt;
     8.9  static void *demand_map_area_start;
    8.10 +
    8.11 +NTSTATUS
    8.12 +hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
    8.13 +{
    8.14 +  DWORD32 cpuid_output[4];
    8.15 +  char xensig[13];
    8.16 +  ULONG i;
    8.17 +  ULONG pages;
    8.18 +  ULONG msr;  
    8.19  
    8.20 +  __cpuid(cpuid_output, 0x40000000);
    8.21 +  *(ULONG*)(xensig + 0) = cpuid_output[1];
    8.22 +  *(ULONG*)(xensig + 4) = cpuid_output[2];
    8.23 +  *(ULONG*)(xensig + 8) = cpuid_output[3];
    8.24 +  xensig[12] = '\0';
    8.25 +  KdPrint((__DRIVER_NAME " Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
    8.26 +
    8.27 +  __cpuid(cpuid_output, 0x40000002);
    8.28 +  pages = cpuid_output[0];
    8.29 +  msr = cpuid_output[1];
    8.30 +  //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
    8.31 +
    8.32 +  xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
    8.33 +  KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
    8.34 +
    8.35 +  if (!xpdd->hypercall_stubs)
    8.36 +    return 1;
    8.37 +  for (i = 0; i < pages; i++) {
    8.38 +    ULONGLONG pfn;
    8.39 +    pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
    8.40 +    KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
    8.41 +    __writemsr(msr, (pfn << PAGE_SHIFT) + i);
    8.42 +  }
    8.43 +  return STATUS_SUCCESS;
    8.44 +}
    8.45 +
    8.46 +NTSTATUS
    8.47 +hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
    8.48 +{
    8.49 +  ExFreePoolWithTag(xpdd->hypercall_stubs, XENPCI_POOL_TAG);
    8.50 +
    8.51 +  return STATUS_SUCCESS;
    8.52 +}
    8.53 +
    8.54 +#if 0
    8.55  PVOID
    8.56  map_frames(PULONG f, ULONG n)
    8.57  {
    8.58 @@ -38,3 +81,4 @@ map_frames(PULONG f, ULONG n)
    8.59      return (PVOID)(ULONG)((ULONG)demand_map_area_start + x * PAGE_SIZE);
    8.60    }
    8.61  }
    8.62 +#endif
     9.1 --- a/xenpci/sources	Sun Jun 22 19:40:44 2008 +1000
     9.2 +++ b/xenpci/sources	Sun Jun 22 19:51:47 2008 +1000
     9.3 @@ -5,4 +5,4 @@ INF_NAME=$(TARGETNAME)
     9.4  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
     9.5  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib
     9.6  AMD64_SOURCES=hypercall.asm swint.asm
     9.7 -SOURCES=xenpci.c xenpci_fdo.c xenpci_pdo.c evtchn.c gnttbl.c xenbus.c
     9.8 \ No newline at end of file
     9.9 +SOURCES=xenpci.c xenpci_fdo.c xenpci_pdo.c evtchn.c gnttbl.c xenbus.c memory.c
    9.10 \ No newline at end of file
    10.1 --- a/xenpci/xenbus.c	Sun Jun 22 19:40:44 2008 +1000
    10.2 +++ b/xenpci/xenbus.c	Sun Jun 22 19:51:47 2008 +1000
    10.3 @@ -29,11 +29,11 @@ struct write_req {
    10.4      unsigned len;
    10.5  };
    10.6  
    10.7 -static void
    10.8 +static DDKAPI void
    10.9  XenBus_ReadThreadProc(PVOID StartContext);
   10.10 -static void
   10.11 +static DDKAPI void
   10.12  XenBus_WatchThreadProc(PVOID StartContext);
   10.13 -static BOOLEAN
   10.14 +static DDKAPI BOOLEAN
   10.15  XenBus_Interrupt(PKINTERRUPT Interrupt, PVOID ServiceContext);
   10.16  
   10.17  static int allocate_xenbus_id(PXENPCI_DEVICE_DATA xpdd)
   10.18 @@ -442,7 +442,7 @@ XenBus_List(
   10.19    return NULL;
   10.20  }
   10.21  
   10.22 -static void
   10.23 +static DDKAPI void
   10.24  XenBus_ReadThreadProc(PVOID StartContext)
   10.25  {
   10.26    int NewWriteIndex;
   10.27 @@ -518,7 +518,7 @@ XenBus_ReadThreadProc(PVOID StartContext
   10.28    }
   10.29  }
   10.30  
   10.31 -static void
   10.32 +static DDKAPI void
   10.33  XenBus_WatchThreadProc(PVOID StartContext)
   10.34  {
   10.35    int index;
   10.36 @@ -802,7 +802,7 @@ XenBus_EndTransaction(
   10.37    return NULL;
   10.38  }
   10.39  
   10.40 -static BOOLEAN
   10.41 +static DDKAPI BOOLEAN
   10.42  XenBus_Interrupt(PKINTERRUPT Interrupt, PVOID ServiceContext)
   10.43  {
   10.44    PXENPCI_DEVICE_DATA xpdd = ServiceContext;
    11.1 --- a/xenpci/xenpci.c	Sun Jun 22 19:40:44 2008 +1000
    11.2 +++ b/xenpci/xenpci.c	Sun Jun 22 19:51:47 2008 +1000
    11.3 @@ -24,15 +24,14 @@ Foundation, Inc., 51 Franklin Street, Fi
    11.4  #define SHUTDOWN_PATH "control/shutdown"
    11.5  #define BALLOON_PATH "memory/target"
    11.6  
    11.7 +#ifdef ALLOC_PRAGMA
    11.8  DRIVER_INITIALIZE DriverEntry;
    11.9 -
   11.10 -#ifdef ALLOC_PRAGMA
   11.11  #pragma alloc_text (INIT, DriverEntry)
   11.12  #endif
   11.13  
   11.14  #pragma warning(disable : 4200) // zero-sized array
   11.15  
   11.16 -static NTSTATUS
   11.17 +static DDKAPI NTSTATUS
   11.18  XenPci_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   11.19  {
   11.20    NTSTATUS status;
   11.21 @@ -46,7 +45,7 @@ XenPci_Pnp(PDEVICE_OBJECT device_object,
   11.22    return status;
   11.23  }
   11.24  
   11.25 -static NTSTATUS
   11.26 +static DDKAPI NTSTATUS
   11.27  XenPci_Power(PDEVICE_OBJECT device_object, PIRP irp)
   11.28  {
   11.29    NTSTATUS status;
   11.30 @@ -60,7 +59,7 @@ XenPci_Power(PDEVICE_OBJECT device_objec
   11.31    return status;
   11.32  }
   11.33  
   11.34 -static NTSTATUS
   11.35 +static DDKAPI NTSTATUS
   11.36  XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
   11.37  {
   11.38    NTSTATUS status;
   11.39 @@ -74,7 +73,7 @@ XenPci_Irp_Create(PDEVICE_OBJECT device_
   11.40    return status;
   11.41  }
   11.42  
   11.43 -static NTSTATUS
   11.44 +static DDKAPI NTSTATUS
   11.45  XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
   11.46  {
   11.47    NTSTATUS status;
   11.48 @@ -88,7 +87,7 @@ XenPci_Irp_Close(PDEVICE_OBJECT device_o
   11.49    return status;
   11.50  }
   11.51  
   11.52 -static NTSTATUS
   11.53 +static DDKAPI NTSTATUS
   11.54  XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
   11.55  {
   11.56    NTSTATUS status;
   11.57 @@ -102,7 +101,7 @@ XenPci_Irp_Read(PDEVICE_OBJECT device_ob
   11.58    return status;
   11.59  }
   11.60  
   11.61 -static NTSTATUS
   11.62 +static DDKAPI NTSTATUS
   11.63  XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
   11.64  {
   11.65    NTSTATUS status;
   11.66 @@ -116,7 +115,7 @@ XenPci_Irp_Cleanup(PDEVICE_OBJECT device
   11.67    return status;
   11.68  }
   11.69  
   11.70 -static NTSTATUS
   11.71 +static DDKAPI NTSTATUS
   11.72  XenPci_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
   11.73  {
   11.74    NTSTATUS status;
   11.75 @@ -215,4 +214,4 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   11.76    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   11.77  
   11.78    return status;
   11.79 -}
   11.80 \ No newline at end of file
   11.81 +}
    12.1 --- a/xenpci/xenpci.h	Sun Jun 22 19:40:44 2008 +1000
    12.2 +++ b/xenpci/xenpci.h	Sun Jun 22 19:51:47 2008 +1000
    12.3 @@ -24,8 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fi
    12.4  #define EISCONN 127
    12.5  
    12.6  #include <ntddk.h>
    12.7 -
    12.8 -#ifndef __MINGW32__
    12.9 +
   12.10 +#ifdef __MINGW32__
   12.11 +#define KeMemoryBarrier() asm("mfence;")
   12.12 +#else
   12.13 +#define DDKAPI
   12.14  #include <wdm.h>
   12.15  //#include <wdf.h>
   12.16  #include <initguid.h>
   12.17 @@ -247,7 +250,11 @@ typedef struct
   12.18    PXENPCI_PDO_DEVICE_DATA context;
   12.19  } XEN_CHILD, *PXEN_CHILD;
   12.20  
   12.21 +#ifdef __GNUC__
   12.22 +#define SWINT(x) case x: asm ("int x"); break;
   12.23 +#else
   12.24  #define SWINT(x) case x: __asm { int x } break;
   12.25 +#endif
   12.26  
   12.27  #if defined(_X86_)
   12.28  static __inline VOID
   12.29 @@ -306,9 +313,6 @@ sw_interrupt(UCHAR intno)
   12.30    
   12.31  #include "hypercall.h"
   12.32  
   12.33 -typedef unsigned long xenbus_transaction_t;
   12.34 -typedef uint32_t XENSTORE_RING_IDX;
   12.35 -
   12.36  #define XBT_NIL ((xenbus_transaction_t)0)
   12.37  
   12.38  static __inline VOID
   12.39 @@ -318,6 +322,11 @@ XenPci_FreeMem(PVOID Ptr)
   12.40  }
   12.41  
   12.42  NTSTATUS
   12.43 +hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd);
   12.44 +NTSTATUS
   12.45 +hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd);
   12.46 +
   12.47 +NTSTATUS
   12.48  XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
   12.49  NTSTATUS
   12.50  XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp);