string.h 2.2 KB

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