string.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef _M68K_STRING_H_
  2. #define _M68K_STRING_H_
  3. #include <linux/types.h>
  4. #include <linux/compiler.h>
  5. static inline size_t __kernel_strlen(const char *s)
  6. {
  7. const char *sc;
  8. for (sc = s; *sc++; )
  9. ;
  10. return sc - s - 1;
  11. }
  12. static inline char *__kernel_strcpy(char *dest, const char *src)
  13. {
  14. char *xdest = dest;
  15. asm volatile ("\n"
  16. "1: move.b (%1)+,(%0)+\n"
  17. " jne 1b"
  18. : "+a" (dest), "+a" (src)
  19. : : "memory");
  20. return xdest;
  21. }
  22. #ifndef __IN_STRING_C
  23. #define __HAVE_ARCH_STRLEN
  24. #define strlen(s) (__builtin_constant_p(s) ? \
  25. __builtin_strlen(s) : \
  26. __kernel_strlen(s))
  27. #define __HAVE_ARCH_STRNLEN
  28. static inline size_t strnlen(const char *s, size_t count)
  29. {
  30. const char *sc = s;
  31. asm volatile ("\n"
  32. "1: subq.l #1,%1\n"
  33. " jcs 2f\n"
  34. " tst.b (%0)+\n"
  35. " jne 1b\n"
  36. " subq.l #1,%0\n"
  37. "2:"
  38. : "+a" (sc), "+d" (count));
  39. return sc - s;
  40. }
  41. #define __HAVE_ARCH_STRCPY
  42. #if __GNUC__ >= 4
  43. #define strcpy(d, s) (__builtin_constant_p(s) && \
  44. __builtin_strlen(s) <= 32 ? \
  45. __builtin_strcpy(d, s) : \
  46. __kernel_strcpy(d, s))
  47. #else
  48. #define strcpy(d, s) __kernel_strcpy(d, s)
  49. #endif
  50. #define __HAVE_ARCH_STRNCPY
  51. static inline char *strncpy(char *dest, const char *src, size_t n)
  52. {
  53. char *xdest = dest;
  54. asm volatile ("\n"
  55. " jra 2f\n"
  56. "1: move.b (%1),(%0)+\n"
  57. " jeq 2f\n"
  58. " addq.l #1,%1\n"
  59. "2: subq.l #1,%2\n"
  60. " jcc 1b\n"
  61. : "+a" (dest), "+a" (src), "+d" (n)
  62. : : "memory");
  63. return xdest;
  64. }
  65. #define __HAVE_ARCH_STRCAT
  66. #define strcat(d, s) ({ \
  67. char *__d = (d); \
  68. strcpy(__d + strlen(__d), (s)); \
  69. })
  70. #ifndef CONFIG_COLDFIRE
  71. #define __HAVE_ARCH_STRCMP
  72. static inline int strcmp(const char *cs, const char *ct)
  73. {
  74. char res;
  75. asm ("\n"
  76. "1: move.b (%0)+,%2\n" /* get *cs */
  77. " cmp.b (%1)+,%2\n" /* compare a byte */
  78. " jne 2f\n" /* not equal, break out */
  79. " tst.b %2\n" /* at end of cs? */
  80. " jne 1b\n" /* no, keep going */
  81. " jra 3f\n" /* strings are equal */
  82. "2: sub.b -(%1),%2\n" /* *cs - *ct */
  83. "3:"
  84. : "+a" (cs), "+a" (ct), "=d" (res));
  85. return res;
  86. }
  87. #endif /* CONFIG_COLDFIRE */
  88. #define __HAVE_ARCH_MEMMOVE
  89. extern void *memmove(void *, const void *, __kernel_size_t);
  90. #define memcmp(d, s, n) __builtin_memcmp(d, s, n)
  91. #define __HAVE_ARCH_MEMSET
  92. extern void *memset(void *, int, __kernel_size_t);
  93. #define memset(d, c, n) __builtin_memset(d, c, n)
  94. #define __HAVE_ARCH_MEMCPY
  95. extern void *memcpy(void *, const void *, __kernel_size_t);
  96. #define memcpy(d, s, n) __builtin_memcpy(d, s, n)
  97. #endif
  98. #endif /* _M68K_STRING_H_ */