6 #include <linux/futex.h>
8 #include <asm/system.h>
9 #include <asm/processor.h>
10 #include <asm/uaccess.h>
12 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13 __asm__ __volatile ( \
15 "2: .section .fixup,\"ax\"\n\
19 .section __ex_table,\"a\"\n\
23 : "=r" (oldval), "=r" (ret), "=m" (*uaddr) \
24 : "i" (-EFAULT), "m" (*uaddr), "0" (oparg), "1" (0))
26 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
27 __asm__ __volatile ( \
31 "2: " LOCK_PREFIX "cmpxchgl %3, %2\n\
33 3: .section .fixup,\"ax\"\n\
37 .section __ex_table,\"a\"\n\
41 : "=&a" (oldval), "=&r" (ret), "=m" (*uaddr), \
43 : "r" (oparg), "i" (-EFAULT), "m" (*uaddr), "1" (0))
46 futex_atomic_op_inuser (int encoded_op
, int __user
*uaddr
)
48 int op
= (encoded_op
>> 28) & 7;
49 int cmp
= (encoded_op
>> 24) & 15;
50 int oparg
= (encoded_op
<< 8) >> 20;
51 int cmparg
= (encoded_op
<< 20) >> 20;
52 int oldval
= 0, ret
, tem
;
53 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
56 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(int)))
61 if (op
== FUTEX_OP_SET
)
62 __futex_atomic_op1("xchgl %0, %2", ret
, oldval
, uaddr
, oparg
);
64 #ifndef CONFIG_X86_BSWAP
65 if (boot_cpu_data
.x86
== 3)
71 __futex_atomic_op1(LOCK_PREFIX
"xaddl %0, %2", ret
,
72 oldval
, uaddr
, oparg
);
75 __futex_atomic_op2("orl %4, %3", ret
, oldval
, uaddr
,
79 __futex_atomic_op2("andl %4, %3", ret
, oldval
, uaddr
,
83 __futex_atomic_op2("xorl %4, %3", ret
, oldval
, uaddr
,
95 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
96 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
97 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
98 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
99 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
100 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
101 default: ret
= -ENOSYS
;