4 #include <linux/futex.h>
5 #include <linux/uaccess.h>
7 #include <asm/system.h>
9 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11 register unsigned long r8 __asm ("r8") = 0; \
12 __asm__ __volatile__( \
14 "[1:] " insn ";; \n" \
15 " .xdata4 \"__ex_table\", 1b-., 2f-. \n" \
17 : "+r" (r8), "=r" (oldval) \
18 : "r" (uaddr), "r" (oparg) \
23 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
25 register unsigned long r8 __asm ("r8") = 0; \
28 __asm__ __volatile__( \
30 "[1:] ld4 %3=[%4];; \n" \
33 " mov ar.ccv=%2;; \n" \
34 "[2:] cmpxchg4.acq %1=[%4],%3,ar.ccv;; \n" \
35 " .xdata4 \"__ex_table\", 1b-., 3f-.\n" \
36 " .xdata4 \"__ex_table\", 2b-., 3f-.\n" \
38 : "+r" (r8), "=r" (val), "=&r" (oldval), \
40 : "r" (uaddr), "r" (oparg) \
44 } while (unlikely (val != oldval)); \
49 futex_atomic_op_inuser (int encoded_op
, int __user
*uaddr
)
51 int op
= (encoded_op
>> 28) & 7;
52 int cmp
= (encoded_op
>> 24) & 15;
53 int oparg
= (encoded_op
<< 8) >> 20;
54 int cmparg
= (encoded_op
<< 20) >> 20;
56 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
59 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(int)))
66 __futex_atomic_op1("xchg4 %1=[%2],%3", ret
, oldval
, uaddr
,
70 __futex_atomic_op2("add %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
73 __futex_atomic_op2("or %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
76 __futex_atomic_op2("and %3=%3,%5", ret
, oldval
, uaddr
,
80 __futex_atomic_op2("xor %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
90 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
91 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
92 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
93 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
94 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
95 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
96 default: ret
= -ENOSYS
;
103 futex_atomic_cmpxchg_inatomic(int __user
*uaddr
, int oldval
, int newval
)
105 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(int)))
109 register unsigned long r8
__asm ("r8");
110 __asm__
__volatile__(
112 " mov ar.ccv=%3;; \n"
113 "[1:] cmpxchg4.acq %0=[%1],%2,ar.ccv \n"
114 " .xdata4 \"__ex_table\", 1b-., 2f-. \n"
117 : "r" (uaddr
), "r" (newval
),
118 "rO" ((long) (unsigned) oldval
)
124 #endif /* _ASM_FUTEX_H */