string_no.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef _M68KNOMMU_STRING_H_
  2. #define _M68KNOMMU_STRING_H_
  3. #ifdef __KERNEL__ /* only set these up for kernel code */
  4. #include <asm/setup.h>
  5. #include <asm/page.h>
  6. #define __HAVE_ARCH_STRCPY
  7. static inline char * strcpy(char * dest,const char *src)
  8. {
  9. char *xdest = dest;
  10. __asm__ __volatile__
  11. ("1:\tmoveb %1@+,%0@+\n\t"
  12. "jne 1b"
  13. : "=a" (dest), "=a" (src)
  14. : "0" (dest), "1" (src) : "memory");
  15. return xdest;
  16. }
  17. #define __HAVE_ARCH_STRNCPY
  18. static inline char * strncpy(char *dest, const char *src, size_t n)
  19. {
  20. char *xdest = dest;
  21. if (n == 0)
  22. return xdest;
  23. __asm__ __volatile__
  24. ("1:\tmoveb %1@+,%0@+\n\t"
  25. "jeq 2f\n\t"
  26. "subql #1,%2\n\t"
  27. "jne 1b\n\t"
  28. "2:"
  29. : "=a" (dest), "=a" (src), "=d" (n)
  30. : "0" (dest), "1" (src), "2" (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__
  40. ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
  41. "cmpb %1@+,%2\n\t" /* compare a byte */
  42. "jne 2f\n\t" /* not equal, break out */
  43. "tstb %2\n\t" /* at end of cs? */
  44. "jne 1b\n\t" /* no, keep going */
  45. "jra 3f\n\t" /* strings are equal */
  46. "2:\tsubb %1@-,%2\n\t" /* *cs - *ct */
  47. "3:"
  48. : "=a" (cs), "=a" (ct), "=d" (__res)
  49. : "0" (cs), "1" (ct));
  50. return __res;
  51. }
  52. #define __HAVE_ARCH_STRNCMP
  53. static inline int strncmp(const char * cs,const char * ct,size_t count)
  54. {
  55. char __res;
  56. if (!count)
  57. return 0;
  58. __asm__
  59. ("1:\tmovb %0@+,%3\n\t" /* get *cs */
  60. "cmpb %1@+,%3\n\t" /* compare a byte */
  61. "jne 3f\n\t" /* not equal, break out */
  62. "tstb %3\n\t" /* at end of cs? */
  63. "jeq 4f\n\t" /* yes, all done */
  64. "subql #1,%2\n\t" /* no, adjust count */
  65. "jne 1b\n\t" /* more to do, keep going */
  66. "2:\tmoveq #0,%3\n\t" /* strings are equal */
  67. "jra 4f\n\t"
  68. "3:\tsubb %1@-,%3\n\t" /* *cs - *ct */
  69. "4:"
  70. : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
  71. : "0" (cs), "1" (ct), "2" (count));
  72. return __res;
  73. }
  74. #endif /* CONFIG_COLDFIRE */
  75. #define __HAVE_ARCH_MEMSET
  76. extern void * memset(void * s, int c, size_t count);
  77. #define __HAVE_ARCH_MEMCPY
  78. extern void * memcpy(void *d, const void *s, size_t count);
  79. #else /* KERNEL */
  80. /*
  81. * let user libraries deal with these,
  82. * IMHO the kernel has no place defining these functions for user apps
  83. */
  84. #define __HAVE_ARCH_STRCPY 1
  85. #define __HAVE_ARCH_STRNCPY 1
  86. #define __HAVE_ARCH_STRCAT 1
  87. #define __HAVE_ARCH_STRNCAT 1
  88. #define __HAVE_ARCH_STRCMP 1
  89. #define __HAVE_ARCH_STRNCMP 1
  90. #define __HAVE_ARCH_STRNICMP 1
  91. #define __HAVE_ARCH_STRCHR 1
  92. #define __HAVE_ARCH_STRRCHR 1
  93. #define __HAVE_ARCH_STRSTR 1
  94. #define __HAVE_ARCH_STRLEN 1
  95. #define __HAVE_ARCH_STRNLEN 1
  96. #define __HAVE_ARCH_MEMSET 1
  97. #define __HAVE_ARCH_MEMCPY 1
  98. #define __HAVE_ARCH_MEMMOVE 1
  99. #define __HAVE_ARCH_MEMSCAN 1
  100. #define __HAVE_ARCH_MEMCMP 1
  101. #define __HAVE_ARCH_MEMCHR 1
  102. #define __HAVE_ARCH_STRTOK 1
  103. #endif /* KERNEL */
  104. #endif /* _M68K_STRING_H_ */