string.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _M68K_STRING_H_
  3. #define _M68K_STRING_H_
  4. #include <linux/types.h>
  5. #include <linux/compiler.h>
  6. #define __HAVE_ARCH_STRNLEN
  7. static inline size_t strnlen(const char *s, size_t count)
  8. {
  9. const char *sc = s;
  10. asm volatile ("\n"
  11. "1: subq.l #1,%1\n"
  12. " jcs 2f\n"
  13. " tst.b (%0)+\n"
  14. " jne 1b\n"
  15. " subq.l #1,%0\n"
  16. "2:"
  17. : "+a" (sc), "+d" (count));
  18. return sc - s;
  19. }
  20. #define __HAVE_ARCH_STRNCPY
  21. static inline char *strncpy(char *dest, const char *src, size_t n)
  22. {
  23. char *xdest = dest;
  24. asm volatile ("\n"
  25. " jra 2f\n"
  26. "1: move.b (%1),(%0)+\n"
  27. " jeq 2f\n"
  28. " addq.l #1,%1\n"
  29. "2: subq.l #1,%2\n"
  30. " jcc 1b\n"
  31. : "+a" (dest), "+a" (src), "+d" (n)
  32. : : "memory");
  33. return xdest;
  34. }
  35. #ifndef CONFIG_COLDFIRE
  36. #define __HAVE_ARCH_STRCMP
  37. static inline int strcmp(const char *cs, const char *ct)
  38. {
  39. char res;
  40. asm ("\n"
  41. "1: move.b (%0)+,%2\n" /* get *cs */
  42. " cmp.b (%1)+,%2\n" /* compare a byte */
  43. " jne 2f\n" /* not equal, break out */
  44. " tst.b %2\n" /* at end of cs? */
  45. " jne 1b\n" /* no, keep going */
  46. " jra 3f\n" /* strings are equal */
  47. "2: sub.b -(%1),%2\n" /* *cs - *ct */
  48. "3:"
  49. : "+a" (cs), "+a" (ct), "=d" (res));
  50. return res;
  51. }
  52. #endif /* CONFIG_COLDFIRE */
  53. #define __HAVE_ARCH_MEMMOVE
  54. extern void *memmove(void *, const void *, __kernel_size_t);
  55. #define memcmp(d, s, n) __builtin_memcmp(d, s, n)
  56. #define __HAVE_ARCH_MEMSET
  57. extern void *memset(void *, int, __kernel_size_t);
  58. #define memset(d, c, n) __builtin_memset(d, c, n)
  59. #define __HAVE_ARCH_MEMCPY
  60. extern void *memcpy(void *, const void *, __kernel_size_t);
  61. #define memcpy(d, s, n) __builtin_memcpy(d, s, n)
  62. #endif /* _M68K_STRING_H_ */