2 * linux/arch/unicore32/include/asm/futex.h
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #ifndef __UNICORE_FUTEX_H__
14 #define __UNICORE_FUTEX_H__
18 #include <linux/futex.h>
19 #include <linux/preempt.h>
20 #include <linux/uaccess.h>
21 #include <linux/errno.h>
23 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
24 __asm__ __volatile__( \
25 "1: ldw.u %1, [%2]\n" \
27 "2: stw.u %0, [%2]\n" \
30 " .pushsection __ex_table,\"a\"\n" \
32 " .long 1b, 4f, 2b, 4f\n" \
34 " .pushsection .fixup,\"ax\"\n" \
38 : "=&r" (ret), "=&r" (oldval) \
39 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
43 futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
45 int op = (encoded_op >> 28) & 7;
46 int cmp = (encoded_op >> 24) & 15;
47 int oparg = (encoded_op << 8) >> 20;
48 int cmparg = (encoded_op << 20) >> 20;
51 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
54 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
57 pagefault_disable(); /* implies preempt_disable() */
61 __futex_atomic_op("mov %0, %3", ret, oldval, uaddr, oparg);
64 __futex_atomic_op("add %0, %1, %3", ret, oldval, uaddr, oparg);
67 __futex_atomic_op("or %0, %1, %3", ret, oldval, uaddr, oparg);
70 __futex_atomic_op("and %0, %1, %3",
71 ret, oldval, uaddr, ~oparg);
74 __futex_atomic_op("xor %0, %1, %3", ret, oldval, uaddr, oparg);
80 pagefault_enable(); /* subsumes preempt_enable() */
85 ret = (oldval == cmparg);
88 ret = (oldval != cmparg);
91 ret = (oldval < cmparg);
94 ret = (oldval >= cmparg);
97 ret = (oldval <= cmparg);
100 ret = (oldval > cmparg);
110 futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
114 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
117 pagefault_disable(); /* implies preempt_disable() */
119 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
120 "1: ldw.u %0, [%3]\n"
123 "2: stw.u %2, [%3]\n"
125 " .pushsection __ex_table,\"a\"\n"
127 " .long 1b, 4f, 2b, 4f\n"
129 " .pushsection .fixup,\"ax\"\n"
134 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
137 pagefault_enable(); /* subsumes preempt_enable() */
142 #endif /* __KERNEL__ */
143 #endif /* __UNICORE_FUTEX_H__ */