OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-m68knommu/] [bitops.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef _ASM_GENERIC_BITOPS_H_
2
#define _ASM_GENERIC_BITOPS_H_
3
 
4
#ifdef __KERNEL__
5
#include <asm/system.h>
6
#endif
7
 
8
/*
9
 * For the benefit of those who are trying to port Linux to another
10
 * architecture, here are some C-language equivalents.  You should
11
 * recode these in the native assembly language, if at all possible.
12
 * To guarantee atomicity, these routines call cli() and sti() to
13
 * disable interrupts while they operate.  (You have to provide inline
14
 * routines to cli() and sti().)
15
 *
16
 * Also note, these routines assume that you have 32 bit integers.
17
 * You will have to change this if you are trying to port Linux to the
18
 * Alpha architecture or to a Cray.  :-)
19
 *
20
 * C language equivalents written by Theodore Ts'o, 9/26/92
21
 */
22
 
23
extern __inline__ int set_bit(int nr, void * a)
24
{
25
        int     * addr = a;
26
        int     mask, retval;
27
        unsigned long flags;
28
 
29
        addr += nr >> 5;
30
        mask = 1 << (nr & 0x1f);
31
        save_flags(flags); cli();
32
        retval = (mask & *addr) != 0;
33
        *addr |= mask;
34
        restore_flags(flags);
35
        return retval;
36
}
37
 
38
extern __inline__ int clear_bit(int nr, void * a)
39
{
40
        int     * addr = a;
41
        int     mask, retval;
42
        unsigned long flags;
43
 
44
        addr += nr >> 5;
45
        mask = 1 << (nr & 0x1f);
46
        save_flags(flags); cli();
47
        retval = (mask & *addr) != 0;
48
        *addr &= ~mask;
49
        restore_flags(flags);
50
        return retval;
51
}
52
 
53
extern __inline__ unsigned long change_bit(unsigned long nr,  void *addr)
54
{
55
        int mask, flags;
56
        unsigned long *ADDR = (unsigned long *) addr;
57
        unsigned long oldbit;
58
 
59
        ADDR += nr >> 5;
60
        mask = 1 << (nr & 31);
61
        save_flags(flags); cli();
62
        oldbit = (mask & *ADDR);
63
        *ADDR ^= mask;
64
        restore_flags(flags);
65
        return oldbit != 0;
66
}
67
 
68
extern __inline__ int test_bit(int nr, void * a)
69
{
70
        int     * addr = a;
71
        int     mask;
72
 
73
        addr += nr >> 5;
74
        mask = 1 << (nr & 0x1f);
75
        return ((mask & *addr) != 0);
76
}
77
 
78
/* The easy/cheese version for now. */
79
extern __inline__ unsigned long ffz(unsigned long word)
80
{
81
        unsigned long result = 0;
82
 
83
        while(word & 1) {
84
                result++;
85
                word >>= 1;
86
        }
87
        return result;
88
}
89
 
90
/* find_next_zero_bit() finds the first zero bit in a bit string of length
91
 * 'size' bits, starting the search at bit 'offset'. This is largely based
92
 * on Linus's ALPHA routines, which are pretty portable BTW.
93
 */
94
 
95
extern __inline__ unsigned long find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
96
{
97
        unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
98
        unsigned long result = offset & ~31UL;
99
        unsigned long tmp;
100
 
101
        if (offset >= size)
102
                return size;
103
        size -= result;
104
        offset &= 31UL;
105
        if (offset) {
106
                tmp = *(p++);
107
                tmp |= ~0UL >> (32-offset);
108
                if (size < 32)
109
                        goto found_first;
110
                if (~tmp)
111
                        goto found_middle;
112
                size -= 32;
113
                result += 32;
114
        }
115
        while (size & ~31UL) {
116
                if (~(tmp = *(p++)))
117
                        goto found_middle;
118
                result += 32;
119
                size -= 32;
120
        }
121
        if (!size)
122
                return result;
123
        tmp = *p;
124
 
125
found_first:
126
        tmp |= ~0UL >> size;
127
found_middle:
128
        return result + ffz(tmp);
129
}
130
 
131
/* Linus sez that gcc can optimize the following correctly, we'll see if this
132
 * holds on the Sparc as it does for the ALPHA.
133
 */
134
 
135
#define find_first_zero_bit(addr, size) \
136
        find_next_zero_bit((addr), (size), 0)
137
 
138
/* Now for the ext2 filesystem bit operations and helper routines. */
139
 
140
extern __inline__ int ext2_set_bit(int nr,void * addr)
141
{
142
        int             mask, retval, flags;
143
        unsigned char   *ADDR = (unsigned char *) addr;
144
 
145
        ADDR += nr >> 3;
146
        mask = 1 << (nr & 0x07);
147
        save_flags(flags); cli();
148
        retval = (mask & *ADDR) != 0;
149
        *ADDR |= mask;
150
        restore_flags(flags);
151
        return retval;
152
}
153
 
154
extern __inline__ int ext2_clear_bit(int nr, void * addr)
155
{
156
        int             mask, retval, flags;
157
        unsigned char   *ADDR = (unsigned char *) addr;
158
 
159
        ADDR += nr >> 3;
160
        mask = 1 << (nr & 0x07);
161
        save_flags(flags); cli();
162
        retval = (mask & *ADDR) != 0;
163
        *ADDR &= ~mask;
164
        restore_flags(flags);
165
        return retval;
166
}
167
 
168
extern __inline__ int ext2_test_bit(int nr, const void * addr)
169
{
170
        int                     mask;
171
        const unsigned char     *ADDR = (const unsigned char *) addr;
172
 
173
        ADDR += nr >> 3;
174
        mask = 1 << (nr & 0x07);
175
        return ((mask & *ADDR) != 0);
176
}
177
 
178
#define ext2_find_first_zero_bit(addr, size) \
179
        ext2_find_next_zero_bit((addr), (size), 0)
180
 
181
extern __inline__ unsigned long ext2_find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
182
{
183
        unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
184
        unsigned long result = offset & ~31UL;
185
        unsigned long tmp;
186
 
187
        if (offset >= size)
188
                return size;
189
        size -= result;
190
        offset &= 31UL;
191
        if(offset) {
192
                tmp = *(p++);
193
                tmp |= ~0UL << (32-offset);
194
                if(size < 32)
195
                        goto found_first;
196
                if(~tmp)
197
                        goto found_middle;
198
                size -= 32;
199
                result += 32;
200
        }
201
        while(size & ~31UL) {
202
                if(~(tmp = *(p++)))
203
                        goto found_middle;
204
                result += 32;
205
                size -= 32;
206
        }
207
        if(!size)
208
                return result;
209
        tmp = *p;
210
 
211
found_first:
212
        tmp |= ~0UL << size;
213
found_middle:
214
        tmp = ((tmp>>24) | ((tmp>>8)&0xff00) | ((tmp<<8)&0xff0000) | (tmp<<24));
215
        return result + ffz(tmp);
216
}
217
 
218
#define __ext2_set_bit ext2_set_bit
219
#define __ext2_clear_bit ext2_clear_bit
220
 
221
extern __inline__ int __ext2_test_bit(int nr, __const__ void * addr)
222
{
223
        int                     mask;
224
        __const__ unsigned char *ADDR = (__const__ unsigned char *) addr;
225
 
226
        ADDR += nr >> 3;
227
        mask = 1 << (nr & 0x07);
228
        return ((mask & *ADDR) != 0);
229
}
230
 
231
extern __inline__ unsigned short __swab16(unsigned short value)
232
{
233
        return ((value >> 8) | (value << 8));
234
}
235
 
236
extern __inline__ unsigned long __swab32(unsigned long value)
237
{
238
        return ((value >> 24) | ((value >> 8) & 0xff00) |
239
               ((value << 8) & 0xff0000) | (value << 24));
240
}
241
 
242
#define __ext2_find_first_zero_bit(addr, size) \
243
        __ext2_find_next_zero_bit((addr), (size), 0)
244
 
245
extern __inline__ unsigned long __ext2_find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
246
{
247
        unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
248
        unsigned long result = offset & ~31UL;
249
        unsigned long tmp;
250
 
251
        if (offset >= size)
252
                return size;
253
        size -= result;
254
        offset &= 31UL;
255
        if(offset) {
256
                tmp = *(p++);
257
                tmp |= __swab32(~0UL >> (32-offset));
258
                if(size < 32)
259
                        goto found_first;
260
                if(~tmp)
261
                        goto found_middle;
262
                size -= 32;
263
                result += 32;
264
        }
265
        while(size & ~31UL) {
266
                if(~(tmp = *(p++)))
267
                        goto found_middle;
268
                result += 32;
269
                size -= 32;
270
        }
271
        if(!size)
272
                return result;
273
        tmp = *p;
274
 
275
found_first:
276
        return result + ffz(__swab32(tmp) | (~0UL << size));
277
found_middle:
278
        return result + ffz(__swab32(tmp));
279
}
280
 
281
 
282
#endif /* _ASM_GENERIC_BITOPS_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.