string.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * String handling functions for PowerPC.
  3. *
  4. * Copyright (C) 1996 Paul Mackerras.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/processor.h>
  12. #include <asm/errno.h>
  13. #include <asm/ppc_asm.h>
  14. .section __ex_table,"a"
  15. PPC_LONG_ALIGN
  16. .text
  17. _GLOBAL(strcpy)
  18. addi r5,r3,-1
  19. addi r4,r4,-1
  20. 1: lbzu r0,1(r4)
  21. cmpwi 0,r0,0
  22. stbu r0,1(r5)
  23. bne 1b
  24. blr
  25. /* This clears out any unused part of the destination buffer,
  26. just as the libc version does. -- paulus */
  27. _GLOBAL(strncpy)
  28. PPC_LCMPI 0,r5,0
  29. beqlr
  30. mtctr r5
  31. addi r6,r3,-1
  32. addi r4,r4,-1
  33. 1: lbzu r0,1(r4)
  34. cmpwi 0,r0,0
  35. stbu r0,1(r6)
  36. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  37. bnelr /* if we didn't hit a null char, we're done */
  38. mfctr r5
  39. PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
  40. beqlr /* we know r0 == 0 here */
  41. 2: stbu r0,1(r6) /* clear it out if so */
  42. bdnz 2b
  43. blr
  44. _GLOBAL(strcat)
  45. addi r5,r3,-1
  46. addi r4,r4,-1
  47. 1: lbzu r0,1(r5)
  48. cmpwi 0,r0,0
  49. bne 1b
  50. addi r5,r5,-1
  51. 1: lbzu r0,1(r4)
  52. cmpwi 0,r0,0
  53. stbu r0,1(r5)
  54. bne 1b
  55. blr
  56. _GLOBAL(strcmp)
  57. addi r5,r3,-1
  58. addi r4,r4,-1
  59. 1: lbzu r3,1(r5)
  60. cmpwi 1,r3,0
  61. lbzu r0,1(r4)
  62. subf. r3,r0,r3
  63. beqlr 1
  64. beq 1b
  65. blr
  66. _GLOBAL(strncmp)
  67. PPC_LCMPI 0,r5,0
  68. beq- 2f
  69. mtctr r5
  70. addi r5,r3,-1
  71. addi r4,r4,-1
  72. 1: lbzu r3,1(r5)
  73. cmpwi 1,r3,0
  74. lbzu r0,1(r4)
  75. subf. r3,r0,r3
  76. beqlr 1
  77. bdnzt eq,1b
  78. blr
  79. 2: li r3,0
  80. blr
  81. _GLOBAL(strlen)
  82. addi r4,r3,-1
  83. 1: lbzu r0,1(r4)
  84. cmpwi 0,r0,0
  85. bne 1b
  86. subf r3,r3,r4
  87. blr
  88. #ifdef CONFIG_PPC32
  89. _GLOBAL(memcmp)
  90. PPC_LCMPI 0,r5,0
  91. beq- 2f
  92. mtctr r5
  93. addi r6,r3,-1
  94. addi r4,r4,-1
  95. 1: lbzu r3,1(r6)
  96. lbzu r0,1(r4)
  97. subf. r3,r0,r3
  98. bdnzt 2,1b
  99. blr
  100. 2: li r3,0
  101. blr
  102. #endif
  103. _GLOBAL(memchr)
  104. PPC_LCMPI 0,r5,0
  105. beq- 2f
  106. mtctr r5
  107. addi r3,r3,-1
  108. 1: lbzu r0,1(r3)
  109. cmpw 0,r0,r4
  110. bdnzf 2,1b
  111. beqlr
  112. 2: li r3,0
  113. blr
  114. #ifdef CONFIG_PPC32
  115. _GLOBAL(__clear_user)
  116. addi r6,r3,-4
  117. li r3,0
  118. li r5,0
  119. cmplwi 0,r4,4
  120. blt 7f
  121. /* clear a single word */
  122. 11: stwu r5,4(r6)
  123. beqlr
  124. /* clear word sized chunks */
  125. andi. r0,r6,3
  126. add r4,r0,r4
  127. subf r6,r0,r6
  128. srwi r0,r4,2
  129. andi. r4,r4,3
  130. mtctr r0
  131. bdz 7f
  132. 1: stwu r5,4(r6)
  133. bdnz 1b
  134. /* clear byte sized chunks */
  135. 7: cmpwi 0,r4,0
  136. beqlr
  137. mtctr r4
  138. addi r6,r6,3
  139. 8: stbu r5,1(r6)
  140. bdnz 8b
  141. blr
  142. 90: mr r3,r4
  143. blr
  144. 91: mfctr r3
  145. slwi r3,r3,2
  146. add r3,r3,r4
  147. blr
  148. 92: mfctr r3
  149. blr
  150. .section __ex_table,"a"
  151. PPC_LONG 11b,90b
  152. PPC_LONG 1b,91b
  153. PPC_LONG 8b,92b
  154. .text
  155. #endif