uaccess_32.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * User space memory access functions
  3. *
  4. * Copyright (C) 1999, 2002 Niibe Yutaka
  5. * Copyright (C) 2003 - 2008 Paul Mundt
  6. *
  7. * Based on:
  8. * MIPS implementation version 1.15 by
  9. * Copyright (C) 1996, 1997, 1998 by Ralf Baechle
  10. * and i386 version.
  11. */
  12. #ifndef __ASM_SH_UACCESS_32_H
  13. #define __ASM_SH_UACCESS_32_H
  14. #define __get_user_size(x,ptr,size,retval) \
  15. do { \
  16. retval = 0; \
  17. switch (size) { \
  18. case 1: \
  19. __get_user_asm(x, ptr, retval, "b"); \
  20. break; \
  21. case 2: \
  22. __get_user_asm(x, ptr, retval, "w"); \
  23. break; \
  24. case 4: \
  25. __get_user_asm(x, ptr, retval, "l"); \
  26. break; \
  27. default: \
  28. __get_user_unknown(); \
  29. break; \
  30. } \
  31. } while (0)
  32. #ifdef CONFIG_MMU
  33. #define __get_user_asm(x, addr, err, insn) \
  34. ({ \
  35. __asm__ __volatile__( \
  36. "1:\n\t" \
  37. "mov." insn " %2, %1\n\t" \
  38. "2:\n" \
  39. ".section .fixup,\"ax\"\n" \
  40. "3:\n\t" \
  41. "mov #0, %1\n\t" \
  42. "mov.l 4f, %0\n\t" \
  43. "jmp @%0\n\t" \
  44. " mov %3, %0\n\t" \
  45. ".balign 4\n" \
  46. "4: .long 2b\n\t" \
  47. ".previous\n" \
  48. ".section __ex_table,\"a\"\n\t" \
  49. ".long 1b, 3b\n\t" \
  50. ".previous" \
  51. :"=&r" (err), "=&r" (x) \
  52. :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); })
  53. #else
  54. #define __get_user_asm(x, addr, err, insn) \
  55. do { \
  56. __asm__ __volatile__ ( \
  57. "mov." insn " %1, %0\n\t" \
  58. : "=&r" (x) \
  59. : "m" (__m(addr)) \
  60. ); \
  61. } while (0)
  62. #endif /* CONFIG_MMU */
  63. extern void __get_user_unknown(void);
  64. #define __put_user_size(x,ptr,size,retval) \
  65. do { \
  66. retval = 0; \
  67. switch (size) { \
  68. case 1: \
  69. __put_user_asm(x, ptr, retval, "b"); \
  70. break; \
  71. case 2: \
  72. __put_user_asm(x, ptr, retval, "w"); \
  73. break; \
  74. case 4: \
  75. __put_user_asm(x, ptr, retval, "l"); \
  76. break; \
  77. case 8: \
  78. __put_user_u64(x, ptr, retval); \
  79. break; \
  80. default: \
  81. __put_user_unknown(); \
  82. } \
  83. } while (0)
  84. #ifdef CONFIG_MMU
  85. #define __put_user_asm(x, addr, err, insn) \
  86. do { \
  87. __asm__ __volatile__ ( \
  88. "1:\n\t" \
  89. "mov." insn " %1, %2\n\t" \
  90. "2:\n" \
  91. ".section .fixup,\"ax\"\n" \
  92. "3:\n\t" \
  93. "mov.l 4f, %0\n\t" \
  94. "jmp @%0\n\t" \
  95. " mov %3, %0\n\t" \
  96. ".balign 4\n" \
  97. "4: .long 2b\n\t" \
  98. ".previous\n" \
  99. ".section __ex_table,\"a\"\n\t" \
  100. ".long 1b, 3b\n\t" \
  101. ".previous" \
  102. : "=&r" (err) \
  103. : "r" (x), "m" (__m(addr)), "i" (-EFAULT), \
  104. "0" (err) \
  105. : "memory" \
  106. ); \
  107. } while (0)
  108. #else
  109. #define __put_user_asm(x, addr, err, insn) \
  110. do { \
  111. __asm__ __volatile__ ( \
  112. "mov." insn " %0, %1\n\t" \
  113. : /* no outputs */ \
  114. : "r" (x), "m" (__m(addr)) \
  115. : "memory" \
  116. ); \
  117. } while (0)
  118. #endif /* CONFIG_MMU */
  119. #if defined(CONFIG_CPU_LITTLE_ENDIAN)
  120. #define __put_user_u64(val,addr,retval) \
  121. ({ \
  122. __asm__ __volatile__( \
  123. "1:\n\t" \
  124. "mov.l %R1,%2\n\t" \
  125. "mov.l %S1,%T2\n\t" \
  126. "2:\n" \
  127. ".section .fixup,\"ax\"\n" \
  128. "3:\n\t" \
  129. "mov.l 4f,%0\n\t" \
  130. "jmp @%0\n\t" \
  131. " mov %3,%0\n\t" \
  132. ".balign 4\n" \
  133. "4: .long 2b\n\t" \
  134. ".previous\n" \
  135. ".section __ex_table,\"a\"\n\t" \
  136. ".long 1b, 3b\n\t" \
  137. ".previous" \
  138. : "=r" (retval) \
  139. : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
  140. : "memory"); })
  141. #else
  142. #define __put_user_u64(val,addr,retval) \
  143. ({ \
  144. __asm__ __volatile__( \
  145. "1:\n\t" \
  146. "mov.l %S1,%2\n\t" \
  147. "mov.l %R1,%T2\n\t" \
  148. "2:\n" \
  149. ".section .fixup,\"ax\"\n" \
  150. "3:\n\t" \
  151. "mov.l 4f,%0\n\t" \
  152. "jmp @%0\n\t" \
  153. " mov %3,%0\n\t" \
  154. ".balign 4\n" \
  155. "4: .long 2b\n\t" \
  156. ".previous\n" \
  157. ".section __ex_table,\"a\"\n\t" \
  158. ".long 1b, 3b\n\t" \
  159. ".previous" \
  160. : "=r" (retval) \
  161. : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
  162. : "memory"); })
  163. #endif
  164. extern void __put_user_unknown(void);
  165. #endif /* __ASM_SH_UACCESS_32_H */