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 \
21 .section __ex_table,\"a\"\n \
25 : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
26 : "i" (-EFAULT), "0" (oparg), "1" (0))
28 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
33 "2: " LOCK_PREFIX "cmpxchgl %3, %2\n \
35 3: .section .fixup,\"ax\"\n \
39 .section __ex_table,\"a\"\n \
41 _ASM_PTR "1b,4b,2b,4b\n \
43 : "=&a" (oldval), "=&r" (ret), "+m" (*uaddr), \
45 : "r" (oparg), "i" (-EFAULT), "1" (0))
48 futex_atomic_op_inuser(int encoded_op
, int __user
*uaddr
)
50 int op
= (encoded_op
>> 28) & 7;
51 int cmp
= (encoded_op
>> 24) & 15;
52 int oparg
= (encoded_op
<< 8) >> 20;
53 int cmparg
= (encoded_op
<< 20) >> 20;
54 int oldval
= 0, ret
, tem
;
56 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
59 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(int)))
62 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_BSWAP)
63 /* Real i386 machines can only support FUTEX_OP_SET */
64 if (op
!= FUTEX_OP_SET
&& boot_cpu_data
.x86
== 3)
72 __futex_atomic_op1("xchgl %0, %2", ret
, oldval
, uaddr
, oparg
);
75 __futex_atomic_op1(LOCK_PREFIX
"xaddl %0, %2", ret
, oldval
,
79 __futex_atomic_op2("orl %4, %3", ret
, oldval
, uaddr
, oparg
);
82 __futex_atomic_op2("andl %4, %3", ret
, oldval
, uaddr
, ~oparg
);
85 __futex_atomic_op2("xorl %4, %3", ret
, oldval
, uaddr
, oparg
);
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
;
108 futex_atomic_cmpxchg_inatomic(int __user
*uaddr
, int oldval
, int newval
)
110 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(int)))
113 __asm__
__volatile__(
114 "1: " LOCK_PREFIX
"cmpxchgl %3, %1 \n"
116 "2: .section .fixup, \"ax\" \n"
121 " .section __ex_table, \"a\" \n"
126 : "=a" (oldval
), "+m" (*uaddr
)
127 : "i" (-EFAULT
), "r" (newval
), "0" (oldval
)