string.S 2.0 KB

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