memset.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* linux/arch/sparc/lib/memset.S: Sparc optimized memset, bzero and clear_user code
  2. * Copyright (C) 1991,1996 Free Software Foundation
  3. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. *
  6. * Returns 0, if ok, and number of bytes not yet set if exception
  7. * occurs and we were called as clear_user.
  8. */
  9. #include <asm/ptrace.h>
  10. /* Work around cpp -rob */
  11. #define ALLOC #alloc
  12. #define EXECINSTR #execinstr
  13. #define EX(x,y,a,b) \
  14. 98: x,y; \
  15. .section .fixup,ALLOC,EXECINSTR; \
  16. .align 4; \
  17. 99: ba 30f; \
  18. a, b, %o0; \
  19. .section __ex_table,ALLOC; \
  20. .align 4; \
  21. .word 98b, 99b; \
  22. .text; \
  23. .align 4
  24. #define EXT(start,end,handler) \
  25. .section __ex_table,ALLOC; \
  26. .align 4; \
  27. .word start, 0, end, handler; \
  28. .text; \
  29. .align 4
  30. /* Please don't change these macros, unless you change the logic
  31. * in the .fixup section below as well.
  32. * Store 64 bytes at (BASE + OFFSET) using value SOURCE. */
  33. #define ZERO_BIG_BLOCK(base, offset, source) \
  34. std source, [base + offset + 0x00]; \
  35. std source, [base + offset + 0x08]; \
  36. std source, [base + offset + 0x10]; \
  37. std source, [base + offset + 0x18]; \
  38. std source, [base + offset + 0x20]; \
  39. std source, [base + offset + 0x28]; \
  40. std source, [base + offset + 0x30]; \
  41. std source, [base + offset + 0x38];
  42. #define ZERO_LAST_BLOCKS(base, offset, source) \
  43. std source, [base - offset - 0x38]; \
  44. std source, [base - offset - 0x30]; \
  45. std source, [base - offset - 0x28]; \
  46. std source, [base - offset - 0x20]; \
  47. std source, [base - offset - 0x18]; \
  48. std source, [base - offset - 0x10]; \
  49. std source, [base - offset - 0x08]; \
  50. std source, [base - offset - 0x00];
  51. .text
  52. .align 4
  53. .globl __bzero_begin
  54. __bzero_begin:
  55. .globl __bzero
  56. .globl memset
  57. .globl __memset_start, __memset_end
  58. __memset_start:
  59. memset:
  60. and %o1, 0xff, %g3
  61. sll %g3, 8, %g2
  62. or %g3, %g2, %g3
  63. sll %g3, 16, %g2
  64. or %g3, %g2, %g3
  65. b 1f
  66. mov %o2, %o1
  67. 3:
  68. cmp %o2, 3
  69. be 2f
  70. EX(stb %g3, [%o0], sub %o1, 0)
  71. cmp %o2, 2
  72. be 2f
  73. EX(stb %g3, [%o0 + 0x01], sub %o1, 1)
  74. EX(stb %g3, [%o0 + 0x02], sub %o1, 2)
  75. 2:
  76. sub %o2, 4, %o2
  77. add %o1, %o2, %o1
  78. b 4f
  79. sub %o0, %o2, %o0
  80. __bzero:
  81. mov %g0, %g3
  82. 1:
  83. cmp %o1, 7
  84. bleu 7f
  85. andcc %o0, 3, %o2
  86. bne 3b
  87. 4:
  88. andcc %o0, 4, %g0
  89. be 2f
  90. mov %g3, %g2
  91. EX(st %g3, [%o0], sub %o1, 0)
  92. sub %o1, 4, %o1
  93. add %o0, 4, %o0
  94. 2:
  95. andcc %o1, 0xffffff80, %o3 ! Now everything is 8 aligned and o1 is len to run
  96. be 9f
  97. andcc %o1, 0x78, %o2
  98. 10:
  99. ZERO_BIG_BLOCK(%o0, 0x00, %g2)
  100. subcc %o3, 128, %o3
  101. ZERO_BIG_BLOCK(%o0, 0x40, %g2)
  102. 11:
  103. EXT(10b, 11b, 20f)
  104. bne 10b
  105. add %o0, 128, %o0
  106. orcc %o2, %g0, %g0
  107. 9:
  108. be 13f
  109. andcc %o1, 7, %o1
  110. srl %o2, 1, %o3
  111. set 13f, %o4
  112. sub %o4, %o3, %o4
  113. jmp %o4
  114. add %o0, %o2, %o0
  115. 12:
  116. ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
  117. ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
  118. 13:
  119. be 8f
  120. andcc %o1, 4, %g0
  121. be 1f
  122. andcc %o1, 2, %g0
  123. EX(st %g3, [%o0], and %o1, 7)
  124. add %o0, 4, %o0
  125. 1:
  126. be 1f
  127. andcc %o1, 1, %g0
  128. EX(sth %g3, [%o0], and %o1, 3)
  129. add %o0, 2, %o0
  130. 1:
  131. bne,a 8f
  132. EX(stb %g3, [%o0], and %o1, 1)
  133. 8:
  134. retl
  135. clr %o0
  136. 7:
  137. be 13b
  138. orcc %o1, 0, %g0
  139. be 0f
  140. 8:
  141. add %o0, 1, %o0
  142. subcc %o1, 1, %o1
  143. bne 8b
  144. EX(stb %g3, [%o0 - 1], add %o1, 1)
  145. 0:
  146. retl
  147. clr %o0
  148. __memset_end:
  149. .section .fixup,#alloc,#execinstr
  150. .align 4
  151. 20:
  152. cmp %g2, 8
  153. bleu 1f
  154. and %o1, 0x7f, %o1
  155. sub %g2, 9, %g2
  156. add %o3, 64, %o3
  157. 1:
  158. sll %g2, 3, %g2
  159. add %o3, %o1, %o0
  160. b 30f
  161. sub %o0, %g2, %o0
  162. 21:
  163. mov 8, %o0
  164. and %o1, 7, %o1
  165. sub %o0, %g2, %o0
  166. sll %o0, 3, %o0
  167. b 30f
  168. add %o0, %o1, %o0
  169. 30:
  170. /* %o4 is faulting address, %o5 is %pc where fault occurred */
  171. save %sp, -104, %sp
  172. mov %i5, %o0
  173. mov %i7, %o1
  174. call lookup_fault
  175. mov %i4, %o2
  176. ret
  177. restore
  178. .globl __bzero_end
  179. __bzero_end: