1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/futex.h>
6 #include <linux/uaccess.h>
9 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11 register unsigned long r8 __asm ("r8") = 0; \
12 __asm__ __volatile__( \
14 "[1:] " insn ";; \n" \
15 " .xdata4 \"__ex_table\", 1b-., 2f-. \n" \
17 : "+r" (r8), "=r" (oldval) \
18 : "r" (uaddr), "r" (oparg) \
23 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
25 register unsigned long r8 __asm ("r8") = 0; \
28 __asm__ __volatile__( \
30 "[1:] ld4 %3=[%4];; \n" \
33 " mov ar.ccv=%2;; \n" \
34 "[2:] cmpxchg4.acq %1=[%4],%3,ar.ccv;; \n" \
35 " .xdata4 \"__ex_table\", 1b-., 3f-.\n" \
36 " .xdata4 \"__ex_table\", 2b-., 3f-.\n" \
38 : "+r" (r8), "=r" (val), "=&r" (oldval), \
40 : "r" (uaddr), "r" (oparg) \
44 } while (unlikely (val != oldval)); \
49 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*uaddr
)
57 __futex_atomic_op1("xchg4 %1=[%2],%3", ret
, oldval
, uaddr
,
61 __futex_atomic_op2("add %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
64 __futex_atomic_op2("or %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
67 __futex_atomic_op2("and %3=%3,%5", ret
, oldval
, uaddr
,
71 __futex_atomic_op2("xor %3=%3,%5", ret
, oldval
, uaddr
, oparg
);
86 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
87 u32 oldval
, u32 newval
)
89 if (!access_ok(uaddr
, sizeof(u32
)))
93 register unsigned long r8
__asm ("r8") = 0;
98 "[1:] cmpxchg4.acq %1=[%2],%3,ar.ccv \n"
99 " .xdata4 \"__ex_table\", 1b-., 2f-. \n"
101 : "+r" (r8
), "=&r" (prev
)
102 : "r" (uaddr
), "r" (newval
),
103 "rO" ((long) (unsigned) oldval
)
110 #endif /* _ASM_FUTEX_H */