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