string.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 <linux/config.h>
  12. #include <asm/processor.h>
  13. #include <asm/errno.h>
  14. #include <asm/ppc_asm.h>
  15. .text
  16. .stabs "arch/powerpc/lib/",N_SO,0,0,0f
  17. .stabs "string.S",N_SO,0,0,0f
  18. 0:
  19. .section __ex_table,"a"
  20. #ifdef CONFIG_PPC64
  21. .align 3
  22. #define EXTBL .llong
  23. #else
  24. .align 2
  25. #define EXTBL .long
  26. #endif
  27. .text
  28. _GLOBAL(strcpy)
  29. addi r5,r3,-1
  30. addi r4,r4,-1
  31. 1: lbzu r0,1(r4)
  32. cmpwi 0,r0,0
  33. stbu r0,1(r5)
  34. bne 1b
  35. blr
  36. /* This clears out any unused part of the destination buffer,
  37. just as the libc version does. -- paulus */
  38. _GLOBAL(strncpy)
  39. cmpwi 0,r5,0
  40. beqlr
  41. mtctr r5
  42. addi r6,r3,-1
  43. addi r4,r4,-1
  44. 1: lbzu r0,1(r4)
  45. cmpwi 0,r0,0
  46. stbu r0,1(r6)
  47. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  48. bnelr /* if we didn't hit a null char, we're done */
  49. mfctr r5
  50. cmpwi 0,r5,0 /* any space left in destination buffer? */
  51. beqlr /* we know r0 == 0 here */
  52. 2: stbu r0,1(r6) /* clear it out if so */
  53. bdnz 2b
  54. blr
  55. _GLOBAL(strcat)
  56. addi r5,r3,-1
  57. addi r4,r4,-1
  58. 1: lbzu r0,1(r5)
  59. cmpwi 0,r0,0
  60. bne 1b
  61. addi r5,r5,-1
  62. 1: lbzu r0,1(r4)
  63. cmpwi 0,r0,0
  64. stbu r0,1(r5)
  65. bne 1b
  66. blr
  67. _GLOBAL(strcmp)
  68. addi r5,r3,-1
  69. addi r4,r4,-1
  70. 1: lbzu r3,1(r5)
  71. cmpwi 1,r3,0
  72. lbzu r0,1(r4)
  73. subf. r3,r0,r3
  74. beqlr 1
  75. beq 1b
  76. blr
  77. _GLOBAL(strlen)
  78. addi r4,r3,-1
  79. 1: lbzu r0,1(r4)
  80. cmpwi 0,r0,0
  81. bne 1b
  82. subf r3,r3,r4
  83. blr
  84. _GLOBAL(memcmp)
  85. cmpwi 0,r5,0
  86. ble- 2f
  87. mtctr r5
  88. addi r6,r3,-1
  89. addi r4,r4,-1
  90. 1: lbzu r3,1(r6)
  91. lbzu r0,1(r4)
  92. subf. r3,r0,r3
  93. bdnzt 2,1b
  94. blr
  95. 2: li r3,0
  96. blr
  97. _GLOBAL(memchr)
  98. cmpwi 0,r5,0
  99. ble- 2f
  100. mtctr r5
  101. addi r3,r3,-1
  102. 1: lbzu r0,1(r3)
  103. cmpw 0,r0,r4
  104. bdnzf 2,1b
  105. beqlr
  106. 2: li r3,0
  107. blr
  108. _GLOBAL(__clear_user)
  109. addi r6,r3,-4
  110. li r3,0
  111. li r5,0
  112. cmplwi 0,r4,4
  113. blt 7f
  114. /* clear a single word */
  115. 11: stwu r5,4(r6)
  116. beqlr
  117. /* clear word sized chunks */
  118. andi. r0,r6,3
  119. add r4,r0,r4
  120. subf r6,r0,r6
  121. srwi r0,r4,2
  122. andi. r4,r4,3
  123. mtctr r0
  124. bdz 7f
  125. 1: stwu r5,4(r6)
  126. bdnz 1b
  127. /* clear byte sized chunks */
  128. 7: cmpwi 0,r4,0
  129. beqlr
  130. mtctr r4
  131. addi r6,r6,3
  132. 8: stbu r5,1(r6)
  133. bdnz 8b
  134. blr
  135. 90: mr r3,r4
  136. blr
  137. 91: mfctr r3
  138. slwi r3,r3,2
  139. add r3,r3,r4
  140. blr
  141. 92: mfctr r3
  142. blr
  143. .section __ex_table,"a"
  144. EXTBL 11b,90b
  145. EXTBL 1b,91b
  146. EXTBL 8b,92b
  147. .text
  148. _GLOBAL(__strncpy_from_user)
  149. addi r6,r3,-1
  150. addi r4,r4,-1
  151. cmpwi 0,r5,0
  152. beq 2f
  153. mtctr r5
  154. 1: lbzu r0,1(r4)
  155. cmpwi 0,r0,0
  156. stbu r0,1(r6)
  157. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  158. beq 3f
  159. 2: addi r6,r6,1
  160. 3: subf r3,r3,r6
  161. blr
  162. 99: li r3,-EFAULT
  163. blr
  164. .section __ex_table,"a"
  165. EXTBL 1b,99b
  166. .text
  167. /* r3 = str, r4 = len (> 0), r5 = top (highest addr) */
  168. _GLOBAL(__strnlen_user)
  169. addi r7,r3,-1
  170. subf r6,r7,r5 /* top+1 - str */
  171. cmplw 0,r4,r6
  172. bge 0f
  173. mr r6,r4
  174. 0: mtctr r6 /* ctr = min(len, top - str) */
  175. 1: lbzu r0,1(r7) /* get next byte */
  176. cmpwi 0,r0,0
  177. bdnzf 2,1b /* loop if --ctr != 0 && byte != 0 */
  178. addi r7,r7,1
  179. subf r3,r3,r7 /* number of bytes we have looked at */
  180. beqlr /* return if we found a 0 byte */
  181. cmpw 0,r3,r4 /* did we look at all len bytes? */
  182. blt 99f /* if not, must have hit top */
  183. addi r3,r4,1 /* return len + 1 to indicate no null found */
  184. blr
  185. 99: li r3,0 /* bad address, return 0 */
  186. blr
  187. .section __ex_table,"a"
  188. EXTBL 1b,99b