2 * linux/arch/arm/lib/bitops.S
4 * Copyright (C) 1995, 1996 Russell King
7 #include <linux/linkage.h>
8 #include <asm/assembler.h>
11 @ Purpose : Function to set a bit
12 @ Prototype: int set_bit(int bit,int *addr)
20 ldrb r2, [r1, r0, lsr #3]
22 strb r2, [r1, r0, lsr #3]
26 ENTRY(test_and_set_bit)
27 add r1, r1, r0, lsr #3 @ Get byte offset
28 and r3, r0, #7 @ Get bit offset
34 orr r2, r2, r0, lsl r3
40 @ Purpose : Function to clear a bit
41 @ Prototype: int clear_bit(int bit,int *addr)
49 ldrb r2, [r1, r0, lsr #3]
51 strb r2, [r1, r0, lsr #3]
55 ENTRY(test_and_clear_bit)
56 add r1, r1, r0, lsr #3 @ Get byte offset
57 and r3, r0, #7 @ Get bit offset
63 bic r2, r2, r0, lsl r3
69 /* Purpose : Function to change a bit
70 * Prototype: int change_bit(int bit,int *addr)
78 ldrb r2, [r1, r0, lsr #3]
80 strb r2, [r1, r0, lsr #3]
84 ENTRY(test_and_change_bit)
85 add r1, r1, r0, lsr #3
92 eor r2, r2, r0, lsl r3
98 @ Purpose : Find a 'zero' bit
99 @ Prototype: int find_first_zero_bit(char *addr,int maxbit);
101 ENTRY(find_first_zero_bit)
102 mov r2, #0 @ Initialise bit position
103 Lfindzbit1lp: ldrb r3, [r0, r2, lsr #3] @ Check byte, if 0xFF, then all bits set
107 cmp r2, r1 @ Check to see if we have come to the end
109 add r0, r1, #1 @ Make sure that we flag an error
111 Lfoundzbit: tst r3, #1 @ Check individual bits
113 RETINSTR(moveq,pc,lr)
116 RETINSTR(moveq,pc,lr)
119 RETINSTR(moveq,pc,lr)
122 RETINSTR(moveq,pc,lr)
125 RETINSTR(moveq,pc,lr)
128 RETINSTR(moveq,pc,lr)
131 RETINSTR(moveq,pc,lr)
135 @ Purpose : Find next 'zero' bit
136 @ Prototype: int find_next_zero_bit(char *addr,int maxbit,int offset)
138 ENTRY(find_next_zero_bit)
140 beq Lfindzbit1lp @ If new byte, goto old routine
141 ldrb r3, [r0, r2, lsr#3]
142 orr r3, r3, #0xFF00 @ Set top bits so we wont get confused
145 mov r3, r3, lsr r4 @ Shift right by no. of bits
151 beq Lfindzbit1lp @ If all bits are set, goto old routine