Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 1 | #if __LINUX_ARM_ARCH__ >= 6 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 2 | .macro bitop, instr |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 3 | ands ip, r1, #3 |
| 4 | strneb r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 5 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 6 | and r3, r0, #31 @ Get bit offset |
| 7 | mov r0, r0, lsr #5 |
| 8 | add r1, r1, r0, lsl #2 @ Get word offset |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 9 | mov r3, r2, lsl r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 10 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 11 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 12 | strex r0, r2, [r1] |
Russell King | e7ec029 | 2005-07-28 20:36:26 +0100 | [diff] [blame] | 13 | cmp r0, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 14 | bne 1b |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame^] | 15 | bx lr |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 16 | .endm |
| 17 | |
| 18 | .macro testop, instr, store |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 19 | ands ip, r1, #3 |
| 20 | strneb r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 21 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 22 | and r3, r0, #31 @ Get bit offset |
| 23 | mov r0, r0, lsr #5 |
| 24 | add r1, r1, r0, lsl #2 @ Get word offset |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 25 | mov r3, r2, lsl r3 @ create mask |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 26 | smp_dmb |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 27 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 28 | ands r0, r2, r3 @ save old value of bit |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 29 | \instr r2, r2, r3 @ toggle bit |
| 30 | strex ip, r2, [r1] |
Russell King | 614d73e | 2005-07-27 23:00:05 +0100 | [diff] [blame] | 31 | cmp ip, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 32 | bne 1b |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 33 | smp_dmb |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 34 | cmp r0, #0 |
| 35 | movne r0, #1 |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame^] | 36 | 2: bx lr |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 37 | .endm |
| 38 | #else |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 39 | .macro bitop, instr |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 40 | ands ip, r1, #3 |
| 41 | strneb r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 42 | and r2, r0, #31 |
| 43 | mov r0, r0, lsr #5 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 44 | mov r3, #1 |
| 45 | mov r3, r3, lsl r2 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 46 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 47 | ldr r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 48 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 49 | str r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 50 | 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 Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 60 | * to avoid dirtying the data cache. |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 61 | */ |
| 62 | .macro testop, instr, store |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 63 | ands ip, r1, #3 |
| 64 | strneb r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 65 | and r3, r0, #31 |
| 66 | mov r0, r0, lsr #5 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 67 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 68 | ldr r2, [r1, r0, lsl #2]! |
| 69 | mov r0, #1 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 70 | tst r2, r0, lsl r3 |
| 71 | \instr r2, r2, r0, lsl r3 |
| 72 | \store r2, [r1] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 73 | moveq r0, #0 |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 74 | restore_irqs ip |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 75 | mov pc, lr |
| 76 | .endm |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 77 | #endif |