root/include/asm-ppc/bitops.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. set_bit
  2. change_bit
  3. clear_bit
  4. test_bit

   1 #ifndef _ASM_PPC_BITOPS_H_
   2 #define _ASM_PPC_BITOPS_H_
   3 
   4 /*
   5  * For the benefit of those who are trying to port Linux to another
   6  * architecture, here are some C-language equivalents.  You should
   7  * recode these in the native assembly language, if at all possible.
   8  * To guarantee atomicity, these routines call cli() and sti() to
   9  * disable interrupts while they operate.  (You have to provide inline
  10  * routines to cli() and sti().)
  11  *
  12  * Also note, these routines assume that you have 32 bit integers.
  13  * You will have to change this if you are trying to port Linux to the
  14  * Alpha architecture or to a Cray.  :-)
  15  * 
  16  * C language equivalents written by Theodore Ts'o, 9/26/92
  17  */
  18 
  19 #include "asm/system.h"  /* For cli/sti declaration */
  20 
  21 #define BIT(n) 1<<(n&0x1F)
  22 typedef unsigned long BITFIELD;
  23 
  24 extern __inline__ int set_bit(int nr, void * add)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 /*extern __inline__ int set_bit(int nr, BITFIELD * addr)*/
  26 {
  27        int      mask, oldbit;
  28   BITFIELD *addr = add;
  29        
  30         int s = _disable_interrupts();
  31         addr += nr >> 5;
  32         mask = BIT(nr);
  33         oldbit = (mask & *addr) != 0;
  34         *addr |= mask;
  35         _enable_interrupts(s);
  36 
  37         
  38         return oldbit;
  39 }
  40 
  41 
  42 /*extern __inline__ int change_bit(int nr, BITFIELD *addr)*/
  43 extern __inline__ int change_bit(int nr, void *add)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45         BITFIELD *addr = add;
  46         int     mask, retval;
  47         int s = _disable_interrupts();
  48         addr += nr >> 5;
  49         mask = BIT(nr);
  50         retval = (mask & *addr) != 0;
  51         *addr ^= mask;
  52         _enable_interrupts(s);
  53         return retval;
  54 }
  55 
  56 
  57 /*extern __inline__ int clear_bit(int nr, BITFIELD *addr2)*/
  58 extern __inline__ int clear_bit(int nr, void *add)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         BITFIELD *addr = add;
  61         int     mask, retval;
  62         int s = _disable_interrupts();
  63         addr += nr >> 5;
  64         mask = BIT(nr);
  65         retval = (mask & *addr) != 0;
  66         *addr &= ~mask;
  67         _enable_interrupts(s);
  68         return retval;
  69 }
  70 
  71 extern __inline__ int test_bit(int nr, void *add)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 /*extern __inline__ int test_bit(int nr, BITFIELD *addr)*/
  73 {
  74         int     mask;
  75         BITFIELD *addr = add;
  76 
  77         addr += nr >> 5;
  78         mask = BIT(nr);
  79         return ((mask & *addr) != 0);
  80 }
  81 
  82 #endif /* _ASM_PPC_BITOPS_H */
  83 
  84 

/* [previous][next][first][last][top][bottom][index][help] */