Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 1 | #include <asm/unwind.h> |
| 2 | |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 3 | #if __LINUX_ARM_ARCH__ >= 6 |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 4 | .macro bitop, name, instr |
| 5 | ENTRY( \name ) |
| 6 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 7 | ands ip, r1, #3 |
| 8 | strneb r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 9 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 10 | and r3, r0, #31 @ Get bit offset |
| 11 | mov r0, r0, lsr #5 |
| 12 | add r1, r1, r0, lsl #2 @ Get word offset |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 13 | mov r3, r2, lsl r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 14 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 15 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 16 | strex r0, r2, [r1] |
Russell King | e7ec029 | 2005-07-28 20:36:26 +0100 | [diff] [blame] | 17 | cmp r0, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 18 | bne 1b |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame] | 19 | bx lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 20 | UNWIND( .fnend ) |
| 21 | ENDPROC(\name ) |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 22 | .endm |
| 23 | |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 24 | .macro testop, name, instr, store |
| 25 | ENTRY( \name ) |
| 26 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 27 | ands ip, r1, #3 |
| 28 | strneb r1, [ip] @ assert word-aligned |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 29 | mov r2, #1 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 30 | and r3, r0, #31 @ Get bit offset |
| 31 | mov r0, r0, lsr #5 |
| 32 | add r1, r1, r0, lsl #2 @ Get word offset |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 33 | mov r3, r2, lsl r3 @ create mask |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 34 | smp_dmb |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 35 | 1: ldrex r2, [r1] |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 36 | ands r0, r2, r3 @ save old value of bit |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 37 | \instr r2, r2, r3 @ toggle bit |
| 38 | strex ip, r2, [r1] |
Russell King | 614d73e | 2005-07-27 23:00:05 +0100 | [diff] [blame] | 39 | cmp ip, #0 |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 40 | bne 1b |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 41 | smp_dmb |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 42 | cmp r0, #0 |
| 43 | movne r0, #1 |
Dave Martin | 3ba6e69 | 2011-02-08 12:09:52 +0100 | [diff] [blame] | 44 | 2: bx lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 45 | UNWIND( .fnend ) |
| 46 | ENDPROC(\name ) |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 47 | .endm |
| 48 | #else |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 49 | .macro bitop, name, instr |
| 50 | ENTRY( \name ) |
| 51 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 52 | ands ip, r1, #3 |
| 53 | strneb r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 54 | and r2, r0, #31 |
| 55 | mov r0, r0, lsr #5 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 56 | mov r3, #1 |
| 57 | mov r3, r3, lsl r2 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 58 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 59 | ldr r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 60 | \instr r2, r2, r3 |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 61 | str r2, [r1, r0, lsl #2] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 62 | restore_irqs ip |
| 63 | mov pc, lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 64 | UNWIND( .fnend ) |
| 65 | ENDPROC(\name ) |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 66 | .endm |
| 67 | |
| 68 | /** |
| 69 | * testop - implement a test_and_xxx_bit operation. |
| 70 | * @instr: operational instruction |
| 71 | * @store: store instruction |
| 72 | * |
| 73 | * Note: we can trivially conditionalise the store instruction |
Simon Arlott | 6cbdc8c | 2007-05-11 20:40:30 +0100 | [diff] [blame] | 74 | * to avoid dirtying the data cache. |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 75 | */ |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 76 | .macro testop, name, instr, store |
| 77 | ENTRY( \name ) |
| 78 | UNWIND( .fnstart ) |
Russell King | a16ede3 | 2011-01-16 17:59:44 +0000 | [diff] [blame] | 79 | ands ip, r1, #3 |
| 80 | strneb r1, [ip] @ assert word-aligned |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 81 | and r3, r0, #31 |
| 82 | mov r0, r0, lsr #5 |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 83 | save_and_disable_irqs ip |
Russell King | 6323f0c | 2011-01-16 18:02:17 +0000 | [diff] [blame] | 84 | ldr r2, [r1, r0, lsl #2]! |
| 85 | mov r0, #1 |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 86 | tst r2, r0, lsl r3 |
| 87 | \instr r2, r2, r0, lsl r3 |
| 88 | \store r2, [r1] |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 89 | moveq r0, #0 |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 90 | restore_irqs ip |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 91 | mov pc, lr |
Will Deacon | c36ef4b | 2011-11-23 11:28:25 +0100 | [diff] [blame] | 92 | UNWIND( .fnend ) |
| 93 | ENDPROC(\name ) |
Russell King | 7a55fd0 | 2005-04-18 22:50:01 +0100 | [diff] [blame] | 94 | .endm |
Russell King | 54ea06f | 2005-07-16 15:21:51 +0100 | [diff] [blame] | 95 | #endif |