string.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Copyright (C) Paul Mackerras 1997.
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version
  7.  * 2 of the License, or (at your option) any later version.
  8.  *
  9.  * NOTE: this code runs in 32 bit mode and is packaged as ELF32.
  10.  */
  11. #include <asm/ppc_asm.tmpl>
  12. .text
  13. .globl strcpy
  14. strcpy:
  15. addi r5,r3,-1
  16. addi r4,r4,-1
  17. 1: lbzu r0,1(r4)
  18. cmpwi 0,r0,0
  19. stbu r0,1(r5)
  20. bne 1b
  21. blr
  22. .globl strncpy
  23. strncpy:
  24. cmpwi 0,r5,0
  25. beqlr
  26. mtctr r5
  27. addi r6,r3,-1
  28. addi r4,r4,-1
  29. 1: lbzu r0,1(r4)
  30. cmpwi 0,r0,0
  31. stbu r0,1(r6)
  32. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  33. blr
  34. .globl strcat
  35. strcat:
  36. addi r5,r3,-1
  37. addi r4,r4,-1
  38. 1: lbzu r0,1(r5)
  39. cmpwi 0,r0,0
  40. bne 1b
  41. addi r5,r5,-1
  42. 1: lbzu r0,1(r4)
  43. cmpwi 0,r0,0
  44. stbu r0,1(r5)
  45. bne 1b
  46. blr
  47. .globl strcmp
  48. strcmp:
  49. addi r5,r3,-1
  50. addi r4,r4,-1
  51. 1: lbzu r3,1(r5)
  52. cmpwi 1,r3,0
  53. lbzu r0,1(r4)
  54. subf. r3,r0,r3
  55. beqlr 1
  56. beq 1b
  57. blr
  58. .globl strlen
  59. strlen:
  60. addi r4,r3,-1
  61. 1: lbzu r0,1(r4)
  62. cmpwi 0,r0,0
  63. bne 1b
  64. subf r3,r3,r4
  65. blr
  66. .globl memset
  67. memset:
  68. rlwimi r4,r4,8,16,23
  69. rlwimi r4,r4,16,0,15
  70. addi r6,r3,-4
  71. cmplwi 0,r5,4
  72. blt 7f
  73. stwu r4,4(r6)
  74. beqlr
  75. andi. r0,r6,3
  76. add r5,r0,r5
  77. subf r6,r0,r6
  78. rlwinm r0,r5,32-2,2,31
  79. mtctr r0
  80. bdz 6f
  81. 1: stwu r4,4(r6)
  82. bdnz 1b
  83. 6: andi. r5,r5,3
  84. 7: cmpwi 0,r5,0
  85. beqlr
  86. mtctr r5
  87. addi r6,r6,3
  88. 8: stbu r4,1(r6)
  89. bdnz 8b
  90. blr
  91. .globl bcopy
  92. bcopy:
  93. mr r6,r3
  94. mr r3,r4
  95. mr r4,r6
  96. b memcpy
  97. .globl memmove
  98. memmove:
  99. cmplw 0,r3,r4
  100. bgt backwards_memcpy
  101. /* fall through */
  102. .globl memcpy
  103. memcpy:
  104. rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
  105. addi r6,r3,-4
  106. addi r4,r4,-4
  107. beq 2f /* if less than 8 bytes to do */
  108. andi. r0,r6,3 /* get dest word aligned */
  109. mtctr r7
  110. bne 5f
  111. 1: lwz r7,4(r4)
  112. lwzu r8,8(r4)
  113. stw r7,4(r6)
  114. stwu r8,8(r6)
  115. bdnz 1b
  116. andi. r5,r5,7
  117. 2: cmplwi 0,r5,4
  118. blt 3f
  119. lwzu r0,4(r4)
  120. addi r5,r5,-4
  121. stwu r0,4(r6)
  122. 3: cmpwi 0,r5,0
  123. beqlr
  124. mtctr r5
  125. addi r4,r4,3
  126. addi r6,r6,3
  127. 4: lbzu r0,1(r4)
  128. stbu r0,1(r6)
  129. bdnz 4b
  130. blr
  131. 5: subfic r0,r0,4
  132. mtctr r0
  133. 6: lbz r7,4(r4)
  134. addi r4,r4,1
  135. stb r7,4(r6)
  136. addi r6,r6,1
  137. bdnz 6b
  138. subf r5,r0,r5
  139. rlwinm. r7,r5,32-3,3,31
  140. beq 2b
  141. mtctr r7
  142. b 1b
  143. .globl backwards_memcpy
  144. backwards_memcpy:
  145. rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
  146. add r6,r3,r5
  147. add r4,r4,r5
  148. beq 2f
  149. andi. r0,r6,3
  150. mtctr r7
  151. bne 5f
  152. 1: lwz r7,-4(r4)
  153. lwzu r8,-8(r4)
  154. stw r7,-4(r6)
  155. stwu r8,-8(r6)
  156. bdnz 1b
  157. andi. r5,r5,7
  158. 2: cmplwi 0,r5,4
  159. blt 3f
  160. lwzu r0,-4(r4)
  161. subi r5,r5,4
  162. stwu r0,-4(r6)
  163. 3: cmpwi 0,r5,0
  164. beqlr
  165. mtctr r5
  166. 4: lbzu r0,-1(r4)
  167. stbu r0,-1(r6)
  168. bdnz 4b
  169. blr
  170. 5: mtctr r0
  171. 6: lbzu r7,-1(r4)
  172. stbu r7,-1(r6)
  173. bdnz 6b
  174. subf r5,r0,r5
  175. rlwinm. r7,r5,32-3,3,31
  176. beq 2b
  177. mtctr r7
  178. b 1b
  179. .globl memcmp
  180. memcmp:
  181. cmpwi 0,r5,0
  182. blelr
  183. mtctr r5
  184. addi r6,r3,-1
  185. addi r4,r4,-1
  186. 1: lbzu r3,1(r6)
  187. lbzu r0,1(r4)
  188. subf. r3,r0,r3
  189. bdnzt 2,1b
  190. blr
  191. /*
  192.  * Flush the dcache and invalidate the icache for a range of addresses.
  193.  *
  194.  * flush_cache(addr, len)
  195.  */
  196. .global flush_cache
  197. flush_cache:
  198. addi 4,4,0x1f /* len = (len + 0x1f) / 0x20 */
  199. rlwinm. 4,4,27,5,31
  200. mtctr 4
  201. beqlr
  202. 1: dcbf 0,3
  203. icbi 0,3
  204. addi 3,3,0x20
  205. bdnz 1b
  206. sync
  207. isync
  208. blr