memset.S 3.9 KB

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