memset.S
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  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. #include <asm/mipsregs.h>
  13. #include <asm/stackframe.h>
  14. #define EX(insn,reg,addr,handler)
  15. 9: insn reg, addr;
  16. .section __ex_table,"a"; 
  17. PTR 9b, handler; 
  18. .previous
  19. #define F_FILL64(dst, offset, val, fixup)
  20. EX(sd, val, (offset + 0x00)(dst), fixup);
  21. EX(sd, val, (offset + 0x08)(dst), fixup);
  22. EX(sd, val, (offset + 0x10)(dst), fixup);
  23. EX(sd, val, (offset + 0x18)(dst), fixup);
  24. EX(sd, val, (offset + 0x20)(dst), fixup);
  25. EX(sd, val, (offset + 0x28)(dst), fixup);
  26. EX(sd, val, (offset + 0x30)(dst), fixup);
  27. EX(sd, val, (offset + 0x38)(dst), fixup)
  28. /*
  29.  * memset(void *s, int c, size_t n)
  30.  *
  31.  * a0: start of area to clear
  32.  * a1: char to fill with
  33.  * a2: size of area to clear
  34.  */
  35. .set noreorder
  36. .align 5
  37. LEAF(memset)
  38. beqz a1, 1f
  39.  move v0, a0 /* result */
  40. andi a1, 0xff /* spread fillword */
  41. dsll t1, a1, 8
  42. or a1, t1
  43. dsll t1, a1, 16
  44. or a1, t1
  45. dsll t1, a1, 32
  46. or a1, t1
  47. 1:
  48. FEXPORT(__bzero)
  49. .type __bzero, @function
  50. sltiu t0, a2, 8 /* very small region? */
  51. bnez t0, small_memset
  52.  andi t0, a0, 7 /* aligned? */
  53. beqz t0, 1f
  54.  dsubu t0, 8 /* alignment in bytes */
  55. #ifdef __MIPSEB__
  56. EX(sdl, a1, (a0), first_fixup) /* make dword aligned */
  57. #endif
  58. #ifdef __MIPSEL__
  59. EX(sdr, a1, (a0), first_fixup) /* make dword aligned */
  60. #endif
  61. dsubu a0, t0 /* dword align ptr */
  62. daddu a2, t0 /* correct size */
  63. 1: ori t1, a2, 0x3f /* # of full blocks */
  64. xori t1, 0x3f
  65. beqz t1, memset_partial /* no block to fill */
  66.  andi t0, a2, 0x38
  67. daddu t1, a0 /* end address */
  68. .set reorder
  69. 1: daddiu a0, 64
  70. F_FILL64(a0, -64, a1, fwd_fixup)
  71. bne t1, a0, 1b
  72. .set noreorder
  73. memset_partial:
  74. la t1, 2f /* where to start */
  75. .set noat
  76. dsrl AT, t0, 1
  77. dsubu t1, AT
  78. .set noat
  79. jr t1
  80.  daddu a0, t0 /* dest ptr */
  81. F_FILL64(a0, -64, a1, partial_fixup) /* ... but first do dwds ... */
  82. 2: andi a2, 7 /* 0 <= n <= 7 to go */
  83. beqz a2, 1f
  84.  daddu a0, a2 /* What's left */
  85. #ifdef __MIPSEB__
  86. EX(sdr, a1, -1(a0), last_fixup)
  87. #endif
  88. #ifdef __MIPSEL__
  89. EX(sdl, a1, -1(a0), last_fixup)
  90. #endif
  91. 1: jr ra
  92.  move a2, zero
  93. small_memset:
  94. beqz a2, 2f
  95.  daddu t1, a0, a2
  96. 1: daddiu a0, 1 /* fill bytewise */
  97. bne t1, a0, 1b
  98.  sb a1, -1(a0)
  99. 2: jr ra /* done */
  100.  move a2, zero
  101. END(memset)
  102. first_fixup:
  103. jr ra
  104.  nop
  105. fwd_fixup:
  106. ld t0, THREAD_BUADDR($28)
  107. andi a2, 0x3f
  108. daddu a2, t1
  109. jr ra
  110.  dsubu a2, t0
  111. partial_fixup:
  112. ld t0, THREAD_BUADDR($28)
  113. andi a2, 7
  114. daddu a2, t1
  115. jr ra
  116.  dsubu a2, t0
  117. last_fixup:
  118. jr ra
  119.  andi v1, a2, 7