copy_to_user.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/alternative.h>
  18. #include <asm/assembler.h>
  19. #include <asm/cache.h>
  20. #include <asm/cpufeature.h>
  21. #include <asm/sysreg.h>
  22. /*
  23. * Copy to user space from a kernel buffer (alignment handled by the hardware)
  24. *
  25. * Parameters:
  26. * x0 - to
  27. * x1 - from
  28. * x2 - n
  29. * Returns:
  30. * x0 - bytes not copied
  31. */
  32. .macro ldrb1 ptr, regB, val
  33. ldrb \ptr, [\regB], \val
  34. .endm
  35. .macro strb1 ptr, regB, val
  36. uao_user_alternative 9998f, strb, sttrb, \ptr, \regB, \val
  37. .endm
  38. .macro ldrh1 ptr, regB, val
  39. ldrh \ptr, [\regB], \val
  40. .endm
  41. .macro strh1 ptr, regB, val
  42. uao_user_alternative 9998f, strh, sttrh, \ptr, \regB, \val
  43. .endm
  44. .macro ldr1 ptr, regB, val
  45. ldr \ptr, [\regB], \val
  46. .endm
  47. .macro str1 ptr, regB, val
  48. uao_user_alternative 9998f, str, sttr, \ptr, \regB, \val
  49. .endm
  50. .macro ldp1 ptr, regB, regC, val
  51. ldp \ptr, \regB, [\regC], \val
  52. .endm
  53. .macro stp1 ptr, regB, regC, val
  54. uao_stp 9998f, \ptr, \regB, \regC, \val
  55. .endm
  56. end .req x5
  57. ENTRY(__arch_copy_to_user)
  58. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_ALT_PAN_NOT_UAO, \
  59. CONFIG_ARM64_PAN)
  60. add end, x0, x2
  61. #include "copy_template.S"
  62. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \
  63. CONFIG_ARM64_PAN)
  64. mov x0, #0
  65. ret
  66. ENDPROC(__arch_copy_to_user)
  67. .section .fixup,"ax"
  68. .align 2
  69. 9998: sub x0, end, dst // bytes not copied
  70. ret
  71. .previous