memset.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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, small_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. #ifdef __MIPSEB__
  82. EX(LONG_S_L, a1, (a0), first_fixup) /* make word/dword aligned */
  83. #endif
  84. #ifdef __MIPSEL__
  85. EX(LONG_S_R, a1, (a0), first_fixup) /* make word/dword aligned */
  86. #endif
  87. PTR_SUBU a0, t0 /* long align ptr */
  88. PTR_ADDU a2, t0 /* correct size */
  89. 1: ori t1, a2, 0x3f /* # of full blocks */
  90. xori t1, 0x3f
  91. beqz t1, memset_partial /* no block to fill */
  92. andi t0, a2, 0x40-LONGSIZE
  93. PTR_ADDU t1, a0 /* end address */
  94. .set reorder
  95. 1: PTR_ADDIU a0, 64
  96. f_fill64 a0, -64, a1, fwd_fixup
  97. bne t1, a0, 1b
  98. .set noreorder
  99. memset_partial:
  100. PTR_LA t1, 2f /* where to start */
  101. #if LONGSIZE == 4
  102. PTR_SUBU t1, t0
  103. #else
  104. .set noat
  105. LONG_SRL AT, t0, 1
  106. PTR_SUBU t1, AT
  107. .set at
  108. #endif
  109. jr t1
  110. PTR_ADDU a0, t0 /* dest ptr */
  111. .set push
  112. .set noreorder
  113. .set nomacro
  114. f_fill64 a0, -64, a1, partial_fixup /* ... but first do longs ... */
  115. 2: .set pop
  116. andi a2, LONGMASK /* At most one long to go */
  117. beqz a2, 1f
  118. PTR_ADDU a0, a2 /* What's left */
  119. #ifdef __MIPSEB__
  120. EX(LONG_S_R, a1, -1(a0), last_fixup)
  121. #endif
  122. #ifdef __MIPSEL__
  123. EX(LONG_S_L, a1, -1(a0), last_fixup)
  124. #endif
  125. 1: jr ra
  126. move a2, zero
  127. small_memset:
  128. beqz a2, 2f
  129. PTR_ADDU t1, a0, a2
  130. 1: PTR_ADDIU a0, 1 /* fill bytewise */
  131. bne t1, a0, 1b
  132. sb a1, -1(a0)
  133. 2: jr ra /* done */
  134. move a2, zero
  135. END(memset)
  136. first_fixup:
  137. jr ra
  138. nop
  139. fwd_fixup:
  140. PTR_L t0, TI_TASK($28)
  141. LONG_L t0, THREAD_BUADDR(t0)
  142. andi a2, 0x3f
  143. LONG_ADDU a2, t1
  144. jr ra
  145. LONG_SUBU a2, t0
  146. partial_fixup:
  147. PTR_L t0, TI_TASK($28)
  148. LONG_L t0, THREAD_BUADDR(t0)
  149. andi a2, LONGMASK
  150. LONG_ADDU a2, t1
  151. jr ra
  152. LONG_SUBU a2, t0
  153. last_fixup:
  154. jr ra
  155. andi v1, a2, LONGMASK