futex_64.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _SPARC64_FUTEX_H
  2. #define _SPARC64_FUTEX_H
  3. #include <linux/futex.h>
  4. #include <linux/uaccess.h>
  5. #include <asm/errno.h>
  6. #define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \
  7. __asm__ __volatile__( \
  8. "\n1: lduwa [%3] %%asi, %2\n" \
  9. " " insn "\n" \
  10. "2: casa [%3] %%asi, %2, %1\n" \
  11. " cmp %2, %1\n" \
  12. " bne,pn %%icc, 1b\n" \
  13. " mov 0, %0\n" \
  14. "3:\n" \
  15. " .section .fixup,#alloc,#execinstr\n" \
  16. " .align 4\n" \
  17. "4: sethi %%hi(3b), %0\n" \
  18. " jmpl %0 + %%lo(3b), %%g0\n" \
  19. " mov %5, %0\n" \
  20. " .previous\n" \
  21. " .section __ex_table,\"a\"\n" \
  22. " .align 4\n" \
  23. " .word 1b, 4b\n" \
  24. " .word 2b, 4b\n" \
  25. " .previous\n" \
  26. : "=&r" (ret), "=&r" (oldval), "=&r" (tem) \
  27. : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \
  28. : "memory")
  29. static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
  30. u32 __user *uaddr)
  31. {
  32. int oldval = 0, ret, tem;
  33. if (unlikely((((unsigned long) uaddr) & 0x3UL)))
  34. return -EINVAL;
  35. pagefault_disable();
  36. switch (op) {
  37. case FUTEX_OP_SET:
  38. __futex_cas_op("mov\t%4, %1", ret, oldval, uaddr, oparg);
  39. break;
  40. case FUTEX_OP_ADD:
  41. __futex_cas_op("add\t%2, %4, %1", ret, oldval, uaddr, oparg);
  42. break;
  43. case FUTEX_OP_OR:
  44. __futex_cas_op("or\t%2, %4, %1", ret, oldval, uaddr, oparg);
  45. break;
  46. case FUTEX_OP_ANDN:
  47. __futex_cas_op("andn\t%2, %4, %1", ret, oldval, uaddr, oparg);
  48. break;
  49. case FUTEX_OP_XOR:
  50. __futex_cas_op("xor\t%2, %4, %1", ret, oldval, uaddr, oparg);
  51. break;
  52. default:
  53. ret = -ENOSYS;
  54. }
  55. pagefault_enable();
  56. if (!ret)
  57. *oval = oldval;
  58. return ret;
  59. }
  60. static inline int
  61. futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  62. u32 oldval, u32 newval)
  63. {
  64. int ret = 0;
  65. __asm__ __volatile__(
  66. "\n1: casa [%4] %%asi, %3, %1\n"
  67. "2:\n"
  68. " .section .fixup,#alloc,#execinstr\n"
  69. " .align 4\n"
  70. "3: sethi %%hi(2b), %0\n"
  71. " jmpl %0 + %%lo(2b), %%g0\n"
  72. " mov %5, %0\n"
  73. " .previous\n"
  74. " .section __ex_table,\"a\"\n"
  75. " .align 4\n"
  76. " .word 1b, 3b\n"
  77. " .previous\n"
  78. : "+r" (ret), "=r" (newval)
  79. : "1" (newval), "r" (oldval), "r" (uaddr), "i" (-EFAULT)
  80. : "memory");
  81. *uval = newval;
  82. return ret;
  83. }
  84. #endif /* !(_SPARC64_FUTEX_H) */