memset.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 Maciej W. Rozycki
  9. */
  10. #include <asm/asm.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/regdef.h>
  13. #if LONGSIZE == 4
  14. #define LONG_S_L swl
  15. #define LONG_S_R swr
  16. #else
  17. #define LONG_S_L sdl
  18. #define LONG_S_R sdr
  19. #endif
  20. #define EX(insn,reg,addr,handler) \
  21. 9: insn reg, addr; \
  22. .section __ex_table,"a"; \
  23. PTR 9b, handler; \
  24. .previous
  25. .macro f_fill64 dst, offset, val, fixup
  26. EX(LONG_S, \val, (\offset + 0 * LONGSIZE)(\dst), \fixup)
  27. EX(LONG_S, \val, (\offset + 1 * LONGSIZE)(\dst), \fixup)
  28. EX(LONG_S, \val, (\offset + 2 * LONGSIZE)(\dst), \fixup)
  29. EX(LONG_S, \val, (\offset + 3 * LONGSIZE)(\dst), \fixup)
  30. EX(LONG_S, \val, (\offset + 4 * LONGSIZE)(\dst), \fixup)
  31. EX(LONG_S, \val, (\offset + 5 * LONGSIZE)(\dst), \fixup)
  32. EX(LONG_S, \val, (\offset + 6 * LONGSIZE)(\dst), \fixup)
  33. EX(LONG_S, \val, (\offset + 7 * LONGSIZE)(\dst), \fixup)
  34. #if LONGSIZE == 4
  35. EX(LONG_S, \val, (\offset + 8 * LONGSIZE)(\dst), \fixup)
  36. EX(LONG_S, \val, (\offset + 9 * LONGSIZE)(\dst), \fixup)
  37. EX(LONG_S, \val, (\offset + 10 * LONGSIZE)(\dst), \fixup)
  38. EX(LONG_S, \val, (\offset + 11 * LONGSIZE)(\dst), \fixup)
  39. EX(LONG_S, \val, (\offset + 12 * LONGSIZE)(\dst), \fixup)
  40. EX(LONG_S, \val, (\offset + 13 * LONGSIZE)(\dst), \fixup)
  41. EX(LONG_S, \val, (\offset + 14 * LONGSIZE)(\dst), \fixup)
  42. EX(LONG_S, \val, (\offset + 15 * LONGSIZE)(\dst), \fixup)
  43. #endif
  44. .endm
  45. /*
  46. * memset(void *s, int c, size_t n)
  47. *
  48. * a0: start of area to clear
  49. * a1: char to fill with
  50. * a2: size of area to clear
  51. */
  52. .set noreorder
  53. .align 5
  54. LEAF(memset)
  55. beqz a1, 1f
  56. move v0, a0 /* result */
  57. andi a1, 0xff /* spread fillword */
  58. LONG_SLL t1, a1, 8
  59. or a1, t1
  60. LONG_SLL t1, a1, 16
  61. #if LONGSIZE == 8
  62. or a1, t1
  63. LONG_SLL t1, a1, 32
  64. #endif
  65. or a1, t1
  66. 1:
  67. FEXPORT(__bzero)
  68. sltiu t0, a2, LONGSIZE /* very small region? */
  69. bnez t0, .Lsmall_memset
  70. andi t0, a0, LONGMASK /* aligned? */
  71. #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
  72. beqz t0, 1f
  73. PTR_SUBU t0, LONGSIZE /* alignment in bytes */
  74. #else
  75. .set noat
  76. li AT, LONGSIZE
  77. beqz t0, 1f
  78. PTR_SUBU t0, AT /* alignment in bytes */
  79. .set at
  80. #endif
  81. R10KCBARRIER(0(ra))
  82. #ifdef __MIPSEB__
  83. EX(LONG_S_L, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */
  84. #endif
  85. #ifdef __MIPSEL__
  86. EX(LONG_S_R, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */
  87. #endif
  88. PTR_SUBU a0, t0 /* long align ptr */
  89. PTR_ADDU a2, t0 /* correct size */
  90. 1: ori t1, a2, 0x3f /* # of full blocks */
  91. xori t1, 0x3f
  92. beqz t1, .Lmemset_partial /* no block to fill */
  93. andi t0, a2, 0x40-LONGSIZE
  94. PTR_ADDU t1, a0 /* end address */
  95. .set reorder
  96. 1: PTR_ADDIU a0, 64
  97. R10KCBARRIER(0(ra))
  98. f_fill64 a0, -64, a1, .Lfwd_fixup
  99. bne t1, a0, 1b
  100. .set noreorder
  101. .Lmemset_partial:
  102. R10KCBARRIER(0(ra))
  103. PTR_LA t1, 2f /* where to start */
  104. #if LONGSIZE == 4
  105. PTR_SUBU t1, t0
  106. #else
  107. .set noat
  108. LONG_SRL AT, t0, 1
  109. PTR_SUBU t1, AT
  110. .set at
  111. #endif
  112. jr t1
  113. PTR_ADDU a0, t0 /* dest ptr */
  114. .set push
  115. .set noreorder
  116. .set nomacro
  117. f_fill64 a0, -64, a1, .Lpartial_fixup /* ... but first do longs ... */
  118. 2: .set pop
  119. andi a2, LONGMASK /* At most one long to go */
  120. beqz a2, 1f
  121. PTR_ADDU a0, a2 /* What's left */
  122. R10KCBARRIER(0(ra))
  123. #ifdef __MIPSEB__
  124. EX(LONG_S_R, a1, -1(a0), .Llast_fixup)
  125. #endif
  126. #ifdef __MIPSEL__
  127. EX(LONG_S_L, a1, -1(a0), .Llast_fixup)
  128. #endif
  129. 1: jr ra
  130. move a2, zero
  131. .Lsmall_memset:
  132. beqz a2, 2f
  133. PTR_ADDU t1, a0, a2
  134. 1: PTR_ADDIU a0, 1 /* fill bytewise */
  135. R10KCBARRIER(0(ra))
  136. bne t1, a0, 1b
  137. sb a1, -1(a0)
  138. 2: jr ra /* done */
  139. move a2, zero
  140. END(memset)
  141. .Lfirst_fixup:
  142. jr ra
  143. nop
  144. .Lfwd_fixup:
  145. PTR_L t0, TI_TASK($28)
  146. LONG_L t0, THREAD_BUADDR(t0)
  147. andi a2, 0x3f
  148. LONG_ADDU a2, t1
  149. jr ra
  150. LONG_SUBU a2, t0
  151. .Lpartial_fixup:
  152. PTR_L t0, TI_TASK($28)
  153. LONG_L t0, THREAD_BUADDR(t0)
  154. andi a2, LONGMASK
  155. LONG_ADDU a2, t1
  156. jr ra
  157. LONG_SUBU a2, t0
  158. .Llast_fixup:
  159. jr ra
  160. andi v1, a2, LONGMASK