usercopy_64.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/linkage.h>
  15. #include <asm/errno.h>
  16. #include <asm/cache.h>
  17. #include <arch/chip.h>
  18. /* Access user memory, but use MMU to avoid propagating kernel exceptions. */
  19. /*
  20. * strnlen_user_asm takes the pointer in r0, and the length bound in r1.
  21. * It returns the length, including the terminating NUL, or zero on exception.
  22. * If length is greater than the bound, returns one plus the bound.
  23. */
  24. STD_ENTRY(strnlen_user_asm)
  25. { beqz r1, 2f; addi r3, r0, -1 } /* bias down to include NUL */
  26. 1: { ld1u r4, r0; addi r1, r1, -1 }
  27. beqz r4, 2f
  28. { bnezt r1, 1b; addi r0, r0, 1 }
  29. 2: { sub r0, r0, r3; jrp lr }
  30. STD_ENDPROC(strnlen_user_asm)
  31. .pushsection .fixup,"ax"
  32. strnlen_user_fault:
  33. { move r0, zero; jrp lr }
  34. ENDPROC(strnlen_user_fault)
  35. .section __ex_table,"a"
  36. .quad 1b, strnlen_user_fault
  37. .popsection
  38. /*
  39. * strncpy_from_user_asm takes the kernel target pointer in r0,
  40. * the userspace source pointer in r1, and the length bound (including
  41. * the trailing NUL) in r2. On success, it returns the string length
  42. * (not including the trailing NUL), or -EFAULT on failure.
  43. */
  44. STD_ENTRY(strncpy_from_user_asm)
  45. { beqz r2, 2f; move r3, r0 }
  46. 1: { ld1u r4, r1; addi r1, r1, 1; addi r2, r2, -1 }
  47. { st1 r0, r4; addi r0, r0, 1 }
  48. beqz r2, 2f
  49. bnezt r4, 1b
  50. addi r0, r0, -1 /* don't count the trailing NUL */
  51. 2: { sub r0, r0, r3; jrp lr }
  52. STD_ENDPROC(strncpy_from_user_asm)
  53. .pushsection .fixup,"ax"
  54. strncpy_from_user_fault:
  55. { movei r0, -EFAULT; jrp lr }
  56. ENDPROC(strncpy_from_user_fault)
  57. .section __ex_table,"a"
  58. .quad 1b, strncpy_from_user_fault
  59. .popsection
  60. /*
  61. * clear_user_asm takes the user target address in r0 and the
  62. * number of bytes to zero in r1.
  63. * It returns the number of uncopiable bytes (hopefully zero) in r0.
  64. * Note that we don't use a separate .fixup section here since we fall
  65. * through into the "fixup" code as the last straight-line bundle anyway.
  66. */
  67. STD_ENTRY(clear_user_asm)
  68. { beqz r1, 2f; or r2, r0, r1 }
  69. andi r2, r2, 7
  70. beqzt r2, .Lclear_aligned_user_asm
  71. 1: { st1 r0, zero; addi r0, r0, 1; addi r1, r1, -1 }
  72. bnezt r1, 1b
  73. 2: { move r0, r1; jrp lr }
  74. .pushsection __ex_table,"a"
  75. .quad 1b, 2b
  76. .popsection
  77. .Lclear_aligned_user_asm:
  78. 1: { st r0, zero; addi r0, r0, 8; addi r1, r1, -8 }
  79. bnezt r1, 1b
  80. 2: { move r0, r1; jrp lr }
  81. STD_ENDPROC(clear_user_asm)
  82. .pushsection __ex_table,"a"
  83. .quad 1b, 2b
  84. .popsection
  85. /*
  86. * flush_user_asm takes the user target address in r0 and the
  87. * number of bytes to flush in r1.
  88. * It returns the number of unflushable bytes (hopefully zero) in r0.
  89. */
  90. STD_ENTRY(flush_user_asm)
  91. beqz r1, 2f
  92. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  93. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  94. { and r0, r0, r2; and r1, r1, r2 }
  95. { sub r1, r1, r0 }
  96. 1: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() }
  97. { addi r0, r0, CHIP_FLUSH_STRIDE(); bnezt r1, 1b }
  98. 2: { move r0, r1; jrp lr }
  99. STD_ENDPROC(flush_user_asm)
  100. .pushsection __ex_table,"a"
  101. .quad 1b, 2b
  102. .popsection
  103. /*
  104. * inv_user_asm takes the user target address in r0 and the
  105. * number of bytes to invalidate in r1.
  106. * It returns the number of not inv'able bytes (hopefully zero) in r0.
  107. */
  108. STD_ENTRY(inv_user_asm)
  109. beqz r1, 2f
  110. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  111. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  112. { and r0, r0, r2; and r1, r1, r2 }
  113. { sub r1, r1, r0 }
  114. 1: { inv r0; addi r1, r1, -CHIP_INV_STRIDE() }
  115. { addi r0, r0, CHIP_INV_STRIDE(); bnezt r1, 1b }
  116. 2: { move r0, r1; jrp lr }
  117. STD_ENDPROC(inv_user_asm)
  118. .pushsection __ex_table,"a"
  119. .quad 1b, 2b
  120. .popsection
  121. /*
  122. * finv_user_asm takes the user target address in r0 and the
  123. * number of bytes to flush-invalidate in r1.
  124. * It returns the number of not finv'able bytes (hopefully zero) in r0.
  125. */
  126. STD_ENTRY(finv_user_asm)
  127. beqz r1, 2f
  128. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  129. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  130. { and r0, r0, r2; and r1, r1, r2 }
  131. { sub r1, r1, r0 }
  132. 1: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() }
  133. { addi r0, r0, CHIP_FINV_STRIDE(); bnezt r1, 1b }
  134. 2: { move r0, r1; jrp lr }
  135. STD_ENDPROC(finv_user_asm)
  136. .pushsection __ex_table,"a"
  137. .quad 1b, 2b
  138. .popsection