string.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include <asm/cache.h>
  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 IFETCH_ALIGN_BYTES
  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. EXPORT_SYMBOL(strncpy)
  38. _GLOBAL(strncmp)
  39. PPC_LCMPI 0,r5,0
  40. beq- 2f
  41. mtctr r5
  42. addi r5,r3,-1
  43. addi r4,r4,-1
  44. .balign IFETCH_ALIGN_BYTES
  45. 1: lbzu r3,1(r5)
  46. cmpwi 1,r3,0
  47. lbzu r0,1(r4)
  48. subf. r3,r0,r3
  49. beqlr 1
  50. bdnzt eq,1b
  51. blr
  52. 2: li r3,0
  53. blr
  54. EXPORT_SYMBOL(strncmp)
  55. #ifdef CONFIG_PPC32
  56. _GLOBAL(memcmp)
  57. PPC_LCMPI 0,r5,0
  58. beq- 2f
  59. mtctr r5
  60. addi r6,r3,-1
  61. addi r4,r4,-1
  62. 1: lbzu r3,1(r6)
  63. lbzu r0,1(r4)
  64. subf. r3,r0,r3
  65. bdnzt 2,1b
  66. blr
  67. 2: li r3,0
  68. blr
  69. EXPORT_SYMBOL(memcmp)
  70. #endif
  71. _GLOBAL(memchr)
  72. PPC_LCMPI 0,r5,0
  73. beq- 2f
  74. mtctr r5
  75. addi r3,r3,-1
  76. .balign IFETCH_ALIGN_BYTES
  77. 1: lbzu r0,1(r3)
  78. cmpw 0,r0,r4
  79. bdnzf 2,1b
  80. beqlr
  81. 2: li r3,0
  82. blr
  83. EXPORT_SYMBOL(memchr)
  84. #ifdef CONFIG_PPC32
  85. _GLOBAL(__arch_clear_user)
  86. addi r6,r3,-4
  87. li r3,0
  88. li r5,0
  89. cmplwi 0,r4,4
  90. blt 7f
  91. /* clear a single word */
  92. 11: stwu r5,4(r6)
  93. beqlr
  94. /* clear word sized chunks */
  95. andi. r0,r6,3
  96. add r4,r0,r4
  97. subf r6,r0,r6
  98. srwi r0,r4,2
  99. andi. r4,r4,3
  100. mtctr r0
  101. bdz 7f
  102. 1: stwu r5,4(r6)
  103. bdnz 1b
  104. /* clear byte sized chunks */
  105. 7: cmpwi 0,r4,0
  106. beqlr
  107. mtctr r4
  108. addi r6,r6,3
  109. 8: stbu r5,1(r6)
  110. bdnz 8b
  111. blr
  112. 90: mr r3,r4
  113. blr
  114. 91: mfctr r3
  115. slwi r3,r3,2
  116. add r3,r3,r4
  117. blr
  118. 92: mfctr r3
  119. blr
  120. EX_TABLE(11b, 90b)
  121. EX_TABLE(1b, 91b)
  122. EX_TABLE(8b, 92b)
  123. EXPORT_SYMBOL(__arch_clear_user)
  124. #endif