uaccess.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. */
  6. #include <linux/module.h>
  7. #include <asm/uaccess.h>
  8. unsigned long __generic_copy_from_user(void *to, const void __user *from,
  9. unsigned long n)
  10. {
  11. unsigned long tmp, res;
  12. asm volatile ("\n"
  13. " tst.l %0\n"
  14. " jeq 2f\n"
  15. "1: "MOVES".l (%1)+,%3\n"
  16. " move.l %3,(%2)+\n"
  17. " subq.l #1,%0\n"
  18. " jne 1b\n"
  19. "2: btst #1,%5\n"
  20. " jeq 4f\n"
  21. "3: "MOVES".w (%1)+,%3\n"
  22. " move.w %3,(%2)+\n"
  23. "4: btst #0,%5\n"
  24. " jeq 6f\n"
  25. "5: "MOVES".b (%1)+,%3\n"
  26. " move.b %3,(%2)+\n"
  27. "6:\n"
  28. " .section .fixup,\"ax\"\n"
  29. " .even\n"
  30. "10: move.l %0,%3\n"
  31. "7: clr.l (%2)+\n"
  32. " subq.l #1,%3\n"
  33. " jne 7b\n"
  34. " lsl.l #2,%0\n"
  35. " btst #1,%5\n"
  36. " jeq 8f\n"
  37. "30: clr.w (%2)+\n"
  38. " addq.l #2,%0\n"
  39. "8: btst #0,%5\n"
  40. " jeq 6b\n"
  41. "50: clr.b (%2)+\n"
  42. " addq.l #1,%0\n"
  43. " jra 6b\n"
  44. " .previous\n"
  45. "\n"
  46. " .section __ex_table,\"a\"\n"
  47. " .align 4\n"
  48. " .long 1b,10b\n"
  49. " .long 3b,30b\n"
  50. " .long 5b,50b\n"
  51. " .previous"
  52. : "=d" (res), "+a" (from), "+a" (to), "=&d" (tmp)
  53. : "0" (n / 4), "d" (n & 3));
  54. return res;
  55. }
  56. EXPORT_SYMBOL(__generic_copy_from_user);
  57. unsigned long __generic_copy_to_user(void __user *to, const void *from,
  58. unsigned long n)
  59. {
  60. unsigned long tmp, res;
  61. asm volatile ("\n"
  62. " tst.l %0\n"
  63. " jeq 4f\n"
  64. "1: move.l (%1)+,%3\n"
  65. "2: "MOVES".l %3,(%2)+\n"
  66. "3: subq.l #1,%0\n"
  67. " jne 1b\n"
  68. "4: btst #1,%5\n"
  69. " jeq 6f\n"
  70. " move.w (%1)+,%3\n"
  71. "5: "MOVES".w %3,(%2)+\n"
  72. "6: btst #0,%5\n"
  73. " jeq 8f\n"
  74. " move.b (%1)+,%3\n"
  75. "7: "MOVES".b %3,(%2)+\n"
  76. "8:\n"
  77. " .section .fixup,\"ax\"\n"
  78. " .even\n"
  79. "20: lsl.l #2,%0\n"
  80. "50: add.l %5,%0\n"
  81. " jra 8b\n"
  82. " .previous\n"
  83. "\n"
  84. " .section __ex_table,\"a\"\n"
  85. " .align 4\n"
  86. " .long 2b,20b\n"
  87. " .long 3b,20b\n"
  88. " .long 5b,50b\n"
  89. " .long 6b,50b\n"
  90. " .long 7b,50b\n"
  91. " .long 8b,50b\n"
  92. " .previous"
  93. : "=d" (res), "+a" (from), "+a" (to), "=&d" (tmp)
  94. : "0" (n / 4), "d" (n & 3));
  95. return res;
  96. }
  97. EXPORT_SYMBOL(__generic_copy_to_user);
  98. /*
  99. * Zero Userspace
  100. */
  101. unsigned long __clear_user(void __user *to, unsigned long n)
  102. {
  103. unsigned long res;
  104. asm volatile ("\n"
  105. " tst.l %0\n"
  106. " jeq 3f\n"
  107. "1: "MOVES".l %2,(%1)+\n"
  108. "2: subq.l #1,%0\n"
  109. " jne 1b\n"
  110. "3: btst #1,%4\n"
  111. " jeq 5f\n"
  112. "4: "MOVES".w %2,(%1)+\n"
  113. "5: btst #0,%4\n"
  114. " jeq 7f\n"
  115. "6: "MOVES".b %2,(%1)\n"
  116. "7:\n"
  117. " .section .fixup,\"ax\"\n"
  118. " .even\n"
  119. "10: lsl.l #2,%0\n"
  120. "40: add.l %4,%0\n"
  121. " jra 7b\n"
  122. " .previous\n"
  123. "\n"
  124. " .section __ex_table,\"a\"\n"
  125. " .align 4\n"
  126. " .long 1b,10b\n"
  127. " .long 2b,10b\n"
  128. " .long 4b,40b\n"
  129. " .long 5b,40b\n"
  130. " .long 6b,40b\n"
  131. " .long 7b,40b\n"
  132. " .previous"
  133. : "=d" (res), "+a" (to)
  134. : "d" (0), "0" (n / 4), "d" (n & 3));
  135. return res;
  136. }
  137. EXPORT_SYMBOL(__clear_user);