usercopy_64.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. .align 8
  37. .quad 1b, strnlen_user_fault
  38. .popsection
  39. /*
  40. * strncpy_from_user_asm takes the kernel target pointer in r0,
  41. * the userspace source pointer in r1, and the length bound (including
  42. * the trailing NUL) in r2. On success, it returns the string length
  43. * (not including the trailing NUL), or -EFAULT on failure.
  44. */
  45. STD_ENTRY(strncpy_from_user_asm)
  46. { beqz r2, 2f; move r3, r0 }
  47. 1: { ld1u r4, r1; addi r1, r1, 1; addi r2, r2, -1 }
  48. { st1 r0, r4; addi r0, r0, 1 }
  49. beqz r4, 2f
  50. bnezt r2, 1b
  51. { sub r0, r0, r3; jrp lr }
  52. 2: addi r0, r0, -1 /* don't count the trailing NUL */
  53. { sub r0, r0, r3; jrp lr }
  54. STD_ENDPROC(strncpy_from_user_asm)
  55. .pushsection .fixup,"ax"
  56. strncpy_from_user_fault:
  57. { movei r0, -EFAULT; jrp lr }
  58. ENDPROC(strncpy_from_user_fault)
  59. .section __ex_table,"a"
  60. .align 8
  61. .quad 1b, strncpy_from_user_fault
  62. .popsection
  63. /*
  64. * clear_user_asm takes the user target address in r0 and the
  65. * number of bytes to zero in r1.
  66. * It returns the number of uncopiable bytes (hopefully zero) in r0.
  67. * Note that we don't use a separate .fixup section here since we fall
  68. * through into the "fixup" code as the last straight-line bundle anyway.
  69. */
  70. STD_ENTRY(clear_user_asm)
  71. { beqz r1, 2f; or r2, r0, r1 }
  72. andi r2, r2, 7
  73. beqzt r2, .Lclear_aligned_user_asm
  74. 1: { st1 r0, zero; addi r0, r0, 1; addi r1, r1, -1 }
  75. bnezt r1, 1b
  76. 2: { move r0, r1; jrp lr }
  77. .pushsection __ex_table,"a"
  78. .align 8
  79. .quad 1b, 2b
  80. .popsection
  81. .Lclear_aligned_user_asm:
  82. 1: { st r0, zero; addi r0, r0, 8; addi r1, r1, -8 }
  83. bnezt r1, 1b
  84. 2: { move r0, r1; jrp lr }
  85. STD_ENDPROC(clear_user_asm)
  86. .pushsection __ex_table,"a"
  87. .align 8
  88. .quad 1b, 2b
  89. .popsection
  90. /*
  91. * flush_user_asm takes the user target address in r0 and the
  92. * number of bytes to flush in r1.
  93. * It returns the number of unflushable bytes (hopefully zero) in r0.
  94. */
  95. STD_ENTRY(flush_user_asm)
  96. beqz r1, 2f
  97. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  98. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  99. { and r0, r0, r2; and r1, r1, r2 }
  100. { sub r1, r1, r0 }
  101. 1: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() }
  102. { addi r0, r0, CHIP_FLUSH_STRIDE(); bnezt r1, 1b }
  103. 2: { move r0, r1; jrp lr }
  104. STD_ENDPROC(flush_user_asm)
  105. .pushsection __ex_table,"a"
  106. .align 8
  107. .quad 1b, 2b
  108. .popsection
  109. /*
  110. * finv_user_asm takes the user target address in r0 and the
  111. * number of bytes to flush-invalidate in r1.
  112. * It returns the number of not finv'able bytes (hopefully zero) in r0.
  113. */
  114. STD_ENTRY(finv_user_asm)
  115. beqz r1, 2f
  116. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  117. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  118. { and r0, r0, r2; and r1, r1, r2 }
  119. { sub r1, r1, r0 }
  120. 1: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() }
  121. { addi r0, r0, CHIP_FINV_STRIDE(); bnezt r1, 1b }
  122. 2: { move r0, r1; jrp lr }
  123. STD_ENDPROC(finv_user_asm)
  124. .pushsection __ex_table,"a"
  125. .align 8
  126. .quad 1b, 2b
  127. .popsection