2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 2006 Ralf Baechle (ralf@linux-mips.org)
13 #include <linux/futex.h>
14 #include <linux/uaccess.h>
15 #include <asm/barrier.h>
16 #include <asm/errno.h>
19 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
21 if (cpu_has_llsc && R10000_LLSC_WAR) { \
22 __asm__ __volatile__( \
26 "1: ll %1, %4 # __futex_atomic_op \n" \
36 " .section .fixup,\"ax\" \n" \
40 " .section __ex_table,\"a\" \n" \
41 " "__UA_ADDR "\t1b, 4b \n" \
42 " "__UA_ADDR "\t2b, 4b \n" \
44 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
45 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
47 } else if (cpu_has_llsc) { \
48 __asm__ __volatile__( \
52 "1: ll %1, %4 # __futex_atomic_op \n" \
62 " .section .fixup,\"ax\" \n" \
66 " .section __ex_table,\"a\" \n" \
67 " "__UA_ADDR "\t1b, 4b \n" \
68 " "__UA_ADDR "\t2b, 4b \n" \
70 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
71 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
78 futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
80 int op
= (encoded_op
>> 28) & 7;
81 int cmp
= (encoded_op
>> 24) & 15;
82 int oparg
= (encoded_op
<< 8) >> 20;
83 int cmparg
= (encoded_op
<< 20) >> 20;
85 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
88 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(u32
)))
95 __futex_atomic_op("move $1, %z5", ret
, oldval
, uaddr
, oparg
);
99 __futex_atomic_op("addu $1, %1, %z5",
100 ret
, oldval
, uaddr
, oparg
);
103 __futex_atomic_op("or $1, %1, %z5",
104 ret
, oldval
, uaddr
, oparg
);
107 __futex_atomic_op("and $1, %1, %z5",
108 ret
, oldval
, uaddr
, ~oparg
);
111 __futex_atomic_op("xor $1, %1, %z5",
112 ret
, oldval
, uaddr
, oparg
);
122 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
123 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
124 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
125 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
126 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
127 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
128 default: ret
= -ENOSYS
;
135 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
136 u32 oldval
, u32 newval
)
141 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
144 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
145 __asm__
__volatile__(
146 "# futex_atomic_cmpxchg_inatomic \n"
151 " bne %1, %z4, 3f \n"
160 " .section .fixup,\"ax\" \n"
164 " .section __ex_table,\"a\" \n"
165 " "__UA_ADDR
"\t1b, 4b \n"
166 " "__UA_ADDR
"\t2b, 4b \n"
168 : "+r" (ret
), "=&r" (val
), "=R" (*uaddr
)
169 : "R" (*uaddr
), "Jr" (oldval
), "Jr" (newval
), "i" (-EFAULT
)
171 } else if (cpu_has_llsc
) {
172 __asm__
__volatile__(
173 "# futex_atomic_cmpxchg_inatomic \n"
178 " bne %1, %z4, 3f \n"
187 " .section .fixup,\"ax\" \n"
191 " .section __ex_table,\"a\" \n"
192 " "__UA_ADDR
"\t1b, 4b \n"
193 " "__UA_ADDR
"\t2b, 4b \n"
195 : "+r" (ret
), "=&r" (val
), "=R" (*uaddr
)
196 : "R" (*uaddr
), "Jr" (oldval
), "Jr" (newval
), "i" (-EFAULT
)
206 #endif /* _ASM_FUTEX_H */