win-pvdrivers

changeset 391:8e10579159a0

implement some macros for common entry/exit kdprints etc. msvc and gcc have different defines so this will make life with 2 compile environments easier.
I couldn't test on ddk before checking in, will try it tonight and fix compile if needed.
author Andy Grover <andy.grover@oracle.com>
date Tue Jul 15 18:27:06 2008 -0700 (2008-07-15)
parents 46b6fa5bb7ad
children acff0605d6d6
files common/include/xen_windows.h mingw/mingw_extras.c mingw/mingw_extras.h xennet/makefile.mingw xennet/xennet.c xennet/xennet_oid.c xennet/xennet_rx.c xennet/xennet_tx.c
line diff
     1.1 --- a/common/include/xen_windows.h	Mon Jul 14 23:04:23 2008 +1000
     1.2 +++ b/common/include/xen_windows.h	Tue Jul 15 18:27:06 2008 -0700
     1.3 @@ -59,7 +59,21 @@ typedef unsigned long xenbus_transaction
     1.4  #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
     1.5  
     1.6  #define wmb() KeMemoryBarrier()
     1.7 -#define mb() KeMemoryBarrier()
     1.8 +#define mb() KeMemoryBarrier()
     1.9 +
    1.10 +#define FUNCTION_ENTER()      KdPrint((__DRIVER_NAME " --> %s\n", __FUNCTION__))
    1.11 +#define FUNCTION_EXIT()       KdPrint((__DRIVER_NAME " <-- %s\n", __FUNCTION__))
    1.12 +#define FUNCTION_ERROR_EXIT() KdPrint((__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__))
    1.13 +#define FUNCTION_CALLED()     KdPrint((__DRIVER_NAME " %s called\n", __FUNCTION__))
    1.14 +#ifdef __MINGW32__
    1.15 +#define FUNCTION_MSG(format, args...) KdPrint((__DRIVER_NAME " %s called:" format, \
    1.16 +  __FUNCTION__, ##args))
    1.17 +#else
    1.18 +#define FUNCTION_MSG(_x_)     { \
    1.19 +    KdPrint((__DRIVER_NAME " %s called: ", __FUNCTION__));          \
    1.20 +    KdPrint((_x_))              \
    1.21 +  }
    1.22 +#endif
    1.23  
    1.24  static __inline char **
    1.25  SplitString(char *String, char Split, int MaxParts, int *Count)
     2.1 --- a/mingw/mingw_extras.c	Mon Jul 14 23:04:23 2008 +1000
     2.2 +++ b/mingw/mingw_extras.c	Tue Jul 15 18:27:06 2008 -0700
     2.3 @@ -18,12 +18,12 @@ NTSTATUS bit_scan_forward(unsigned long 
     2.4    {
     2.5      if (mask & (1 << i)) {
     2.6        *index = i + 1;
     2.7 -      KdPrint((__FUNC__ __LINE__ " Check that I work as expected!\n"));
     2.8 +      KdPrint(("file %s line %s Check that I work as expected!\n", __FILE__, __LINE__));
     2.9        return 1;
    2.10      }
    2.11    }
    2.12  
    2.13 -  KdPrint((__FUNC__ __LINE__ " Check that I work as expected!\n"));
    2.14 +  KdPrint(("file %s line %s Check that I work as expected!\n", __FILE__, __LINE__));
    2.15  
    2.16    return 0;
    2.17  }
    2.18 @@ -40,7 +40,7 @@ int synch_set_bit(int nr, volatile long 
    2.19      :"=r" (oldbit),"+m" (*(volatile long *) addr)
    2.20      :"Ir" (nr) : "memory");
    2.21  
    2.22 -  KdPrint((__FUNC__ " Check that I work as expected!\n"));
    2.23 +  KdPrint(("file %s line %s Check that I work as expected!\n", __FILE__, __LINE__));
    2.24  
    2.25    return oldbit;
    2.26  }
    2.27 @@ -54,7 +54,7 @@ int synch_clear_bit(int nr, volatile lon
    2.28      :"=r" (oldbit),"+m" (*(volatile long *) addr)
    2.29      :"Ir" (nr) : "memory");
    2.30  
    2.31 -  KdPrint((__FUNC__ " Check that I work as expected!\n"));
    2.32 +  KdPrint(("file %s line %s Check that I work as expected!\n", __FILE__, __LINE__));
    2.33  
    2.34    return oldbit;
    2.35  }
     3.1 --- a/mingw/mingw_extras.h	Mon Jul 14 23:04:23 2008 +1000
     3.2 +++ b/mingw/mingw_extras.h	Tue Jul 15 18:27:06 2008 -0700
     3.3 @@ -1,5 +1,7 @@
     3.4  #include <stdio.h>
     3.5  
     3.6 +#define __FUNCTION__ __func__
     3.7 +
     3.8  NTSTATUS bit_scan_forward(unsigned long *index, unsigned long mask);
     3.9  int synch_set_bit(int nr, volatile long * addr);
    3.10  int synch_clear_bit(int nr, volatile long * addr);
     4.1 --- a/xennet/makefile.mingw	Mon Jul 14 23:04:23 2008 +1000
     4.2 +++ b/xennet/makefile.mingw	Tue Jul 15 18:27:06 2008 -0700
     4.3 @@ -1,7 +1,7 @@
     4.4  W32API_PATH=/home/agrover/temp/w32api-3.11
     4.5  
     4.6 -CFLAGS = -Wall -L$(W32API_PATH)/lib/ddk -I$(W32API_PATH)/include/ddk -I../common/include -I../common/include/public -Wno-multichar -Wno-unknown-pragmas
     4.7 +CFLAGS = -g -Wall -L$(W32API_PATH)/lib/ddk -I$(W32API_PATH)/include/ddk -I../common/include -I../common/include/public -Wno-multichar -Wno-unknown-pragmas -DDBG
     4.8  
     4.9  xennet.sys: xennet.c xennet_oid.c xennet_tx.c xennet_rx.c xennet_common.c ../mingw/mingw_extras.c
    4.10 -	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal -lndis
    4.11 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -shared -Wl,--entry,_DriverEntry@8 -nostartfiles -nostdlib $^ -lntoskrnl -lhal -lndis
    4.12  
     5.1 --- a/xennet/xennet.c	Mon Jul 14 23:04:23 2008 +1000
     5.2 +++ b/xennet/xennet.c	Tue Jul 15 18:27:06 2008 -0700
     5.3 @@ -127,12 +127,12 @@ XenNet_InterruptIsr(
     5.4  {
     5.5    struct xennet_info *xi = MiniportAdapterContext;
     5.6    
     5.7 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     5.8 +  //FUNCTION_ENTER();
     5.9  
    5.10    *QueueMiniportHandleInterrupt = (BOOLEAN)!!xi->connected;
    5.11    *InterruptRecognized = FALSE; /* we can't be sure here... */
    5.12  
    5.13 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.14 +  //FUNCTION_EXIT();
    5.15  }
    5.16  
    5.17  static DDKAPI VOID
    5.18 @@ -140,13 +140,13 @@ XenNet_InterruptDpc(NDIS_HANDLE  Minipor
    5.19  {
    5.20    struct xennet_info *xi = MiniportAdapterContext;
    5.21  
    5.22 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    5.23 +  //FUNCTION_ENTER();
    5.24    if (xi->connected)
    5.25    {
    5.26      XenNet_TxBufferGC(xi);
    5.27      XenNet_RxBufferCheck(xi);
    5.28    }
    5.29 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.30 +  //FUNCTION_EXIT();
    5.31  }
    5.32  
    5.33  static NDIS_STATUS
    5.34 @@ -205,7 +205,7 @@ XenNet_ConnectBackend(struct xennet_info
    5.35        {
    5.36          KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
    5.37            ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
    5.38 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.39 +        FUNCTION_ERROR_EXIT();
    5.40          return NDIS_STATUS_ADAPTER_NOT_FOUND;
    5.41        }
    5.42        else
    5.43 @@ -294,7 +294,8 @@ XenNet_Init(
    5.44    
    5.45    UNREFERENCED_PARAMETER(OpenErrorStatus);
    5.46  
    5.47 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    5.48 +  FUNCTION_ENTER();
    5.49 +
    5.50    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    5.51  
    5.52    /* deal with medium stuff */
    5.53 @@ -430,7 +431,7 @@ XenNet_Init(
    5.54        {
    5.55          KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
    5.56            ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
    5.57 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.58 +        FUNCTION_ERROR_EXIT();
    5.59          return NDIS_STATUS_FAILURE;
    5.60        }
    5.61        else
    5.62 @@ -559,13 +560,13 @@ XenNet_Init(
    5.63    NdisMInitializeTimer(&xi->resume_timer, xi->adapter_handle, XenResumeCheck_Timer, xi);
    5.64    NdisMSetPeriodicTimer(&xi->resume_timer, 100);
    5.65  
    5.66 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.67 +  FUNCTION_EXIT();
    5.68  
    5.69    return NDIS_STATUS_SUCCESS;
    5.70  
    5.71  err:
    5.72    NdisFreeMemory(xi, 0, 0);
    5.73 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (error path)\n"));
    5.74 +  FUNCTION_ERROR_EXIT();
    5.75    return status;
    5.76  }
    5.77  
    5.78 @@ -582,7 +583,7 @@ XenNet_PnPEventNotify(
    5.79    UNREFERENCED_PARAMETER(InformationBuffer);
    5.80    UNREFERENCED_PARAMETER(InformationBufferLength);
    5.81  
    5.82 -  KdPrint((__FUNCTION__ " called\n"));
    5.83 +  FUNCTION_CALLED();
    5.84  }
    5.85  
    5.86  /* Called when machine is shutting down, so just quiesce the HW and be done fast. */
    5.87 @@ -593,7 +594,7 @@ XenNet_Shutdown(
    5.88  {
    5.89    struct xennet_info *xi = MiniportAdapterContext;
    5.90  
    5.91 -  KdPrint((__FUNCTION__ " called\n"));
    5.92 +  FUNCTION_CALLED();
    5.93  
    5.94    NdisMDeregisterInterrupt(&xi->interrupt);
    5.95  }
    5.96 @@ -609,7 +610,7 @@ XenNet_Halt(
    5.97  //  PVOID if_cxt = xi->XenInterface.InterfaceHeader.Context;
    5.98  //  LARGE_INTEGER timeout;
    5.99  
   5.100 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   5.101 +  FUNCTION_ENTER();
   5.102    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   5.103  
   5.104    // Disables the interrupt
   5.105 @@ -630,10 +631,10 @@ XenNet_Halt(
   5.106  
   5.107    NdisFreeMemory(xi, 0, 0); // <= DISPATCH_LEVEL
   5.108  
   5.109 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   5.110 +  FUNCTION_EXIT();
   5.111  }
   5.112  
   5.113 -NTSTATUS
   5.114 +NTSTATUS DDKAPI
   5.115  DriverEntry(
   5.116    PDRIVER_OBJECT DriverObject,
   5.117    PUNICODE_STRING RegistryPath
   5.118 @@ -643,6 +644,8 @@ DriverEntry(
   5.119    NDIS_HANDLE ndis_wrapper_handle;
   5.120    NDIS_MINIPORT_CHARACTERISTICS mini_chars;
   5.121  
   5.122 +  FUNCTION_ENTER();
   5.123 +
   5.124    RtlZeroMemory(&mini_chars, sizeof(mini_chars));
   5.125  
   5.126    NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
   5.127 @@ -684,5 +687,7 @@ DriverEntry(
   5.128      return status;
   5.129    }
   5.130  
   5.131 +  FUNCTION_EXIT();
   5.132 +
   5.133    return status;
   5.134  }
     6.1 --- a/xennet/xennet_oid.c	Mon Jul 14 23:04:23 2008 +1000
     6.2 +++ b/xennet/xennet_oid.c	Tue Jul 15 18:27:06 2008 -0700
     6.3 @@ -92,7 +92,7 @@ XenNet_QueryInformation(
     6.4    *BytesNeeded = 0;
     6.5    *BytesWritten = 0;
     6.6  
     6.7 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     6.8 +// FUNCTION_ENTER()
     6.9  
    6.10    switch(Oid)
    6.11    {
    6.12 @@ -104,12 +104,12 @@ XenNet_QueryInformation(
    6.13        if (!xi->connected)
    6.14        {
    6.15          temp_data = NdisHardwareStatusInitializing;
    6.16 -        KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " NdisHardwareStatusInitializing\n"));
    6.17 +        FUNCTION_MSG("NdisHardwareStatusInitializing\n");
    6.18        }
    6.19        else
    6.20        {
    6.21          temp_data = NdisHardwareStatusReady;
    6.22 -        KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " NdisHardwareStatusReady\n"));
    6.23 +        FUNCTION_MSG("NdisHardwareStatusReady\n");
    6.24        }
    6.25        break;
    6.26      case OID_GEN_MEDIA_SUPPORTED:
    6.27 @@ -354,14 +354,14 @@ XenNet_QueryInformation(
    6.28  
    6.29    if (!NT_SUCCESS(status))
    6.30    {
    6.31 -  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returned error)\n"));
    6.32 +    // FUNCTION_ERROR_EXIT();
    6.33      return status;
    6.34    }
    6.35  
    6.36    if (len > InformationBufferLength)
    6.37    {
    6.38      *BytesNeeded = len;
    6.39 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (BUFFER_TOO_SHORT %d > %d)\n", len, InformationBufferLength));
    6.40 +    FUNCTION_MSG("(BUFFER_TOO_SHORT %d > %d)\n", len, InformationBufferLength);
    6.41      return NDIS_STATUS_BUFFER_TOO_SHORT;
    6.42    }
    6.43  
     7.1 --- a/xennet/xennet_rx.c	Mon Jul 14 23:04:23 2008 +1000
     7.2 +++ b/xennet/xennet_rx.c	Tue Jul 15 18:27:06 2008 -0700
     7.3 @@ -564,7 +564,7 @@ XenNet_RxInit(xennet_info_t *xi)
     7.4  {
     7.5    int i;
     7.6  
     7.7 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     7.8 +  FUNCTION_ENTER();
     7.9  
    7.10    xi->rx_id_free = NET_RX_RING_SIZE;
    7.11  
    7.12 @@ -579,7 +579,7 @@ XenNet_RxInit(xennet_info_t *xi)
    7.13  
    7.14    XenNet_RxBufferAlloc(xi);
    7.15  
    7.16 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    7.17 +  FUNCTION_EXIT();
    7.18  
    7.19    return TRUE;
    7.20  }
    7.21 @@ -589,7 +589,7 @@ XenNet_RxShutdown(xennet_info_t *xi)
    7.22  {
    7.23    KIRQL OldIrql;
    7.24  
    7.25 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    7.26 +  FUNCTION_ENTER();
    7.27  
    7.28    KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
    7.29  
    7.30 @@ -605,7 +605,7 @@ XenNet_RxShutdown(xennet_info_t *xi)
    7.31  
    7.32    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
    7.33  
    7.34 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    7.35 +  FUNCTION_EXIT();
    7.36  
    7.37    return TRUE;
    7.38  }
     8.1 --- a/xennet/xennet_tx.c	Mon Jul 14 23:04:23 2008 +1000
     8.2 +++ b/xennet/xennet_tx.c	Tue Jul 15 18:27:06 2008 -0700
     8.3 @@ -460,7 +460,7 @@ XenNet_TxShutdown(xennet_info_t *xi)
     8.4    ULONG i;
     8.5    KIRQL OldIrql;
     8.6  
     8.7 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     8.8 +  FUNCTION_ENTER();
     8.9  
    8.10    ASSERT(!xi->connected);
    8.11  
    8.12 @@ -490,7 +490,7 @@ XenNet_TxShutdown(xennet_info_t *xi)
    8.13  
    8.14    KeReleaseSpinLock(&xi->tx_lock, OldIrql);
    8.15  
    8.16 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    8.17 +  FUNCTION_EXIT();
    8.18  
    8.19    return TRUE;
    8.20  }