blob: bd00551fb79761430343d6ab93c09510bf59924c [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
Russell Kinga16ede32011-01-16 17:59:44 +00004 ands ip, r1, #3
5 strneb r1, [ip] @ assert word-aligned
Russell King54ea06f2005-07-16 15:21:51 +01006 mov r2, #1
7 and r3, r0, #7 @ Get bit offset
8 add r1, r1, r0, lsr #3 @ Get byte offset
9 mov r3, r2, lsl r3
101: ldrexb r2, [r1]
11 \instr r2, r2, r3
12 strexb r0, r2, [r1]
Russell Kinge7ec0292005-07-28 20:36:26 +010013 cmp r0, #0
Russell King54ea06f2005-07-16 15:21:51 +010014 bne 1b
15 mov pc, lr
16 .endm
17
18 .macro testop, instr, store
Russell Kinga16ede32011-01-16 17:59:44 +000019 ands ip, r1, #3
20 strneb r1, [ip] @ assert word-aligned
Russell King54ea06f2005-07-16 15:21:51 +010021 and r3, r0, #7 @ Get bit offset
22 mov r2, #1
23 add r1, r1, r0, lsr #3 @ Get byte offset
24 mov r3, r2, lsl r3 @ create mask
Russell Kingbac4e962009-05-25 20:58:00 +010025 smp_dmb
Russell King54ea06f2005-07-16 15:21:51 +0100261: ldrexb r2, [r1]
27 ands r0, r2, r3 @ save old value of bit
Russell King614d73e2005-07-27 23:00:05 +010028 \instr r2, r2, r3 @ toggle bit
29 strexb ip, r2, [r1]
30 cmp ip, #0
Russell King54ea06f2005-07-16 15:21:51 +010031 bne 1b
Russell Kingbac4e962009-05-25 20:58:00 +010032 smp_dmb
Russell King54ea06f2005-07-16 15:21:51 +010033 cmp r0, #0
34 movne r0, #1
352: mov pc, lr
36 .endm
37#else
Russell King7a55fd02005-04-18 22:50:01 +010038 .macro bitop, instr
Russell Kinga16ede32011-01-16 17:59:44 +000039 ands ip, r1, #3
40 strneb r1, [ip] @ assert word-aligned
Russell King7a55fd02005-04-18 22:50:01 +010041 and r2, r0, #7
42 mov r3, #1
43 mov r3, r3, lsl r2
Russell King59d1ff32005-11-09 15:04:22 +000044 save_and_disable_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010045 ldrb r2, [r1, r0, lsr #3]
46 \instr r2, r2, r3
47 strb r2, [r1, r0, lsr #3]
48 restore_irqs ip
49 mov pc, lr
50 .endm
51
52/**
53 * testop - implement a test_and_xxx_bit operation.
54 * @instr: operational instruction
55 * @store: store instruction
56 *
57 * Note: we can trivially conditionalise the store instruction
Simon Arlott6cbdc8c2007-05-11 20:40:30 +010058 * to avoid dirtying the data cache.
Russell King7a55fd02005-04-18 22:50:01 +010059 */
60 .macro testop, instr, store
Russell Kinga16ede32011-01-16 17:59:44 +000061 ands ip, r1, #3
62 strneb r1, [ip] @ assert word-aligned
Russell King7a55fd02005-04-18 22:50:01 +010063 add r1, r1, r0, lsr #3
64 and r3, r0, #7
65 mov r0, #1
Russell King59d1ff32005-11-09 15:04:22 +000066 save_and_disable_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010067 ldrb r2, [r1]
68 tst r2, r0, lsl r3
69 \instr r2, r2, r0, lsl r3
70 \store r2, [r1]
Russell King7a55fd02005-04-18 22:50:01 +010071 moveq r0, #0
Uwe Kleine-König0d928b02009-08-13 20:38:17 +020072 restore_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010073 mov pc, lr
74 .endm
Russell King54ea06f2005-07-16 15:21:51 +010075#endif