memset.S 3.4 KB

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