xref: /openbmc/u-boot/arch/sh/include/asm/string.h (revision 30754ef7)
1 #ifndef __ASM_SH_STRING_H
2 #define __ASM_SH_STRING_H
3 
4 /*
5  * Copyright (C) 1999 Niibe Yutaka
6  * But consider these trivial functions to be public domain.
7  *
8  * from linux kernel code.
9  */
10 
11 #ifdef __KERNEL__               /* only set these up for kernel code */
12 
13 #define __HAVE_ARCH_STRCPY
14 static inline char *strcpy(char *__dest, const char *__src)
15 {
16 	register char *__xdest = __dest;
17 	unsigned long __dummy;
18 
19 	__asm__ __volatile__("1:\n\t"
20 			     "mov.b	@%1+, %2\n\t"
21 			     "mov.b	%2, @%0\n\t"
22 			     "cmp/eq	#0, %2\n\t"
23 			     "bf/s	1b\n\t"
24 			     " add	#1, %0\n\t"
25 			     : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
26 			     : "0" (__dest), "1" (__src)
27 			     : "memory", "t");
28 
29 	return __xdest;
30 }
31 
32 #define __HAVE_ARCH_STRNCPY
33 static inline char *strncpy(char *__dest, const char *__src, size_t __n)
34 {
35 	register char *__xdest = __dest;
36 	unsigned long __dummy;
37 
38 	if (__n == 0)
39 		return __xdest;
40 
41 	__asm__ __volatile__(
42 		"1:\n"
43 		"mov.b	@%1+, %2\n\t"
44 		"mov.b	%2, @%0\n\t"
45 		"cmp/eq	#0, %2\n\t"
46 		"bt/s	2f\n\t"
47 		" cmp/eq	%5,%1\n\t"
48 		"bf/s	1b\n\t"
49 		" add	#1, %0\n"
50 		"2:"
51 		: "=r" (__dest), "=r" (__src), "=&z" (__dummy)
52 		: "0" (__dest), "1" (__src), "r" (__src+__n)
53 		: "memory", "t");
54 
55 	return __xdest;
56 }
57 
58 #define __HAVE_ARCH_STRCMP
59 static inline int strcmp(const char *__cs, const char *__ct)
60 {
61 	register int __res;
62 	unsigned long __dummy;
63 
64 	__asm__ __volatile__(
65 		"mov.b	@%1+, %3\n"
66 		"1:\n\t"
67 		"mov.b	@%0+, %2\n\t"
68 		"cmp/eq #0, %3\n\t"
69 		"bt	2f\n\t"
70 		"cmp/eq %2, %3\n\t"
71 		"bt/s	1b\n\t"
72 		" mov.b	@%1+, %3\n\t"
73 		"add	#-2, %1\n\t"
74 		"mov.b	@%1, %3\n\t"
75 		"sub	%3, %2\n"
76 		"2:"
77 		: "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
78 		: "0" (__cs), "1" (__ct)
79 		: "t");
80 
81 	return __res;
82 }
83 
84 #undef __HAVE_ARCH_STRNCMP
85 extern int strncmp(const char *__cs, const char *__ct, size_t __n);
86 
87 #undef __HAVE_ARCH_MEMSET
88 extern void *memset(void *__s, int __c, size_t __count);
89 
90 #undef __HAVE_ARCH_MEMCPY
91 extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
92 
93 #undef __HAVE_ARCH_MEMMOVE
94 extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
95 
96 #undef __HAVE_ARCH_MEMCHR
97 extern void *memchr(const void *__s, int __c, size_t __n);
98 
99 #undef __HAVE_ARCH_STRLEN
100 extern size_t strlen(const char *);
101 
102 /* arch/sh/lib/strcasecmp.c */
103 extern int strcasecmp(const char *, const char *);
104 
105 #else                           /* KERNEL */
106 
107 /*
108  * let user libraries deal with these,
109  * IMHO the kernel has no place defining these functions for user apps
110  */
111 
112 #define __HAVE_ARCH_STRCPY      1
113 #define __HAVE_ARCH_STRNCPY     1
114 #define __HAVE_ARCH_STRCAT      1
115 #define __HAVE_ARCH_STRNCAT     1
116 #define __HAVE_ARCH_STRCMP      1
117 #define __HAVE_ARCH_STRNCMP     1
118 #define __HAVE_ARCH_STRNICMP    1
119 #define __HAVE_ARCH_STRCHR      1
120 #define __HAVE_ARCH_STRRCHR     1
121 #define __HAVE_ARCH_STRSTR      1
122 #define __HAVE_ARCH_STRLEN      1
123 #define __HAVE_ARCH_STRNLEN     1
124 #define __HAVE_ARCH_MEMSET      1
125 #define __HAVE_ARCH_MEMCPY      1
126 #define __HAVE_ARCH_MEMMOVE     1
127 #define __HAVE_ARCH_MEMSCAN     1
128 #define __HAVE_ARCH_MEMCMP      1
129 #define __HAVE_ARCH_MEMCHR      1
130 #define __HAVE_ARCH_STRTOK      1
131 
132 #endif /* KERNEL */
133 #endif /* __ASM_SH_STRING_H */
134