string.h 1.6 KB

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