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