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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-ppc/] [bitops.h] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#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)
25
{
26
       int      mask, oldbit;
27
  BITFIELD *addr = add;
28
 
29
        int s = _disable_interrupts();
30
        addr += nr >> 5;
31
        mask = BIT(nr);
32
        oldbit = (mask & *addr) != 0;
33
        *addr |= mask;
34
        _enable_interrupts(s);
35
 
36
 
37
        return oldbit;
38
}
39
 
40
extern __inline__ int change_bit(int nr, void *add)
41
{
42
        BITFIELD *addr = add;
43
        int     mask, retval;
44
        int s = _disable_interrupts();
45
        addr += nr >> 5;
46
        mask = BIT(nr);
47
        retval = (mask & *addr) != 0;
48
        *addr ^= mask;
49
        _enable_interrupts(s);
50
        return retval;
51
}
52
 
53
extern __inline__ int clear_bit(int nr, void *add)
54
{
55
        BITFIELD *addr = add;
56
        int     mask, retval;
57
        int s = _disable_interrupts();
58
        addr += nr >> 5;
59
        mask = BIT(nr);
60
        retval = (mask & *addr) != 0;
61
        *addr &= ~mask;
62
        _enable_interrupts(s);
63
        return retval;
64
}
65
 
66
extern __inline__ int test_bit(int nr, void *add)
67
{
68
        int     mask;
69
        BITFIELD *addr = add;
70
 
71
        addr += nr >> 5;
72
        mask = BIT(nr);
73
        return ((mask & *addr) != 0);
74
}
75
#if 0
76
extern __inline__ int find_first_zero_bit(void *add, int len)
77
{
78
        int     mask, nr, i;
79
        BITFIELD *addr = add;
80
        nr = 0;
81
        while (len)
82
        {
83
                if (~*addr != 0)
84
                { /* Contains at least one zero */
85
                        for (i = 0;  i < 32;  i++, nr++)
86
                        {
87
                                mask = BIT(nr);
88
                                if ((mask & *addr) == 0)
89
                                {
90
                                        return (nr);
91
                                }
92
                        }
93
                }
94
                len -= 32;
95
                addr++;
96
                nr += 32;
97
        }
98
        return (0);  /* Shouldn't happen */
99
}
100
 
101
extern __inline__ int find_next_zero_bit(void *add, int len, int nr)
102
{
103
        int     mask, i;
104
        BITFIELD *addr = add;
105
        addr += nr >> 5;
106
        len -= nr;
107
        while (len)
108
        {
109
                if (*addr != 0xFFFFFFFF)
110
                { /* Contains at least one zero */
111
                        for (i = 0;  i < 32;  i++, nr++)
112
                        {
113
                                mask = BIT(nr);
114
                                if ((mask & *addr) == 0)
115
                                {
116
printk("Bit: %d(%d), Pat: %x\n", nr, nr&0x1F, *addr);
117
                                        return (nr);
118
                                }
119
                        }
120
                }
121
                len -= 32;
122
                addr++;
123
                nr += 32;
124
        }
125
        return (0);  /* Shouldn't happen */
126
}
127
#endif
128
#endif /* _ASM_PPC_BITOPS_H */
129
 
130
 

powered by: WebSVN 2.1.0

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