string.S 2.2 KB

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