string.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /* This clears out any unused part of the destination buffer,
  18. just as the libc version does. -- paulus */
  19. _GLOBAL(strncpy)
  20. PPC_LCMPI 0,r5,0
  21. beqlr
  22. mtctr r5
  23. addi r6,r3,-1
  24. addi r4,r4,-1
  25. 1: lbzu r0,1(r4)
  26. cmpwi 0,r0,0
  27. stbu r0,1(r6)
  28. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  29. bnelr /* if we didn't hit a null char, we're done */
  30. mfctr r5
  31. PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
  32. beqlr /* we know r0 == 0 here */
  33. 2: stbu r0,1(r6) /* clear it out if so */
  34. bdnz 2b
  35. blr
  36. _GLOBAL(strncmp)
  37. PPC_LCMPI 0,r5,0
  38. beq- 2f
  39. mtctr r5
  40. addi r5,r3,-1
  41. addi r4,r4,-1
  42. 1: lbzu r3,1(r5)
  43. cmpwi 1,r3,0
  44. lbzu r0,1(r4)
  45. subf. r3,r0,r3
  46. beqlr 1
  47. bdnzt eq,1b
  48. blr
  49. 2: li r3,0
  50. blr
  51. #ifdef CONFIG_PPC32
  52. _GLOBAL(memcmp)
  53. PPC_LCMPI 0,r5,0
  54. beq- 2f
  55. mtctr r5
  56. addi r6,r3,-1
  57. addi r4,r4,-1
  58. 1: lbzu r3,1(r6)
  59. lbzu r0,1(r4)
  60. subf. r3,r0,r3
  61. bdnzt 2,1b
  62. blr
  63. 2: li r3,0
  64. blr
  65. #endif
  66. _GLOBAL(memchr)
  67. PPC_LCMPI 0,r5,0
  68. beq- 2f
  69. mtctr r5
  70. addi r3,r3,-1
  71. 1: lbzu r0,1(r3)
  72. cmpw 0,r0,r4
  73. bdnzf 2,1b
  74. beqlr
  75. 2: li r3,0
  76. blr
  77. #ifdef CONFIG_PPC32
  78. _GLOBAL(__clear_user)
  79. addi r6,r3,-4
  80. li r3,0
  81. li r5,0
  82. cmplwi 0,r4,4
  83. blt 7f
  84. /* clear a single word */
  85. 11: stwu r5,4(r6)
  86. beqlr
  87. /* clear word sized chunks */
  88. andi. r0,r6,3
  89. add r4,r0,r4
  90. subf r6,r0,r6
  91. srwi r0,r4,2
  92. andi. r4,r4,3
  93. mtctr r0
  94. bdz 7f
  95. 1: stwu r5,4(r6)
  96. bdnz 1b
  97. /* clear byte sized chunks */
  98. 7: cmpwi 0,r4,0
  99. beqlr
  100. mtctr r4
  101. addi r6,r6,3
  102. 8: stbu r5,1(r6)
  103. bdnz 8b
  104. blr
  105. 90: mr r3,r4
  106. blr
  107. 91: mfctr r3
  108. slwi r3,r3,2
  109. add r3,r3,r4
  110. blr
  111. 92: mfctr r3
  112. blr
  113. .section __ex_table,"a"
  114. PPC_LONG 11b,90b
  115. PPC_LONG 1b,91b
  116. PPC_LONG 8b,92b
  117. .text
  118. #endif