[442] | 1 | #ifndef _ASM_BITOPS_H
|
---|
| 2 | #define _ASM_BITOPS_H
|
---|
[32] | 3 |
|
---|
| 4 | /*
|
---|
| 5 | * Copyright 1992, Linus Torvalds.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * These have to be done with inline assembly: that way the bit-setting
|
---|
| 10 | * is guaranteed to be atomic. All bit operations return 0 if the bit
|
---|
| 11 | * was cleared before the operation and != 0 if it was not.
|
---|
| 12 | *
|
---|
| 13 | * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | /*
|
---|
| 17 | * Function prototypes to keep gcc -Wall happy
|
---|
| 18 | */
|
---|
| 19 | #ifdef __WATCOMC__
|
---|
| 20 | int set_bit(int nr, volatile void * addr);
|
---|
| 21 | #pragma aux set_bit = \
|
---|
| 22 | "bts dword ptr [esi], eax" \
|
---|
| 23 | "setc al" \
|
---|
| 24 | "movzx eax, al" \
|
---|
| 25 | parm [eax] [esi] \
|
---|
| 26 | value [eax]
|
---|
| 27 |
|
---|
| 28 | int clear_bit(int nr, volatile void * addr);
|
---|
| 29 | #pragma aux clear_bit = \
|
---|
| 30 | "btr dword ptr [esi], eax" \
|
---|
| 31 | "setc al" \
|
---|
| 32 | "movzx eax, al" \
|
---|
| 33 | parm [eax] [esi] \
|
---|
| 34 | value [eax]
|
---|
| 35 |
|
---|
| 36 | int change_bit(int nr, volatile void * addr);
|
---|
| 37 | #pragma aux change_bit = \
|
---|
| 38 | "btc dword ptr [esi], eax" \
|
---|
| 39 | "setc al" \
|
---|
| 40 | "movzx eax, al" \
|
---|
| 41 | parm [eax] [esi] \
|
---|
| 42 | value [eax]
|
---|
| 43 |
|
---|
| 44 | #define test_and_set_bit(nr, addr) set_bit(nr, addr)
|
---|
| 45 | #define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
|
---|
| 46 | #define test_and_change_bit(nr, addr) change_bit(nr, addr)
|
---|
| 47 |
|
---|
| 48 | /*
|
---|
| 49 | * ffs: find first bit set. This is defined the same way as
|
---|
| 50 | * the libc and compiler builtin ffs routines, therefore
|
---|
| 51 | * differs in spirit from the above ffz (man ffs).
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | int ffs(int x);
|
---|
| 55 | #pragma aux ffs = \
|
---|
| 56 | "bsf eax, ebx" \
|
---|
| 57 | "jnz @f" \
|
---|
| 58 | "mov eax, -1" \
|
---|
| 59 | "@f:" \
|
---|
| 60 | "inc eax" \
|
---|
| 61 | parm [ebx] \
|
---|
| 62 | value [eax]
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | * ffz = Find First Zero in word. Undefined if no zero exists,
|
---|
| 66 | * so code should check against ~0UL first..
|
---|
| 67 | */
|
---|
| 68 | unsigned long ffz(unsigned long word);
|
---|
| 69 | #pragma aux ffz = \
|
---|
| 70 | "bsf eax, ebx" \
|
---|
| 71 | parm [ebx] \
|
---|
| 72 | value [eax]
|
---|
| 73 |
|
---|
| 74 | //{
|
---|
| 75 | // int r;
|
---|
| 76 | //
|
---|
| 77 | // __asm__("bsfl %1,%0\n\t"
|
---|
| 78 | // "jnz 1f\n\t"
|
---|
| 79 | // "movl $-1,%0\n"
|
---|
| 80 | // "1:" : "=r" (r) : "g" (x));
|
---|
| 81 | // return r+1;
|
---|
| 82 | //}
|
---|
| 83 |
|
---|
| 84 | #else
|
---|
| 85 | extern void set_bit(int nr, volatile void * addr);
|
---|
| 86 | extern void clear_bit(int nr, volatile void * addr);
|
---|
| 87 | extern void change_bit(int nr, volatile void * addr);
|
---|
| 88 | extern int test_and_set_bit(int nr, volatile void * addr);
|
---|
| 89 | extern int test_and_clear_bit(int nr, volatile void * addr);
|
---|
| 90 | extern int test_and_change_bit(int nr, volatile void * addr);
|
---|
| 91 | #endif
|
---|
| 92 |
|
---|
| 93 | extern int __constant_test_bit(int nr, const volatile void * addr);
|
---|
| 94 | extern int __test_bit(int nr, volatile void * addr);
|
---|
[679] | 95 | /**
|
---|
| 96 | * find_first_zero_bit - find the first cleared bit in a memory region
|
---|
| 97 | * @addr: The address to start the search at
|
---|
| 98 | * @size: The maximum size to search
|
---|
| 99 | *
|
---|
| 100 | * Returns the bit number of the first cleared bit.
|
---|
| 101 | */
|
---|
| 102 | extern unsigned long find_first_zero_bit(const unsigned long *addr,
|
---|
| 103 | unsigned long size);
|
---|
[32] | 104 |
|
---|
[679] | 105 | /**
|
---|
| 106 | * find_next_zero_bit - find the next cleared bit in a memory region
|
---|
| 107 | * @addr: The address to base the search on
|
---|
| 108 | * @offset: The bitnumber to start searching at
|
---|
| 109 | * @size: The bitmap size in bits
|
---|
| 110 | */
|
---|
| 111 | extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
|
---|
| 112 | long size, unsigned long offset);
|
---|
| 113 |
|
---|
| 114 |
|
---|
[32] | 115 | /*
|
---|
| 116 | * This routine doesn't need to be atomic.
|
---|
| 117 | */
|
---|
| 118 | #define test_bit(nr, addr) (((1UL << (nr & 31)) & (((const unsigned int *) addr)[nr >> 5])) != 0)
|
---|
| 119 |
|
---|
[679] | 120 | extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
|
---|
| 121 | size, unsigned long offset);
|
---|
| 122 |
|
---|
[442] | 123 | #endif /* _ASM_BITOPS_H */
|
---|