string.S 2.1 KB

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