memset.S 3.8 KB

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