string.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. .text
  16. /* This clears out any unused part of the destination buffer,
  17. just as the libc version does. -- paulus */
  18. _GLOBAL(strncpy)
  19. PPC_LCMPI 0,r5,0
  20. beqlr
  21. mtctr r5
  22. addi r6,r3,-1
  23. addi r4,r4,-1
  24. .balign 16
  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. EXPORT_SYMBOL(strncpy)
  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. EXPORT_SYMBOL(strncmp)
  54. #ifdef CONFIG_PPC32
  55. _GLOBAL(memcmp)
  56. PPC_LCMPI 0,r5,0
  57. beq- 2f
  58. mtctr r5
  59. addi r6,r3,-1
  60. addi r4,r4,-1
  61. 1: lbzu r3,1(r6)
  62. lbzu r0,1(r4)
  63. subf. r3,r0,r3
  64. bdnzt 2,1b
  65. blr
  66. 2: li r3,0
  67. blr
  68. EXPORT_SYMBOL(memcmp)
  69. #endif
  70. _GLOBAL(memchr)
  71. PPC_LCMPI 0,r5,0
  72. beq- 2f
  73. mtctr r5
  74. addi r3,r3,-1
  75. .balign 16
  76. 1: lbzu r0,1(r3)
  77. cmpw 0,r0,r4
  78. bdnzf 2,1b
  79. beqlr
  80. 2: li r3,0
  81. blr
  82. EXPORT_SYMBOL(memchr)
  83. #ifdef CONFIG_PPC32
  84. _GLOBAL(__clear_user)
  85. addi r6,r3,-4
  86. li r3,0
  87. li r5,0
  88. cmplwi 0,r4,4
  89. blt 7f
  90. /* clear a single word */
  91. 11: stwu r5,4(r6)
  92. beqlr
  93. /* clear word sized chunks */
  94. andi. r0,r6,3
  95. add r4,r0,r4
  96. subf r6,r0,r6
  97. srwi r0,r4,2
  98. andi. r4,r4,3
  99. mtctr r0
  100. bdz 7f
  101. 1: stwu r5,4(r6)
  102. bdnz 1b
  103. /* clear byte sized chunks */
  104. 7: cmpwi 0,r4,0
  105. beqlr
  106. mtctr r4
  107. addi r6,r6,3
  108. 8: stbu r5,1(r6)
  109. bdnz 8b
  110. blr
  111. 90: mr r3,r4
  112. blr
  113. 91: mfctr r3
  114. slwi r3,r3,2
  115. add r3,r3,r4
  116. blr
  117. 92: mfctr r3
  118. blr
  119. EX_TABLE(11b, 90b)
  120. EX_TABLE(1b, 91b)
  121. EX_TABLE(8b, 92b)
  122. EXPORT_SYMBOL(__clear_user)
  123. #endif