1 #ifndef _SPARC64_FUTEX_H
2 #define _SPARC64_FUTEX_H
4 #include <linux/futex.h>
5 #include <linux/uaccess.h>
8 #define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \
9 __asm__ __volatile__( \
10 "\n1: lduwa [%3] %%asi, %2\n" \
12 "2: casa [%3] %%asi, %2, %1\n" \
14 " bne,pn %%icc, 1b\n" \
17 " .section .fixup,#alloc,#execinstr\n" \
19 "4: sethi %%hi(3b), %0\n" \
20 " jmpl %0 + %%lo(3b), %%g0\n" \
23 " .section __ex_table,\"a\"\n" \
28 : "=&r" (ret), "=&r" (oldval), "=&r" (tem) \
29 : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
32 static inline int futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
34 int op
= (encoded_op
>> 28) & 7;
35 int cmp
= (encoded_op
>> 24) & 15;
36 int oparg
= (encoded_op
<< 8) >> 20;
37 int cmparg
= (encoded_op
<< 20) >> 20;
38 int oldval
= 0, ret
, tem
;
40 if (unlikely(!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
))))
42 if (unlikely((((unsigned long) uaddr
) & 0x3UL
)))
45 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
52 __futex_cas_op("mov\t%4, %1", ret
, oldval
, uaddr
, oparg
);
55 __futex_cas_op("add\t%2, %4, %1", ret
, oldval
, uaddr
, oparg
);
58 __futex_cas_op("or\t%2, %4, %1", ret
, oldval
, uaddr
, oparg
);
61 __futex_cas_op("andn\t%2, %4, %1", ret
, oldval
, uaddr
, oparg
);
64 __futex_cas_op("xor\t%2, %4, %1", ret
, oldval
, uaddr
, oparg
);
74 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
75 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
76 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
77 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
78 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
79 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
80 default: ret
= -ENOSYS
;
87 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
88 u32 oldval
, u32 newval
)
93 "\n1: casa [%4] %%asi, %3, %1\n"
95 " .section .fixup,#alloc,#execinstr\n"
97 "3: sethi %%hi(2b), %0\n"
98 " jmpl %0 + %%lo(2b), %%g0\n"
101 " .section __ex_table,\"a\"\n"
105 : "+r" (ret
), "=r" (newval
)
106 : "1" (newval
), "r" (oldval
), "r" (uaddr
), "i" (-EFAULT
)
113 #endif /* !(_SPARC64_FUTEX_H) */