memset.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1998, 1999, 2000 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. * Copyright (C) 2007 by Maciej W. Rozycki
  9. * Copyright (C) 2011, 2012 MIPS Technologies, Inc.
  10. */
  11. #include <asm/asm.h>
  12. #include <asm/asm-offsets.h>
  13. #include <asm/regdef.h>
  14. #if LONGSIZE == 4
  15. #define LONG_S_L swl
  16. #define LONG_S_R swr
  17. #else
  18. #define LONG_S_L sdl
  19. #define LONG_S_R sdr
  20. #endif
  21. #ifdef CONFIG_CPU_MICROMIPS
  22. #define STORSIZE (LONGSIZE * 2)
  23. #define STORMASK (STORSIZE - 1)
  24. #define FILL64RG t8
  25. #define FILLPTRG t7
  26. #undef LONG_S
  27. #define LONG_S LONG_SP
  28. #else
  29. #define STORSIZE LONGSIZE
  30. #define STORMASK LONGMASK
  31. #define FILL64RG a1
  32. #define FILLPTRG t0
  33. #endif
  34. #define LEGACY_MODE 1
  35. #define EVA_MODE 2
  36. /*
  37. * No need to protect it with EVA #ifdefery. The generated block of code
  38. * will never be assembled if EVA is not enabled.
  39. */
  40. #define __EVAFY(insn, reg, addr) __BUILD_EVA_INSN(insn##e, reg, addr)
  41. #define ___BUILD_EVA_INSN(insn, reg, addr) __EVAFY(insn, reg, addr)
  42. #define EX(insn,reg,addr,handler) \
  43. .if \mode == LEGACY_MODE; \
  44. 9: insn reg, addr; \
  45. .else; \
  46. 9: ___BUILD_EVA_INSN(insn, reg, addr); \
  47. .endif; \
  48. .section __ex_table,"a"; \
  49. PTR 9b, handler; \
  50. .previous
  51. .macro f_fill64 dst, offset, val, fixup, mode
  52. EX(LONG_S, \val, (\offset + 0 * STORSIZE)(\dst), \fixup)
  53. EX(LONG_S, \val, (\offset + 1 * STORSIZE)(\dst), \fixup)
  54. EX(LONG_S, \val, (\offset + 2 * STORSIZE)(\dst), \fixup)
  55. EX(LONG_S, \val, (\offset + 3 * STORSIZE)(\dst), \fixup)
  56. #if ((defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) || !defined(CONFIG_CPU_MICROMIPS))
  57. EX(LONG_S, \val, (\offset + 4 * STORSIZE)(\dst), \fixup)
  58. EX(LONG_S, \val, (\offset + 5 * STORSIZE)(\dst), \fixup)
  59. EX(LONG_S, \val, (\offset + 6 * STORSIZE)(\dst), \fixup)
  60. EX(LONG_S, \val, (\offset + 7 * STORSIZE)(\dst), \fixup)
  61. #endif
  62. #if (!defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4))
  63. EX(LONG_S, \val, (\offset + 8 * STORSIZE)(\dst), \fixup)
  64. EX(LONG_S, \val, (\offset + 9 * STORSIZE)(\dst), \fixup)
  65. EX(LONG_S, \val, (\offset + 10 * STORSIZE)(\dst), \fixup)
  66. EX(LONG_S, \val, (\offset + 11 * STORSIZE)(\dst), \fixup)
  67. EX(LONG_S, \val, (\offset + 12 * STORSIZE)(\dst), \fixup)
  68. EX(LONG_S, \val, (\offset + 13 * STORSIZE)(\dst), \fixup)
  69. EX(LONG_S, \val, (\offset + 14 * STORSIZE)(\dst), \fixup)
  70. EX(LONG_S, \val, (\offset + 15 * STORSIZE)(\dst), \fixup)
  71. #endif
  72. .endm
  73. .set noreorder
  74. .align 5
  75. /*
  76. * Macro to generate the __bzero{,_user} symbol
  77. * Arguments:
  78. * mode: LEGACY_MODE or EVA_MODE
  79. */
  80. .macro __BUILD_BZERO mode
  81. /* Initialize __memset if this is the first time we call this macro */
  82. .ifnotdef __memset
  83. .set __memset, 1
  84. .hidden __memset /* Make sure it does not leak */
  85. .endif
  86. sltiu t0, a2, STORSIZE /* very small region? */
  87. bnez t0, .Lsmall_memset\@
  88. andi t0, a0, STORMASK /* aligned? */
  89. #ifdef CONFIG_CPU_MICROMIPS
  90. move t8, a1 /* used by 'swp' instruction */
  91. move t9, a1
  92. #endif
  93. #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
  94. beqz t0, 1f
  95. PTR_SUBU t0, STORSIZE /* alignment in bytes */
  96. #else
  97. .set noat
  98. li AT, STORSIZE
  99. beqz t0, 1f
  100. PTR_SUBU t0, AT /* alignment in bytes */
  101. .set at
  102. #endif
  103. R10KCBARRIER(0(ra))
  104. #ifdef __MIPSEB__
  105. EX(LONG_S_L, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
  106. #endif
  107. #ifdef __MIPSEL__
  108. EX(LONG_S_R, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
  109. #endif
  110. PTR_SUBU a0, t0 /* long align ptr */
  111. PTR_ADDU a2, t0 /* correct size */
  112. 1: ori t1, a2, 0x3f /* # of full blocks */
  113. xori t1, 0x3f
  114. beqz t1, .Lmemset_partial\@ /* no block to fill */
  115. andi t0, a2, 0x40-STORSIZE
  116. PTR_ADDU t1, a0 /* end address */
  117. .set reorder
  118. 1: PTR_ADDIU a0, 64
  119. R10KCBARRIER(0(ra))
  120. f_fill64 a0, -64, FILL64RG, .Lfwd_fixup\@, \mode
  121. bne t1, a0, 1b
  122. .set noreorder
  123. .Lmemset_partial\@:
  124. R10KCBARRIER(0(ra))
  125. PTR_LA t1, 2f /* where to start */
  126. #ifdef CONFIG_CPU_MICROMIPS
  127. LONG_SRL t7, t0, 1
  128. #endif
  129. #if LONGSIZE == 4
  130. PTR_SUBU t1, FILLPTRG
  131. #else
  132. .set noat
  133. LONG_SRL AT, FILLPTRG, 1
  134. PTR_SUBU t1, AT
  135. .set at
  136. #endif
  137. jr t1
  138. PTR_ADDU a0, t0 /* dest ptr */
  139. .set push
  140. .set noreorder
  141. .set nomacro
  142. /* ... but first do longs ... */
  143. f_fill64 a0, -64, FILL64RG, .Lpartial_fixup\@, \mode
  144. 2: .set pop
  145. andi a2, STORMASK /* At most one long to go */
  146. beqz a2, 1f
  147. PTR_ADDU a0, a2 /* What's left */
  148. R10KCBARRIER(0(ra))
  149. #ifdef __MIPSEB__
  150. EX(LONG_S_R, a1, -1(a0), .Llast_fixup\@)
  151. #endif
  152. #ifdef __MIPSEL__
  153. EX(LONG_S_L, a1, -1(a0), .Llast_fixup\@)
  154. #endif
  155. 1: jr ra
  156. move a2, zero
  157. .Lsmall_memset\@:
  158. beqz a2, 2f
  159. PTR_ADDU t1, a0, a2
  160. 1: PTR_ADDIU a0, 1 /* fill bytewise */
  161. R10KCBARRIER(0(ra))
  162. bne t1, a0, 1b
  163. sb a1, -1(a0)
  164. 2: jr ra /* done */
  165. move a2, zero
  166. .if __memset == 1
  167. END(memset)
  168. .set __memset, 0
  169. .hidden __memset
  170. .endif
  171. .Lfirst_fixup\@:
  172. jr ra
  173. nop
  174. .Lfwd_fixup\@:
  175. PTR_L t0, TI_TASK($28)
  176. andi a2, 0x3f
  177. LONG_L t0, THREAD_BUADDR(t0)
  178. LONG_ADDU a2, t1
  179. jr ra
  180. LONG_SUBU a2, t0
  181. .Lpartial_fixup\@:
  182. PTR_L t0, TI_TASK($28)
  183. andi a2, STORMASK
  184. LONG_L t0, THREAD_BUADDR(t0)
  185. LONG_ADDU a2, t1
  186. jr ra
  187. LONG_SUBU a2, t0
  188. .Llast_fixup\@:
  189. jr ra
  190. andi v1, a2, STORMASK
  191. .endm
  192. /*
  193. * memset(void *s, int c, size_t n)
  194. *
  195. * a0: start of area to clear
  196. * a1: char to fill with
  197. * a2: size of area to clear
  198. */
  199. LEAF(memset)
  200. beqz a1, 1f
  201. move v0, a0 /* result */
  202. andi a1, 0xff /* spread fillword */
  203. LONG_SLL t1, a1, 8
  204. or a1, t1
  205. LONG_SLL t1, a1, 16
  206. #if LONGSIZE == 8
  207. or a1, t1
  208. LONG_SLL t1, a1, 32
  209. #endif
  210. or a1, t1
  211. 1:
  212. #ifndef CONFIG_EVA
  213. FEXPORT(__bzero)
  214. #endif
  215. __BUILD_BZERO LEGACY_MODE
  216. #ifdef CONFIG_EVA
  217. LEAF(__bzero)
  218. __BUILD_BZERO EVA_MODE
  219. END(__bzero)
  220. #endif