Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 1 | #ifndef __ASM_SH_ATOMIC_GRB_H |
| 2 | #define __ASM_SH_ATOMIC_GRB_H |
| 3 | |
Peter Zijlstra | c647015 | 2014-03-26 18:12:45 +0100 | [diff] [blame] | 4 | #define ATOMIC_OP(op) \ |
| 5 | static inline void atomic_##op(int i, atomic_t *v) \ |
| 6 | { \ |
| 7 | int tmp; \ |
| 8 | \ |
| 9 | __asm__ __volatile__ ( \ |
| 10 | " .align 2 \n\t" \ |
| 11 | " mova 1f, r0 \n\t" /* r0 = end point */ \ |
| 12 | " mov r15, r1 \n\t" /* r1 = saved sp */ \ |
| 13 | " mov #-6, r15 \n\t" /* LOGIN: r15 = size */ \ |
| 14 | " mov.l @%1, %0 \n\t" /* load old value */ \ |
| 15 | " " #op " %2, %0 \n\t" /* $op */ \ |
| 16 | " mov.l %0, @%1 \n\t" /* store new value */ \ |
| 17 | "1: mov r1, r15 \n\t" /* LOGOUT */ \ |
| 18 | : "=&r" (tmp), \ |
| 19 | "+r" (v) \ |
| 20 | : "r" (i) \ |
| 21 | : "memory" , "r0", "r1"); \ |
| 22 | } \ |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 23 | |
Peter Zijlstra | c647015 | 2014-03-26 18:12:45 +0100 | [diff] [blame] | 24 | #define ATOMIC_OP_RETURN(op) \ |
| 25 | static inline int atomic_##op##_return(int i, atomic_t *v) \ |
| 26 | { \ |
| 27 | int tmp; \ |
| 28 | \ |
| 29 | __asm__ __volatile__ ( \ |
| 30 | " .align 2 \n\t" \ |
| 31 | " mova 1f, r0 \n\t" /* r0 = end point */ \ |
| 32 | " mov r15, r1 \n\t" /* r1 = saved sp */ \ |
| 33 | " mov #-6, r15 \n\t" /* LOGIN: r15 = size */ \ |
| 34 | " mov.l @%1, %0 \n\t" /* load old value */ \ |
| 35 | " " #op " %2, %0 \n\t" /* $op */ \ |
| 36 | " mov.l %0, @%1 \n\t" /* store new value */ \ |
| 37 | "1: mov r1, r15 \n\t" /* LOGOUT */ \ |
| 38 | : "=&r" (tmp), \ |
| 39 | "+r" (v) \ |
| 40 | : "r" (i) \ |
| 41 | : "memory" , "r0", "r1"); \ |
| 42 | \ |
| 43 | return tmp; \ |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 44 | } |
| 45 | |
Peter Zijlstra | c647015 | 2014-03-26 18:12:45 +0100 | [diff] [blame] | 46 | #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 47 | |
Peter Zijlstra | c647015 | 2014-03-26 18:12:45 +0100 | [diff] [blame] | 48 | ATOMIC_OPS(add) |
| 49 | ATOMIC_OPS(sub) |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 50 | |
Peter Zijlstra | 658aa51 | 2014-04-23 19:44:20 +0200 | [diff] [blame] | 51 | ATOMIC_OP(and) |
| 52 | ATOMIC_OP(or) |
| 53 | ATOMIC_OP(xor) |
| 54 | |
Peter Zijlstra | c647015 | 2014-03-26 18:12:45 +0100 | [diff] [blame] | 55 | #undef ATOMIC_OPS |
| 56 | #undef ATOMIC_OP_RETURN |
| 57 | #undef ATOMIC_OP |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 58 | |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 59 | #endif /* __ASM_SH_ATOMIC_GRB_H */ |