1 #ifndef _ASM_X86_FUTEX_H
2 #define _ASM_X86_FUTEX_H
6 #include <linux/futex.h>
10 #include <asm/processor.h>
11 #include <asm/system.h>
12 #include <asm/uaccess.h>
14 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17 "2: .section .fixup,\"ax\"\n \
22 : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
23 : "i" (-EFAULT), "0" (oparg), "1" (0))
25 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
30 "2: lock; cmpxchgl %3, %2\n \
32 3: .section .fixup,\"ax\"\n \
38 : "=&a" (oldval), "=&r" (ret), "+m" (*uaddr), \
40 : "r" (oparg), "i" (-EFAULT), "1" (0))
43 futex_atomic_op_inuser(int encoded_op
, int __user
*uaddr
)
45 int op
= (encoded_op
>> 28) & 7;
46 int cmp
= (encoded_op
>> 24) & 15;
47 int oparg
= (encoded_op
<< 8) >> 20;
48 int cmparg
= (encoded_op
<< 20) >> 20;
49 int oldval
= 0, ret
, tem
;
51 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
54 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(int)))
57 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_BSWAP)
58 /* Real i386 machines can only support FUTEX_OP_SET */
59 if (op
!= FUTEX_OP_SET
&& boot_cpu_data
.x86
== 3)
67 __futex_atomic_op1("xchgl %0, %2", ret
, oldval
, uaddr
, oparg
);
70 __futex_atomic_op1("lock; xaddl %0, %2", ret
, oldval
,
74 __futex_atomic_op2("orl %4, %3", ret
, oldval
, uaddr
, oparg
);
77 __futex_atomic_op2("andl %4, %3", ret
, oldval
, uaddr
, ~oparg
);
80 __futex_atomic_op2("xorl %4, %3", 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
)
106 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_BSWAP)
107 /* Real i386 machines have no cmpxchg instruction */
108 if (boot_cpu_data
.x86
== 3)
112 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(int)))
115 __asm__
__volatile__(
116 "1: lock; cmpxchgl %3, %1 \n"
117 "2: .section .fixup, \"ax\" \n"
122 : "=a" (oldval
), "+m" (*uaddr
)
123 : "i" (-EFAULT
), "r" (newval
), "0" (oldval
)