win-pvdrivers

changeset 379:8c83b0ebcb05

move bit ops to mingw_extras since now xenvbd and evtchn.c are using them. no longer inline but shouldn't matter, eh?
author Andy Grover <andy.grover@oracle.com>
date Wed Jul 09 12:32:12 2008 -0700 (2008-07-09)
parents 9ac05494063f
children 5b2a37528899
files mingw/mingw_extras.c mingw/mingw_extras.h
line diff
     1.1 --- a/mingw/mingw_extras.c	Wed Jul 09 12:31:18 2008 -0700
     1.2 +++ b/mingw/mingw_extras.c	Wed Jul 09 12:32:12 2008 -0700
     1.3 @@ -9,6 +9,55 @@
     1.4  
     1.5  #include <ntddk.h>
     1.6  #include "mingw_extras.h"
     1.7 +
     1.8 +NTSTATUS bit_scan_forward(unsigned long *index, unsigned long mask)
     1.9 +{
    1.10 +  int i;
    1.11 +
    1.12 +  for (i = 0; i < sizeof(unsigned long)*8; i++)
    1.13 +  {
    1.14 +    if (mask & (1 << i)) {
    1.15 +      *index = i + 1;
    1.16 +      KdPrint((__FUNC__ __LINE__ " Check that I work as expected!\n"));
    1.17 +      return 1;
    1.18 +    }
    1.19 +  }
    1.20 +
    1.21 +  KdPrint((__FUNC__ __LINE__ " Check that I work as expected!\n"));
    1.22 +
    1.23 +  return 0;
    1.24 +}
    1.25 +
    1.26 +/**
    1.27 +  From linux include/asm-i386/bitops.h
    1.28 + */
    1.29 +int synch_set_bit(int nr, volatile long * addr)
    1.30 +{
    1.31 +  int oldbit;
    1.32 +
    1.33 +  __asm__ __volatile__( "lock;"
    1.34 +    "btsl %2,%1\n\tsbbl %0,%0"
    1.35 +    :"=r" (oldbit),"+m" (*(volatile long *) addr)
    1.36 +    :"Ir" (nr) : "memory");
    1.37 +
    1.38 +  KdPrint((__FUNC__ " Check that I work as expected!\n"));
    1.39 +
    1.40 +  return oldbit;
    1.41 +}
    1.42 +
    1.43 +int synch_clear_bit(int nr, volatile long * addr)
    1.44 +{
    1.45 +  int oldbit;
    1.46 +
    1.47 +  __asm__ __volatile__( "lock;"
    1.48 +    "btrl %2,%1\n\tsbbl %0,%0"
    1.49 +    :"=r" (oldbit),"+m" (*(volatile long *) addr)
    1.50 +    :"Ir" (nr) : "memory");
    1.51 +
    1.52 +  KdPrint((__FUNC__ " Check that I work as expected!\n"));
    1.53 +
    1.54 +  return oldbit;
    1.55 +}
    1.56  
    1.57  NTSTATUS
    1.58  RtlStringCbPrintfW(
     2.1 --- a/mingw/mingw_extras.h	Wed Jul 09 12:31:18 2008 -0700
     2.2 +++ b/mingw/mingw_extras.h	Wed Jul 09 12:32:12 2008 -0700
     2.3 @@ -1,4 +1,8 @@
     2.4  #include <stdio.h>
     2.5 +
     2.6 +NTSTATUS bit_scan_forward(unsigned long *index, unsigned long mask);
     2.7 +int synch_set_bit(int nr, volatile long * addr);
     2.8 +int synch_clear_bit(int nr, volatile long * addr);
     2.9  
    2.10  /* windows wchar 2 bytes, Linux's is 4! */
    2.11  typedef unsigned short win_wchar_t;