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. .type __bzero,#function
  59. .globl memset
  60. EXPORT_SYMBOL(__bzero)
  61. EXPORT_SYMBOL(memset)
  62. .globl __memset_start, __memset_end
  63. __memset_start:
  64. memset:
  65. mov %o0, %g1
  66. mov 1, %g4
  67. and %o1, 0xff, %g3
  68. sll %g3, 8, %g2
  69. or %g3, %g2, %g3
  70. sll %g3, 16, %g2
  71. or %g3, %g2, %g3
  72. b 1f
  73. mov %o2, %o1
  74. 3:
  75. cmp %o2, 3
  76. be 2f
  77. EX(stb %g3, [%o0], sub %o1, 0)
  78. cmp %o2, 2
  79. be 2f
  80. EX(stb %g3, [%o0 + 0x01], sub %o1, 1)
  81. EX(stb %g3, [%o0 + 0x02], sub %o1, 2)
  82. 2:
  83. sub %o2, 4, %o2
  84. add %o1, %o2, %o1
  85. b 4f
  86. sub %o0, %o2, %o0
  87. __bzero:
  88. clr %g4
  89. mov %g0, %g3
  90. 1:
  91. cmp %o1, 7
  92. bleu 7f
  93. andcc %o0, 3, %o2
  94. bne 3b
  95. 4:
  96. andcc %o0, 4, %g0
  97. be 2f
  98. mov %g3, %g2
  99. EX(st %g3, [%o0], sub %o1, 0)
  100. sub %o1, 4, %o1
  101. add %o0, 4, %o0
  102. 2:
  103. andcc %o1, 0xffffff80, %o3 ! Now everything is 8 aligned and o1 is len to run
  104. be 9f
  105. andcc %o1, 0x78, %o2
  106. 10:
  107. ZERO_BIG_BLOCK(%o0, 0x00, %g2)
  108. subcc %o3, 128, %o3
  109. ZERO_BIG_BLOCK(%o0, 0x40, %g2)
  110. 11:
  111. EXT(10b, 11b, 20f)
  112. bne 10b
  113. add %o0, 128, %o0
  114. orcc %o2, %g0, %g0
  115. 9:
  116. be 13f
  117. andcc %o1, 7, %o1
  118. srl %o2, 1, %o3
  119. set 13f, %o4
  120. sub %o4, %o3, %o4
  121. jmp %o4
  122. add %o0, %o2, %o0
  123. 12:
  124. ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
  125. ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
  126. 13:
  127. be 8f
  128. andcc %o1, 4, %g0
  129. be 1f
  130. andcc %o1, 2, %g0
  131. EX(st %g3, [%o0], and %o1, 7)
  132. add %o0, 4, %o0
  133. 1:
  134. be 1f
  135. andcc %o1, 1, %g0
  136. EX(sth %g3, [%o0], and %o1, 3)
  137. add %o0, 2, %o0
  138. 1:
  139. bne,a 8f
  140. EX(stb %g3, [%o0], and %o1, 1)
  141. 8:
  142. b 0f
  143. nop
  144. 7:
  145. be 13b
  146. orcc %o1, 0, %g0
  147. be 0f
  148. 8:
  149. add %o0, 1, %o0
  150. subcc %o1, 1, %o1
  151. bne 8b
  152. EX(stb %g3, [%o0 - 1], add %o1, 1)
  153. 0:
  154. andcc %g4, 1, %g0
  155. be 5f
  156. nop
  157. retl
  158. mov %g1, %o0
  159. 5:
  160. retl
  161. clr %o0
  162. __memset_end:
  163. .section .fixup,#alloc,#execinstr
  164. .align 4
  165. 20:
  166. cmp %g2, 8
  167. bleu 1f
  168. and %o1, 0x7f, %o1
  169. sub %g2, 9, %g2
  170. add %o3, 64, %o3
  171. 1:
  172. sll %g2, 3, %g2
  173. add %o3, %o1, %o0
  174. b 30f
  175. sub %o0, %g2, %o0
  176. 21:
  177. mov 8, %o0
  178. and %o1, 7, %o1
  179. sub %o0, %g2, %o0
  180. sll %o0, 3, %o0
  181. b 30f
  182. add %o0, %o1, %o0
  183. 30:
  184. /* %o4 is faulting address, %o5 is %pc where fault occurred */
  185. save %sp, -104, %sp
  186. mov %i5, %o0
  187. mov %i7, %o1
  188. call lookup_fault
  189. mov %i4, %o2
  190. ret
  191. restore
  192. .globl __bzero_end
  193. __bzero_end: