blob: d42252918bfb4e7b944dbda70e205ccb0ebcc87f [file] [log] [blame]
Russell King3c4ee4e2005-08-10 14:41:45 +01001
Russell King4a5f79e2005-11-03 15:48:21 +00002#if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_CPU_32v6K)
Russell King54ea06f2005-07-16 15:21:51 +01003 .macro bitop, instr
4 mov r2, #1
5 and r3, r0, #7 @ Get bit offset
6 add r1, r1, r0, lsr #3 @ Get byte offset
7 mov r3, r2, lsl r3
81: ldrexb r2, [r1]
9 \instr r2, r2, r3
10 strexb r0, r2, [r1]
Russell Kinge7ec0292005-07-28 20:36:26 +010011 cmp r0, #0
Russell King54ea06f2005-07-16 15:21:51 +010012 bne 1b
13 mov pc, lr
14 .endm
15
16 .macro testop, instr, store
17 and r3, r0, #7 @ Get bit offset
18 mov r2, #1
19 add r1, r1, r0, lsr #3 @ Get byte offset
20 mov r3, r2, lsl r3 @ create mask
Russell Kingbac4e962009-05-25 20:58:00 +010021 smp_dmb
Russell King54ea06f2005-07-16 15:21:51 +0100221: ldrexb r2, [r1]
23 ands r0, r2, r3 @ save old value of bit
Russell King614d73e2005-07-27 23:00:05 +010024 \instr r2, r2, r3 @ toggle bit
25 strexb ip, r2, [r1]
26 cmp ip, #0
Russell King54ea06f2005-07-16 15:21:51 +010027 bne 1b
Russell Kingbac4e962009-05-25 20:58:00 +010028 smp_dmb
Russell King54ea06f2005-07-16 15:21:51 +010029 cmp r0, #0
30 movne r0, #1
312: mov pc, lr
32 .endm
33#else
Russell King7a55fd02005-04-18 22:50:01 +010034 .macro bitop, instr
35 and r2, r0, #7
36 mov r3, #1
37 mov r3, r3, lsl r2
Russell King59d1ff32005-11-09 15:04:22 +000038 save_and_disable_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010039 ldrb r2, [r1, r0, lsr #3]
40 \instr r2, r2, r3
41 strb r2, [r1, r0, lsr #3]
42 restore_irqs ip
43 mov pc, lr
44 .endm
45
46/**
47 * testop - implement a test_and_xxx_bit operation.
48 * @instr: operational instruction
49 * @store: store instruction
50 *
51 * Note: we can trivially conditionalise the store instruction
Simon Arlott6cbdc8c2007-05-11 20:40:30 +010052 * to avoid dirtying the data cache.
Russell King7a55fd02005-04-18 22:50:01 +010053 */
54 .macro testop, instr, store
55 add r1, r1, r0, lsr #3
56 and r3, r0, #7
57 mov r0, #1
Russell King59d1ff32005-11-09 15:04:22 +000058 save_and_disable_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010059 ldrb r2, [r1]
60 tst r2, r0, lsl r3
61 \instr r2, r2, r0, lsl r3
62 \store r2, [r1]
Russell King7a55fd02005-04-18 22:50:01 +010063 moveq r0, #0
Uwe Kleine-König0d928b02009-08-13 20:38:17 +020064 restore_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010065 mov pc, lr
66 .endm
Russell King54ea06f2005-07-16 15:21:51 +010067#endif