win-pvdrivers

changeset 338:72acaf6e4668

more mingw fixes for evtchn.c
author Andy Grover <andy.grover@oracle.com>
date Sun Jun 22 17:31:23 2008 -0700 (2008-06-22)
parents 52533409dbbd
children 9e3eb0ed57b1
files xenpci/evtchn.c xenpci/hypercall_x86_mingw.h xenpci/makefile.mingw xenpci/memory.c xenpci/xenpci.h
line diff
     1.1 --- a/xenpci/evtchn.c	Thu Jun 19 17:20:16 2008 -0700
     1.2 +++ b/xenpci/evtchn.c	Sun Jun 22 17:31:23 2008 -0700
     1.3 @@ -19,11 +19,66 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  
     1.5  #include "xenpci.h"
     1.6  
     1.7 -#if defined(_WIN32)
     1.8 +#if defined(__MINGW32__)
     1.9 +
    1.10 +/* mingw-runtime 3.13 is buggy */
    1.11 +#undef KeGetCurrentProcessorNumber
    1.12 +#define KeGetCurrentProcessorNumber() \
    1.13 +  ((ULONG)KeGetCurrentKPCR()->Number)
    1.14 +
    1.15 +/* mingw-runtime 3.13 lacks certain lowlevel intrinsics */
    1.16 +NTSTATUS BitScanForward(unsigned long *index, unsigned long mask)
    1.17 +{
    1.18 +  int i;
    1.19 +
    1.20 +  for (i = 0; i < sizeof(unsigned long)*8; i++)
    1.21 +  {
    1.22 +    if (mask & (1 << i)) {
    1.23 +      *index = i + 1;
    1.24 +      return 1;
    1.25 +    }
    1.26 +  }
    1.27 +  return 0;
    1.28 +}
    1.29 +
    1.30 +/**
    1.31 +  From linux include/asm-i386/bitops.h
    1.32 + */
    1.33 +static inline int test_and_set_bit(int nr, volatile long * addr)
    1.34 +{
    1.35 +  int oldbit;
    1.36 +
    1.37 +  __asm__ __volatile__( "lock;"
    1.38 +    "btsl %2,%1\n\tsbbl %0,%0"
    1.39 +    :"=r" (oldbit),"+m" (*(volatile long *) addr)
    1.40 +    :"Ir" (nr) : "memory");
    1.41 +  
    1.42 +  return oldbit;
    1.43 +}
    1.44 +static inline int test_and_clear_bit(int nr, volatile long * addr)
    1.45 +{
    1.46 +  int oldbit;
    1.47 +
    1.48 +  __asm__ __volatile__( "lock;"
    1.49 +    "btrl %2,%1\n\tsbbl %0,%0"
    1.50 +    :"=r" (oldbit),"+m" (*(volatile long *) addr)
    1.51 +    :"Ir" (nr) : "memory");
    1.52 +  return oldbit;
    1.53 +}
    1.54 +
    1.55 +  #define xchg(p1, p2) InterlockedExchange((xen_long_t * volatile)p1, p2)
    1.56 +  #define synch_clear_bit(p1, p2) test_and_clear_bit(p1, p2)
    1.57 +  #define synch_set_bit(p1, p2) test_and_set_bit(p1, p2)
    1.58 +  #define bit_scan_forward(p1, p2) BitScanForward(p1, p2)
    1.59 +
    1.60 +#elif defined(_WIN32)
    1.61    #define xchg(p1, p2) _InterlockedExchange(p1, p2)
    1.62    #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
    1.63    #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    1.64    #define bit_scan_forward(p1, p2) _BitScanForward(p1, p2)
    1.65 +
    1.66 +
    1.67 +
    1.68  #else
    1.69    #define xchg(p1, p2) _InterlockedExchange64(p1, p2)
    1.70    #define synch_clear_bit(p1, p2) _interlockedbittestandreset64(p2, p1)
    1.71 @@ -31,7 +86,7 @@ Foundation, Inc., 51 Franklin Street, Fi
    1.72    #define bit_scan_forward(p1, p2) _BitScanForward64(p1, p2)
    1.73  #endif
    1.74  
    1.75 -static VOID
    1.76 +static DDKAPI VOID
    1.77  EvtChn_DpcBounce(PRKDPC Dpc, PVOID Context, PVOID SystemArgument1, PVOID SystemArgument2)
    1.78  {
    1.79    ev_action_t *action = Context;
    1.80 @@ -46,7 +101,7 @@ EvtChn_DpcBounce(PRKDPC Dpc, PVOID Conte
    1.81      action->ServiceRoutine(NULL, action->ServiceContext);
    1.82  }
    1.83  
    1.84 -static BOOLEAN
    1.85 +static DDKAPI BOOLEAN
    1.86  EvtChn_Interrupt(PKINTERRUPT Interrupt, PVOID Context)
    1.87  {
    1.88    int cpu = KeGetCurrentProcessorNumber() & (MAX_VIRT_CPUS - 1);
    1.89 @@ -194,24 +249,29 @@ EvtChn_Unbind(PVOID Context, evtchn_port
    1.90  }
    1.91  
    1.92  NTSTATUS
    1.93 -EvtChn_Mask(PXENPCI_DEVICE_DATA xpdd, evtchn_port_t Port)
    1.94 +EvtChn_Mask(PVOID Context, evtchn_port_t Port)
    1.95  {
    1.96 +  PXENPCI_DEVICE_DATA xpdd = Context;
    1.97 +
    1.98    synch_set_bit(Port,
    1.99      (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[0]);
   1.100    return STATUS_SUCCESS;
   1.101  }
   1.102  
   1.103  NTSTATUS
   1.104 -EvtChn_Unmask(PXENPCI_DEVICE_DATA xpdd , evtchn_port_t Port)
   1.105 +EvtChn_Unmask(PVOID Context, evtchn_port_t Port)
   1.106  {
   1.107 +  PXENPCI_DEVICE_DATA xpdd = Context;
   1.108 +
   1.109    synch_clear_bit(Port,
   1.110      (volatile xen_long_t *)&xpdd->shared_info_area->evtchn_mask[0]);
   1.111    return STATUS_SUCCESS;
   1.112  }
   1.113  
   1.114  NTSTATUS
   1.115 -EvtChn_Notify(PXENPCI_DEVICE_DATA xpdd, evtchn_port_t Port)
   1.116 +EvtChn_Notify(PVOID Context, evtchn_port_t Port)
   1.117  {
   1.118 +  PXENPCI_DEVICE_DATA xpdd = Context;
   1.119    struct evtchn_send send;
   1.120  
   1.121    send.port = Port;
     2.1 --- a/xenpci/hypercall_x86_mingw.h	Thu Jun 19 17:20:16 2008 -0700
     2.2 +++ b/xenpci/hypercall_x86_mingw.h	Sun Jun 22 17:31:23 2008 -0700
     2.3 @@ -30,8 +30,8 @@
     2.4  
     2.5  #define _hypercall2(type, name, a1, a2)                         \
     2.6  ({                                                              \
     2.7 -        long __res, __ign1, __ign2;                             \
     2.8 -        char *stub_addr;                                        \
     2.9 +        long __res, __ign1, __ign2;                             \
    2.10 +        char *stub_addr;                                        \
    2.11          stub_addr = xpdd->hypercall_stubs;                      \
    2.12          asm volatile (                                          \
    2.13                  HYPERCALL_STR(name)                             \
     3.1 --- a/xenpci/makefile.mingw	Thu Jun 19 17:20:16 2008 -0700
     3.2 +++ b/xenpci/makefile.mingw	Sun Jun 22 17:31:23 2008 -0700
     3.3 @@ -1,6 +1,6 @@
     3.4  CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public -Wno-multichar -Wno-unknown-pragmas
     3.5  
     3.6 -xenpci.sys: xenpci.c xenbus.c evtchn.c
     3.7 +xenpci.sys: xenpci.c xenbus.c evtchn.c gnttbl.c
     3.8  	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal
     3.9  
    3.10  test.exe: test.c kexec.h
     4.1 --- a/xenpci/memory.c	Thu Jun 19 17:20:16 2008 -0700
     4.2 +++ b/xenpci/memory.c	Sun Jun 22 17:31:23 2008 -0700
     4.3 @@ -2,7 +2,7 @@
     4.4  
     4.5  //static pgentry_t *demand_map_pgt;
     4.6  static void *demand_map_area_start;
     4.7 -
     4.8 +
     4.9  NTSTATUS
    4.10  hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
    4.11  {
    4.12 @@ -46,7 +46,7 @@ hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
    4.13    return STATUS_SUCCESS;
    4.14  }
    4.15  
    4.16 -#if 0
    4.17 +#if 0
    4.18  PVOID
    4.19  map_frames(PULONG f, ULONG n)
    4.20  {
     5.1 --- a/xenpci/xenpci.h	Thu Jun 19 17:20:16 2008 -0700
     5.2 +++ b/xenpci/xenpci.h	Sun Jun 22 17:31:23 2008 -0700
     5.3 @@ -24,11 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fi
     5.4  #define EISCONN 127
     5.5  
     5.6  #include <ntddk.h>
     5.7 -
     5.8 -#ifdef __MINGW32__
     5.9 +
    5.10 +#ifdef __MINGW32__
    5.11  #define KeMemoryBarrier() asm("mfence;")
    5.12  #else
    5.13 -#define DDKAPI
    5.14 +#define DDKAPI
    5.15  #include <wdm.h>
    5.16  //#include <wdf.h>
    5.17  #include <initguid.h>
    5.18 @@ -251,9 +251,9 @@ typedef struct
    5.19  } XEN_CHILD, *PXEN_CHILD;
    5.20  
    5.21  #ifdef __GNUC__
    5.22 -#define SWINT(x) case x: asm ("int x"); break;
    5.23 +#define SWINT(x) if (intno == x) { asm ("int $"#x";"); return;}
    5.24  #else
    5.25 -#define SWINT(x) case x: __asm { int x } break;
    5.26 +#define SWINT(x) if (intno == x) { __asm { int x } return; }
    5.27  #endif
    5.28  
    5.29  #if defined(_X86_)
    5.30 @@ -261,8 +261,6 @@ static __inline VOID
    5.31  sw_interrupt(UCHAR intno)
    5.32  {
    5.33    //KdPrint((__DRIVER_NAME "     Calling interrupt %02X\n", intno));
    5.34 -  switch (intno)
    5.35 -  {
    5.36    SWINT(0x10) SWINT(0x11) SWINT(0x12) SWINT(0x13) SWINT(0x14) SWINT(0x15) SWINT(0x16) SWINT(0x17)
    5.37    SWINT(0x18) SWINT(0x19) SWINT(0x1A) SWINT(0x1B) SWINT(0x1C) SWINT(0x1D) SWINT(0x1E) SWINT(0x1F)
    5.38    SWINT(0x20) SWINT(0x21) SWINT(0x22) SWINT(0x23) SWINT(0x24) SWINT(0x25) SWINT(0x26) SWINT(0x27)
    5.39 @@ -294,11 +292,9 @@ sw_interrupt(UCHAR intno)
    5.40    SWINT(0xF0) SWINT(0xF1) SWINT(0xF2) SWINT(0xF3) SWINT(0xF4) SWINT(0xF5) SWINT(0xF6) SWINT(0xF7)
    5.41    SWINT(0xF8) SWINT(0xF9) SWINT(0xFA) SWINT(0xFB) SWINT(0xFC) SWINT(0xFD) SWINT(0xFE) SWINT(0xFF)
    5.42  
    5.43 -  default:
    5.44 -    KdPrint((__DRIVER_NAME "     interrupt %02X not set up. Blame James.\n", intno));
    5.45 -    KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, (ULONG)intno, 0x00000000, 0x00000000);
    5.46 -    break;
    5.47 -  }
    5.48 +  /* not found */
    5.49 +  KdPrint((__DRIVER_NAME "     interrupt %02X not set up. Blame James.\n", intno));
    5.50 +  KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, (ULONG)intno, 0x00000000, 0x00000000);
    5.51  }
    5.52  #else
    5.53  VOID _sw_interrupt(UCHAR);