string.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * OpenRISC string.S
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * Modifications for the OpenRISC architecture:
  10. * Copyright (C) 2003 Matjaz Breskvar <[email protected]>
  11. * Copyright (C) 2010-2011 Jonas Bonn <[email protected]>
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/errno.h>
  15. /*
  16. * this can be optimized by doing gcc inline assemlby with
  17. * proper constraints (no need to save args registers...)
  18. *
  19. */
  20. /*
  21. *
  22. * int __copy_tofrom_user(void *to, const void *from, unsigned long size);
  23. *
  24. * NOTE: it returns number of bytes NOT copied !!!
  25. *
  26. */
  27. .global __copy_tofrom_user
  28. __copy_tofrom_user:
  29. l.addi r1,r1,-12
  30. l.sw 0(r1),r6
  31. l.sw 4(r1),r4
  32. l.sw 8(r1),r3
  33. l.addi r11,r5,0
  34. 2: l.sfeq r11,r0
  35. l.bf 1f
  36. l.addi r11,r11,-1
  37. 8: l.lbz r6,0(r4)
  38. 9: l.sb 0(r3),r6
  39. l.addi r3,r3,1
  40. l.j 2b
  41. l.addi r4,r4,1
  42. 1:
  43. l.addi r11,r11,1 // r11 holds the return value
  44. l.lwz r6,0(r1)
  45. l.lwz r4,4(r1)
  46. l.lwz r3,8(r1)
  47. l.jr r9
  48. l.addi r1,r1,12
  49. .section .fixup, "ax"
  50. 99:
  51. l.j 1b
  52. l.nop
  53. .previous
  54. .section __ex_table, "a"
  55. .long 8b, 99b // read fault
  56. .long 9b, 99b // write fault
  57. .previous
  58. /*
  59. * unsigned long clear_user(void *addr, unsigned long size) ;
  60. *
  61. * NOTE: it returns number of bytes NOT cleared !!!
  62. */
  63. .global __clear_user
  64. __clear_user:
  65. l.addi r1,r1,-8
  66. l.sw 0(r1),r4
  67. l.sw 4(r1),r3
  68. 2: l.sfeq r4,r0
  69. l.bf 1f
  70. l.addi r4,r4,-1
  71. 9: l.sb 0(r3),r0
  72. l.j 2b
  73. l.addi r3,r3,1
  74. 1:
  75. l.addi r11,r4,1
  76. l.lwz r4,0(r1)
  77. l.lwz r3,4(r1)
  78. l.jr r9
  79. l.addi r1,r1,8
  80. .section .fixup, "ax"
  81. 99:
  82. l.j 1b
  83. l.nop
  84. .previous
  85. .section __ex_table, "a"
  86. .long 9b, 99b // write fault
  87. .previous