string.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #ifndef _BLACKFIN_STRING_H_
  2. #define _BLACKFIN_STRING_H_
  3. #include <linux/types.h>
  4. #ifdef __KERNEL__ /* only set these up for kernel code */
  5. #define __HAVE_ARCH_STRCPY
  6. extern inline char *strcpy(char *dest, const char *src)
  7. {
  8. char *xdest = dest;
  9. char temp = 0;
  10. __asm__ __volatile__ (
  11. "1:"
  12. "%2 = B [%1++] (Z);"
  13. "B [%0++] = %2;"
  14. "CC = %2;"
  15. "if cc jump 1b (bp);"
  16. : "+&a" (dest), "+&a" (src), "=&d" (temp)
  17. :
  18. : "memory", "CC");
  19. return xdest;
  20. }
  21. #define __HAVE_ARCH_STRNCPY
  22. extern inline char *strncpy(char *dest, const char *src, size_t n)
  23. {
  24. char *xdest = dest;
  25. char temp = 0;
  26. if (n == 0)
  27. return xdest;
  28. __asm__ __volatile__ (
  29. "1:"
  30. "%3 = B [%1++] (Z);"
  31. "B [%0++] = %3;"
  32. "CC = %3;"
  33. "if ! cc jump 2f;"
  34. "%2 += -1;"
  35. "CC = %2 == 0;"
  36. "if ! cc jump 1b (bp);"
  37. "jump 4f;"
  38. "2:"
  39. /* if src is shorter than n, we need to null pad bytes now */
  40. "%3 = 0;"
  41. "3:"
  42. "%2 += -1;"
  43. "CC = %2 == 0;"
  44. "if cc jump 4f;"
  45. "B [%0++] = %3;"
  46. "jump 3b;"
  47. "4:"
  48. : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp)
  49. :
  50. : "memory", "CC");
  51. return xdest;
  52. }
  53. #define __HAVE_ARCH_STRCMP
  54. extern inline int strcmp(const char *cs, const char *ct)
  55. {
  56. /* need to use int's here so the char's in the assembly don't get
  57. * sign extended incorrectly when we don't want them to be
  58. */
  59. int __res1, __res2;
  60. __asm__ __volatile__ (
  61. "1:"
  62. "%2 = B[%0++] (Z);" /* get *cs */
  63. "%3 = B[%1++] (Z);" /* get *ct */
  64. "CC = %2 == %3;" /* compare a byte */
  65. "if ! cc jump 2f;" /* not equal, break out */
  66. "CC = %2;" /* at end of cs? */
  67. "if cc jump 1b (bp);" /* no, keep going */
  68. "jump.s 3f;" /* strings are equal */
  69. "2:"
  70. "%2 = %2 - %3;" /* *cs - *ct */
  71. "3:"
  72. : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2)
  73. :
  74. : "memory", "CC");
  75. return __res1;
  76. }
  77. #define __HAVE_ARCH_STRNCMP
  78. extern inline int strncmp(const char *cs, const char *ct, size_t count)
  79. {
  80. /* need to use int's here so the char's in the assembly don't get
  81. * sign extended incorrectly when we don't want them to be
  82. */
  83. int __res1, __res2;
  84. if (!count)
  85. return 0;
  86. __asm__ __volatile__ (
  87. "1:"
  88. "%3 = B[%0++] (Z);" /* get *cs */
  89. "%4 = B[%1++] (Z);" /* get *ct */
  90. "CC = %3 == %4;" /* compare a byte */
  91. "if ! cc jump 3f;" /* not equal, break out */
  92. "CC = %3;" /* at end of cs? */
  93. "if ! cc jump 4f;" /* yes, all done */
  94. "%2 += -1;" /* no, adjust count */
  95. "CC = %2 == 0;"
  96. "if ! cc jump 1b;" /* more to do, keep going */
  97. "2:"
  98. "%3 = 0;" /* strings are equal */
  99. "jump.s 4f;"
  100. "3:"
  101. "%3 = %3 - %4;" /* *cs - *ct */
  102. "4:"
  103. : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2)
  104. :
  105. : "memory", "CC");
  106. return __res1;
  107. }
  108. #define __HAVE_ARCH_MEMSET
  109. extern void *memset(void *s, int c, size_t count);
  110. #define __HAVE_ARCH_MEMCPY
  111. extern void *memcpy(void *d, const void *s, size_t count);
  112. #define __HAVE_ARCH_MEMCMP
  113. extern int memcmp(const void *, const void *, __kernel_size_t);
  114. #define __HAVE_ARCH_MEMCHR
  115. extern void *memchr(const void *s, int c, size_t n);
  116. #define __HAVE_ARCH_MEMMOVE
  117. extern void *memmove(void *dest, const void *src, size_t count);
  118. #endif /*__KERNEL__*/
  119. #endif /* _BLACKFIN_STRING_H_ */