string.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef _M68K_STRING_H_
  2. #define _M68K_STRING_H_
  3. #include <asm/setup.h>
  4. #include <asm/page.h>
  5. #define __HAVE_ARCH_STRCPY
  6. static inline char * strcpy(char * dest,const char *src)
  7. {
  8. char *xdest = dest;
  9. __asm__ __volatile__
  10. ("1:\tmoveb %1@+,%0@+\n\t"
  11. "jne 1b"
  12. : "=a" (dest), "=a" (src)
  13. : "0" (dest), "1" (src) : "memory");
  14. return xdest;
  15. }
  16. #define __HAVE_ARCH_STRNCPY
  17. static inline char * strncpy(char *dest, const char *src, size_t n)
  18. {
  19. char *xdest = dest;
  20. if (n == 0)
  21. return xdest;
  22. __asm__ __volatile__
  23. ("1:\tmoveb %1@+,%0@+\n\t"
  24. "jeq 2f\n\t"
  25. "subql #1,%2\n\t"
  26. "jne 1b\n\t"
  27. "2:"
  28. : "=a" (dest), "=a" (src), "=d" (n)
  29. : "0" (dest), "1" (src), "2" (n)
  30. : "memory");
  31. return xdest;
  32. }
  33. #define __HAVE_ARCH_STRCAT
  34. static inline char * strcat(char * dest, const char * src)
  35. {
  36. char *tmp = dest;
  37. while (*dest)
  38. dest++;
  39. while ((*dest++ = *src++))
  40. ;
  41. return tmp;
  42. }
  43. #define __HAVE_ARCH_STRNCAT
  44. static inline char * strncat(char *dest, const char *src, size_t count)
  45. {
  46. char *tmp = dest;
  47. if (count) {
  48. while (*dest)
  49. dest++;
  50. while ((*dest++ = *src++)) {
  51. if (--count == 0) {
  52. *dest++='\0';
  53. break;
  54. }
  55. }
  56. }
  57. return tmp;
  58. }
  59. #define __HAVE_ARCH_STRCHR
  60. static inline char * strchr(const char * s, int c)
  61. {
  62. const char ch = c;
  63. for(; *s != ch; ++s)
  64. if (*s == '\0')
  65. return( NULL );
  66. return( (char *) s);
  67. }
  68. /* strstr !! */
  69. #define __HAVE_ARCH_STRLEN
  70. static inline size_t strlen(const char * s)
  71. {
  72. const char *sc;
  73. for (sc = s; *sc != '\0'; ++sc) ;
  74. return(sc - s);
  75. }
  76. /* strnlen !! */
  77. #define __HAVE_ARCH_STRCMP
  78. static inline int strcmp(const char * cs,const char * ct)
  79. {
  80. char __res;
  81. __asm__
  82. ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
  83. "cmpb %1@+,%2\n\t" /* compare a byte */
  84. "jne 2f\n\t" /* not equal, break out */
  85. "tstb %2\n\t" /* at end of cs? */
  86. "jne 1b\n\t" /* no, keep going */
  87. "jra 3f\n\t" /* strings are equal */
  88. "2:\tsubb %1@-,%2\n\t" /* *cs - *ct */
  89. "3:"
  90. : "=a" (cs), "=a" (ct), "=d" (__res)
  91. : "0" (cs), "1" (ct));
  92. return __res;
  93. }
  94. #define __HAVE_ARCH_STRNCMP
  95. static inline int strncmp(const char * cs,const char * ct,size_t count)
  96. {
  97. char __res;
  98. if (!count)
  99. return 0;
  100. __asm__
  101. ("1:\tmovb %0@+,%3\n\t" /* get *cs */
  102. "cmpb %1@+,%3\n\t" /* compare a byte */
  103. "jne 3f\n\t" /* not equal, break out */
  104. "tstb %3\n\t" /* at end of cs? */
  105. "jeq 4f\n\t" /* yes, all done */
  106. "subql #1,%2\n\t" /* no, adjust count */
  107. "jne 1b\n\t" /* more to do, keep going */
  108. "2:\tmoveq #0,%3\n\t" /* strings are equal */
  109. "jra 4f\n\t"
  110. "3:\tsubb %1@-,%3\n\t" /* *cs - *ct */
  111. "4:"
  112. : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
  113. : "0" (cs), "1" (ct), "2" (count));
  114. return __res;
  115. }
  116. #define __HAVE_ARCH_MEMSET
  117. extern void *memset(void *, int, __kernel_size_t);
  118. #define memset(d, c, n) __builtin_memset(d, c, n)
  119. #define __HAVE_ARCH_MEMCPY
  120. extern void *memcpy(void *, const void *, __kernel_size_t);
  121. #define memcpy(d, s, n) __builtin_memcpy(d, s, n)
  122. #define __HAVE_ARCH_MEMMOVE
  123. extern void *memmove(void *, const void *, __kernel_size_t);
  124. #define __HAVE_ARCH_MEMCMP
  125. extern int memcmp(const void *, const void *, __kernel_size_t);
  126. #define memcmp(d, s, n) __builtin_memcmp(d, s, n)
  127. #endif /* _M68K_STRING_H_ */