blob: 10d868a5a48135840278022e153f3610b0b7a640 [file] [log] [blame]
Russell King6323f0c2011-01-16 18:02:17 +00001#if __LINUX_ARM_ARCH__ >= 6
Russell King54ea06f2005-07-16 15:21:51 +01002 .macro bitop, instr
Russell Kinga16ede32011-01-16 17:59:44 +00003 ands ip, r1, #3
4 strneb r1, [ip] @ assert word-aligned
Russell King54ea06f2005-07-16 15:21:51 +01005 mov r2, #1
Russell King6323f0c2011-01-16 18:02:17 +00006 and r3, r0, #31 @ Get bit offset
7 mov r0, r0, lsr #5
8 add r1, r1, r0, lsl #2 @ Get word offset
Russell King54ea06f2005-07-16 15:21:51 +01009 mov r3, r2, lsl r3
Russell King6323f0c2011-01-16 18:02:17 +0000101: ldrex r2, [r1]
Russell King54ea06f2005-07-16 15:21:51 +010011 \instr r2, r2, r3
Russell King6323f0c2011-01-16 18:02:17 +000012 strex r0, r2, [r1]
Russell Kinge7ec0292005-07-28 20:36:26 +010013 cmp r0, #0
Russell King54ea06f2005-07-16 15:21:51 +010014 bne 1b
Dave Martin3ba6e692011-02-08 12:09:52 +010015 bx lr
Russell King54ea06f2005-07-16 15:21:51 +010016 .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 mov r2, #1
Russell King6323f0c2011-01-16 18:02:17 +000022 and r3, r0, #31 @ Get bit offset
23 mov r0, r0, lsr #5
24 add r1, r1, r0, lsl #2 @ Get word offset
Russell King54ea06f2005-07-16 15:21:51 +010025 mov r3, r2, lsl r3 @ create mask
Russell Kingbac4e962009-05-25 20:58:00 +010026 smp_dmb
Russell King6323f0c2011-01-16 18:02:17 +0000271: ldrex r2, [r1]
Russell King54ea06f2005-07-16 15:21:51 +010028 ands r0, r2, r3 @ save old value of bit
Russell King6323f0c2011-01-16 18:02:17 +000029 \instr r2, r2, r3 @ toggle bit
30 strex ip, r2, [r1]
Russell King614d73e2005-07-27 23:00:05 +010031 cmp ip, #0
Russell King54ea06f2005-07-16 15:21:51 +010032 bne 1b
Russell Kingbac4e962009-05-25 20:58:00 +010033 smp_dmb
Russell King54ea06f2005-07-16 15:21:51 +010034 cmp r0, #0
35 movne r0, #1
Dave Martin3ba6e692011-02-08 12:09:52 +0100362: bx lr
Russell King54ea06f2005-07-16 15:21:51 +010037 .endm
38#else
Russell King7a55fd02005-04-18 22:50:01 +010039 .macro bitop, instr
Russell Kinga16ede32011-01-16 17:59:44 +000040 ands ip, r1, #3
41 strneb r1, [ip] @ assert word-aligned
Russell King6323f0c2011-01-16 18:02:17 +000042 and r2, r0, #31
43 mov r0, r0, lsr #5
Russell King7a55fd02005-04-18 22:50:01 +010044 mov r3, #1
45 mov r3, r3, lsl r2
Russell King59d1ff32005-11-09 15:04:22 +000046 save_and_disable_irqs ip
Russell King6323f0c2011-01-16 18:02:17 +000047 ldr r2, [r1, r0, lsl #2]
Russell King7a55fd02005-04-18 22:50:01 +010048 \instr r2, r2, r3
Russell King6323f0c2011-01-16 18:02:17 +000049 str r2, [r1, r0, lsl #2]
Russell King7a55fd02005-04-18 22:50:01 +010050 restore_irqs ip
51 mov pc, lr
52 .endm
53
54/**
55 * testop - implement a test_and_xxx_bit operation.
56 * @instr: operational instruction
57 * @store: store instruction
58 *
59 * Note: we can trivially conditionalise the store instruction
Simon Arlott6cbdc8c2007-05-11 20:40:30 +010060 * to avoid dirtying the data cache.
Russell King7a55fd02005-04-18 22:50:01 +010061 */
62 .macro testop, instr, store
Russell Kinga16ede32011-01-16 17:59:44 +000063 ands ip, r1, #3
64 strneb r1, [ip] @ assert word-aligned
Russell King6323f0c2011-01-16 18:02:17 +000065 and r3, r0, #31
66 mov r0, r0, lsr #5
Russell King59d1ff32005-11-09 15:04:22 +000067 save_and_disable_irqs ip
Russell King6323f0c2011-01-16 18:02:17 +000068 ldr r2, [r1, r0, lsl #2]!
69 mov r0, #1
Russell King7a55fd02005-04-18 22:50:01 +010070 tst r2, r0, lsl r3
71 \instr r2, r2, r0, lsl r3
72 \store r2, [r1]
Russell King7a55fd02005-04-18 22:50:01 +010073 moveq r0, #0
Uwe Kleine-König0d928b02009-08-13 20:38:17 +020074 restore_irqs ip
Russell King7a55fd02005-04-18 22:50:01 +010075 mov pc, lr
76 .endm
Russell King54ea06f2005-07-16 15:21:51 +010077#endif