usercopy_32.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2010 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. { bz r1, 2f; addi r3, r0, -1 } /* bias down to include NUL */
  26. 1: { lb_u r4, r0; addi r1, r1, -1 }
  27. bz r4, 2f
  28. { bnzt 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 4
  37. .word 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. { bz r2, 2f; move r3, r0 }
  47. 1: { lb_u r4, r1; addi r1, r1, 1; addi r2, r2, -1 }
  48. { sb r0, r4; addi r0, r0, 1 }
  49. bz r2, 2f
  50. bnzt r4, 1b
  51. addi r0, r0, -1 /* don't count the trailing NUL */
  52. 2: { sub r0, r0, r3; jrp lr }
  53. STD_ENDPROC(strncpy_from_user_asm)
  54. .pushsection .fixup,"ax"
  55. strncpy_from_user_fault:
  56. { movei r0, -EFAULT; jrp lr }
  57. ENDPROC(strncpy_from_user_fault)
  58. .section __ex_table,"a"
  59. .align 4
  60. .word 1b, strncpy_from_user_fault
  61. .popsection
  62. /*
  63. * clear_user_asm takes the user target address in r0 and the
  64. * number of bytes to zero in r1.
  65. * It returns the number of uncopiable bytes (hopefully zero) in r0.
  66. * Note that we don't use a separate .fixup section here since we fall
  67. * through into the "fixup" code as the last straight-line bundle anyway.
  68. */
  69. STD_ENTRY(clear_user_asm)
  70. { bz r1, 2f; or r2, r0, r1 }
  71. andi r2, r2, 3
  72. bzt r2, .Lclear_aligned_user_asm
  73. 1: { sb r0, zero; addi r0, r0, 1; addi r1, r1, -1 }
  74. bnzt r1, 1b
  75. 2: { move r0, r1; jrp lr }
  76. .pushsection __ex_table,"a"
  77. .align 4
  78. .word 1b, 2b
  79. .popsection
  80. .Lclear_aligned_user_asm:
  81. 1: { sw r0, zero; addi r0, r0, 4; addi r1, r1, -4 }
  82. bnzt r1, 1b
  83. 2: { move r0, r1; jrp lr }
  84. STD_ENDPROC(clear_user_asm)
  85. .pushsection __ex_table,"a"
  86. .align 4
  87. .word 1b, 2b
  88. .popsection
  89. /*
  90. * flush_user_asm takes the user target address in r0 and the
  91. * number of bytes to flush in r1.
  92. * It returns the number of unflushable bytes (hopefully zero) in r0.
  93. */
  94. STD_ENTRY(flush_user_asm)
  95. bz r1, 2f
  96. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  97. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  98. { and r0, r0, r2; and r1, r1, r2 }
  99. { sub r1, r1, r0 }
  100. 1: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() }
  101. { addi r0, r0, CHIP_FLUSH_STRIDE(); bnzt r1, 1b }
  102. 2: { move r0, r1; jrp lr }
  103. STD_ENDPROC(flush_user_asm)
  104. .pushsection __ex_table,"a"
  105. .align 4
  106. .word 1b, 2b
  107. .popsection
  108. /*
  109. * finv_user_asm takes the user target address in r0 and the
  110. * number of bytes to flush-invalidate in r1.
  111. * It returns the number of not finv'able bytes (hopefully zero) in r0.
  112. */
  113. STD_ENTRY(finv_user_asm)
  114. bz r1, 2f
  115. { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
  116. { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
  117. { and r0, r0, r2; and r1, r1, r2 }
  118. { sub r1, r1, r0 }
  119. 1: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() }
  120. { addi r0, r0, CHIP_FINV_STRIDE(); bnzt r1, 1b }
  121. 2: { move r0, r1; jrp lr }
  122. STD_ENDPROC(finv_user_asm)
  123. .pushsection __ex_table,"a"
  124. .align 4
  125. .word 1b, 2b
  126. .popsection