6 #include <linux/futex.h>
10 #include <asm/system.h>
11 #include <asm/uaccess.h>
13 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
14 __asm__ __volatile ( \
16 "2: .section .fixup,\"ax\"\n\
20 .section __ex_table,\"a\"\n\
24 : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
25 : "i" (-EFAULT), "0" (oparg), "1" (0))
27 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
28 __asm__ __volatile ( \
32 "2: " LOCK_PREFIX "cmpxchgl %3, %2\n\
34 3: .section .fixup,\"ax\"\n\
38 .section __ex_table,\"a\"\n\
40 _ASM_PTR "1b,4b,2b,4b\n \
42 : "=&a" (oldval), "=&r" (ret), "+m" (*uaddr), \
44 : "r" (oparg), "i" (-EFAULT), "1" (0))
47 futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
49 int op = (encoded_op >> 28) & 7;
50 int cmp = (encoded_op >> 24) & 15;
51 int oparg = (encoded_op << 8) >> 20;
52 int cmparg = (encoded_op << 20) >> 20;
53 int oldval = 0, ret, tem;
54 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
57 if (! access_ok (VERIFY_WRITE, uaddr, sizeof(int)))
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);
87 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
88 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
89 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
90 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
91 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
92 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
93 default: ret = -ENOSYS;
100 futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
102 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
105 __asm__ __volatile__(
106 "1: " LOCK_PREFIX "cmpxchgl %3, %1 \n"
108 "2: .section .fixup, \"ax\" \n"
113 " .section __ex_table, \"a\" \n"
118 : "=a" (oldval), "+m" (*uaddr)
119 : "i" (-EFAULT), "r" (newval), "0" (oldval)