1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
4 #ifndef __NDS32_FUTEX_H__
5 #define __NDS32_FUTEX_H__
7 #include <linux/futex.h>
8 #include <linux/uaccess.h>
11 #define __futex_atomic_ex_table(err_reg) \
12 " .pushsection __ex_table,\"a\"\n" \
17 " .pushsection .fixup,\"ax\"\n" \
18 "4: move %0, " err_reg "\n" \
22 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
26 "1: llw %1, [%2+$ta]\n" \
28 "2: scw %0, [%2+$ta]\n" \
32 __futex_atomic_ex_table("%4") \
33 : "=&r" (ret), "=&r" (oldval) \
34 : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
37 futex_atomic_cmpxchg_inatomic(u32
* uval
, u32 __user
* uaddr
,
38 u32 oldval
, u32 newval
)
43 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
47 asm volatile (" movi $ta, #0\n"
48 "1: llw %1, [%6 + $ta]\n"
52 "2: scw %2, [%6 + $ta]\n"
54 "3:\n " __futex_atomic_ex_table("%7")
55 :"+&r"(ret
), "=&r"(val
), "=&r"(tmp
), "=&r"(flags
)
56 :"r"(oldval
), "r"(newval
), "r"(uaddr
), "i"(-EFAULT
)
65 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*uaddr
)
73 __futex_atomic_op("move %0, %3", ret
, oldval
, tmp
, uaddr
,
77 __futex_atomic_op("add %0, %1, %3", ret
, oldval
, tmp
, uaddr
,
81 __futex_atomic_op("or %0, %1, %3", ret
, oldval
, tmp
, uaddr
,
85 __futex_atomic_op("and %0, %1, %3", ret
, oldval
, tmp
, uaddr
,
89 __futex_atomic_op("xor %0, %1, %3", ret
, oldval
, tmp
, uaddr
,
103 #endif /* __NDS32_FUTEX_H__ */