1 #ifndef _ASM_X86_FUTEX_H
2 #define _ASM_X86_FUTEX_H
6 #include <linux/futex.h>
7 #include <linux/uaccess.h>
10 #include <asm/errno.h>
11 #include <asm/processor.h>
12 #include <asm/system.h>
14 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15 asm volatile("1:\t" insn "\n" \
16 "2:\t.section .fixup,\"ax\"\n" \
20 _ASM_EXTABLE(1b, 3b) \
21 : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
22 : "i" (-EFAULT), "0" (oparg), "1" (0))
24 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
25 asm volatile("1:\tmovl %2, %0\n" \
28 "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
30 "3:\t.section .fixup,\"ax\"\n" \
34 _ASM_EXTABLE(1b, 4b) \
35 _ASM_EXTABLE(2b, 4b) \
36 : "=&a" (oldval), "=&r" (ret), \
37 "+m" (*uaddr), "=&r" (tem) \
38 : "r" (oparg), "i" (-EFAULT), "1" (0))
40 static inline int futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
42 int op
= (encoded_op
>> 28) & 7;
43 int cmp
= (encoded_op
>> 24) & 15;
44 int oparg
= (encoded_op
<< 8) >> 20;
45 int cmparg
= (encoded_op
<< 20) >> 20;
46 int oldval
= 0, ret
, tem
;
48 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
51 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
54 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_BSWAP)
55 /* Real i386 machines can only support FUTEX_OP_SET */
56 if (op
!= FUTEX_OP_SET
&& boot_cpu_data
.x86
== 3)
64 __futex_atomic_op1("xchgl %0, %2", ret
, oldval
, uaddr
, oparg
);
67 __futex_atomic_op1(LOCK_PREFIX
"xaddl %0, %2", ret
, oldval
,
71 __futex_atomic_op2("orl %4, %3", ret
, oldval
, uaddr
, oparg
);
74 __futex_atomic_op2("andl %4, %3", ret
, oldval
, uaddr
, ~oparg
);
77 __futex_atomic_op2("xorl %4, %3", ret
, oldval
, uaddr
, oparg
);
88 ret
= (oldval
== cmparg
);
91 ret
= (oldval
!= cmparg
);
94 ret
= (oldval
< cmparg
);
97 ret
= (oldval
>= cmparg
);
100 ret
= (oldval
<= cmparg
);
102 case FUTEX_OP_CMP_GT
:
103 ret
= (oldval
> cmparg
);
112 static inline int futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
113 u32 oldval
, u32 newval
)
117 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_BSWAP)
118 /* Real i386 machines have no cmpxchg instruction */
119 if (boot_cpu_data
.x86
== 3)
123 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
126 asm volatile("1:\t" LOCK_PREFIX
"cmpxchgl %4, %2\n"
127 "2:\t.section .fixup, \"ax\"\n"
132 : "+r" (ret
), "=a" (oldval
), "+m" (*uaddr
)
133 : "i" (-EFAULT
), "r" (newval
), "1" (oldval
)
142 #endif /* _ASM_X86_FUTEX_H */