memset.S 4.0 KB

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