memset.S 3.8 KB

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