diff options
| author | Greg Ungerer <gerg@snapgear.com> | 2010-09-07 00:52:52 -0400 |
|---|---|---|
| committer | Geert Uytterhoeven <geert@linux-m68k.org> | 2010-10-22 03:43:23 -0400 |
| commit | ea61bc461d09e8d331a307916530aaae808c72a2 (patch) | |
| tree | 813b2ef469f9712d73cf165a2904b23f527256b0 | |
| parent | 5bc5a70b62e5b672e40dd031da3e0444f62dbd3a (diff) | |
m68k/m68knommu: merge MMU and non-MMU string.h
The MMU and non-MMU string.h varients (string_no.h and string_mm.h)
and almost the same. Switch to using the string_mm.h one, merging
in the necessary ColdFire support.
Signed-off-by: Greg Ungerer <gerg@uclinux.org>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
| -rw-r--r-- | arch/m68k/include/asm/string.h | 134 | ||||
| -rw-r--r-- | arch/m68k/include/asm/string_mm.h | 131 | ||||
| -rw-r--r-- | arch/m68k/include/asm/string_no.h | 126 |
3 files changed, 131 insertions, 260 deletions
diff --git a/arch/m68k/include/asm/string.h b/arch/m68k/include/asm/string.h index 2c356f90f171..2936dda938d7 100644 --- a/arch/m68k/include/asm/string.h +++ b/arch/m68k/include/asm/string.h | |||
| @@ -1,5 +1,133 @@ | |||
| 1 | #ifdef __uClinux__ | 1 | #ifndef _M68K_STRING_H_ |
| 2 | #include "string_no.h" | 2 | #define _M68K_STRING_H_ |
| 3 | |||
| 4 | #include <linux/types.h> | ||
| 5 | #include <linux/compiler.h> | ||
| 6 | |||
| 7 | static inline size_t __kernel_strlen(const char *s) | ||
| 8 | { | ||
| 9 | const char *sc; | ||
| 10 | |||
| 11 | for (sc = s; *sc++; ) | ||
| 12 | ; | ||
| 13 | return sc - s - 1; | ||
| 14 | } | ||
| 15 | |||
| 16 | static inline char *__kernel_strcpy(char *dest, const char *src) | ||
| 17 | { | ||
| 18 | char *xdest = dest; | ||
| 19 | |||
| 20 | asm volatile ("\n" | ||
| 21 | "1: move.b (%1)+,(%0)+\n" | ||
| 22 | " jne 1b" | ||
| 23 | : "+a" (dest), "+a" (src) | ||
| 24 | : : "memory"); | ||
| 25 | return xdest; | ||
| 26 | } | ||
| 27 | |||
| 28 | #ifndef __IN_STRING_C | ||
| 29 | |||
| 30 | #define __HAVE_ARCH_STRLEN | ||
| 31 | #define strlen(s) (__builtin_constant_p(s) ? \ | ||
| 32 | __builtin_strlen(s) : \ | ||
| 33 | __kernel_strlen(s)) | ||
| 34 | |||
| 35 | #define __HAVE_ARCH_STRNLEN | ||
| 36 | static inline size_t strnlen(const char *s, size_t count) | ||
| 37 | { | ||
| 38 | const char *sc = s; | ||
| 39 | |||
| 40 | asm volatile ("\n" | ||
| 41 | "1: subq.l #1,%1\n" | ||
| 42 | " jcs 2f\n" | ||
| 43 | " tst.b (%0)+\n" | ||
| 44 | " jne 1b\n" | ||
| 45 | " subq.l #1,%0\n" | ||
| 46 | "2:" | ||
| 47 | : "+a" (sc), "+d" (count)); | ||
| 48 | return sc - s; | ||
| 49 | } | ||
| 50 | |||
| 51 | #define __HAVE_ARCH_STRCPY | ||
| 52 | #if __GNUC__ >= 4 | ||
| 53 | #define strcpy(d, s) (__builtin_constant_p(s) && \ | ||
| 54 | __builtin_strlen(s) <= 32 ? \ | ||
| 55 | __builtin_strcpy(d, s) : \ | ||
| 56 | __kernel_strcpy(d, s)) | ||
| 3 | #else | 57 | #else |
| 4 | #include "string_mm.h" | 58 | #define strcpy(d, s) __kernel_strcpy(d, s) |
| 5 | #endif | 59 | #endif |
| 60 | |||
| 61 | #define __HAVE_ARCH_STRNCPY | ||
| 62 | static inline char *strncpy(char *dest, const char *src, size_t n) | ||
| 63 | { | ||
| 64 | char *xdest = dest; | ||
| 65 | |||
| 66 | asm volatile ("\n" | ||
| 67 | " jra 2f\n" | ||
| 68 | "1: move.b (%1),(%0)+\n" | ||
| 69 | " jeq 2f\n" | ||
| 70 | " addq.l #1,%1\n" | ||
| 71 | "2: subq.l #1,%2\n" | ||
| 72 | " jcc 1b\n" | ||
| 73 | : "+a" (dest), "+a" (src), "+d" (n) | ||
| 74 | : : "memory"); | ||
| 75 | return xdest; | ||
| 76 | } | ||
| 77 | |||
| 78 | #define __HAVE_ARCH_STRCAT | ||
| 79 | #define strcat(d, s) ({ \ | ||
| 80 | char *__d = (d); \ | ||
| 81 | strcpy(__d + strlen(__d), (s)); \ | ||
| 82 | }) | ||
| 83 | |||
| 84 | #define __HAVE_ARCH_STRCHR | ||
| 85 | static inline char *strchr(const char *s, int c) | ||
| 86 | { | ||
| 87 | char sc, ch = c; | ||
| 88 | |||
| 89 | for (; (sc = *s++) != ch; ) { | ||
| 90 | if (!sc) | ||
| 91 | return NULL; | ||
| 92 | } | ||
| 93 | return (char *)s - 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | #ifndef CONFIG_COLDFIRE | ||
| 97 | #define __HAVE_ARCH_STRCMP | ||
| 98 | static inline int strcmp(const char *cs, const char *ct) | ||
| 99 | { | ||
| 100 | char res; | ||
| 101 | |||
| 102 | asm ("\n" | ||
| 103 | "1: move.b (%0)+,%2\n" /* get *cs */ | ||
| 104 | " cmp.b (%1)+,%2\n" /* compare a byte */ | ||
| 105 | " jne 2f\n" /* not equal, break out */ | ||
| 106 | " tst.b %2\n" /* at end of cs? */ | ||
| 107 | " jne 1b\n" /* no, keep going */ | ||
| 108 | " jra 3f\n" /* strings are equal */ | ||
| 109 | "2: sub.b -(%1),%2\n" /* *cs - *ct */ | ||
| 110 | "3:" | ||
| 111 | : "+a" (cs), "+a" (ct), "=d" (res)); | ||
| 112 | return res; | ||
| 113 | } | ||
| 114 | |||
| 115 | #define __HAVE_ARCH_MEMMOVE | ||
| 116 | extern void *memmove(void *, const void *, __kernel_size_t); | ||
| 117 | |||
| 118 | #define __HAVE_ARCH_MEMCMP | ||
| 119 | extern int memcmp(const void *, const void *, __kernel_size_t); | ||
| 120 | #define memcmp(d, s, n) __builtin_memcmp(d, s, n) | ||
| 121 | #endif /* CONFIG_COLDFIRE */ | ||
| 122 | |||
| 123 | #define __HAVE_ARCH_MEMSET | ||
| 124 | extern void *memset(void *, int, __kernel_size_t); | ||
| 125 | #define memset(d, c, n) __builtin_memset(d, c, n) | ||
| 126 | |||
| 127 | #define __HAVE_ARCH_MEMCPY | ||
| 128 | extern void *memcpy(void *, const void *, __kernel_size_t); | ||
| 129 | #define memcpy(d, s, n) __builtin_memcpy(d, s, n) | ||
| 130 | |||
| 131 | #endif | ||
| 132 | |||
| 133 | #endif /* _M68K_STRING_H_ */ | ||
diff --git a/arch/m68k/include/asm/string_mm.h b/arch/m68k/include/asm/string_mm.h deleted file mode 100644 index 2eb7df1e0f5d..000000000000 --- a/arch/m68k/include/asm/string_mm.h +++ /dev/null | |||
| @@ -1,131 +0,0 @@ | |||
| 1 | #ifndef _M68K_STRING_H_ | ||
| 2 | #define _M68K_STRING_H_ | ||
| 3 | |||
| 4 | #include <linux/types.h> | ||
| 5 | #include <linux/compiler.h> | ||
| 6 | |||
| 7 | static inline size_t __kernel_strlen(const char *s) | ||
| 8 | { | ||
| 9 | const char *sc; | ||
| 10 | |||
| 11 | for (sc = s; *sc++; ) | ||
| 12 | ; | ||
| 13 | return sc - s - 1; | ||
| 14 | } | ||
| 15 | |||
| 16 | static inline char *__kernel_strcpy(char *dest, const char *src) | ||
| 17 | { | ||
| 18 | char *xdest = dest; | ||
| 19 | |||
| 20 | asm volatile ("\n" | ||
| 21 | "1: move.b (%1)+,(%0)+\n" | ||
| 22 | " jne 1b" | ||
| 23 | : "+a" (dest), "+a" (src) | ||
| 24 | : : "memory"); | ||
| 25 | return xdest; | ||
| 26 | } | ||
| 27 | |||
| 28 | #ifndef __IN_STRING_C | ||
| 29 | |||
| 30 | #define __HAVE_ARCH_STRLEN | ||
| 31 | #define strlen(s) (__builtin_constant_p(s) ? \ | ||
| 32 | __builtin_strlen(s) : \ | ||
| 33 | __kernel_strlen(s)) | ||
| 34 | |||
| 35 | #define __HAVE_ARCH_STRNLEN | ||
| 36 | static inline size_t strnlen(const char *s, size_t count) | ||
| 37 | { | ||
| 38 | const char *sc = s; | ||
| 39 | |||
| 40 | asm volatile ("\n" | ||
| 41 | "1: subq.l #1,%1\n" | ||
| 42 | " jcs 2f\n" | ||
| 43 | " tst.b (%0)+\n" | ||
| 44 | " jne 1b\n" | ||
| 45 | " subq.l #1,%0\n" | ||
| 46 | "2:" | ||
| 47 | : "+a" (sc), "+d" (count)); | ||
| 48 | return sc - s; | ||
| 49 | } | ||
| 50 | |||
| 51 | #define __HAVE_ARCH_STRCPY | ||
| 52 | #if __GNUC__ >= 4 | ||
| 53 | #define strcpy(d, s) (__builtin_constant_p(s) && \ | ||
| 54 | __builtin_strlen(s) <= 32 ? \ | ||
| 55 | __builtin_strcpy(d, s) : \ | ||
| 56 | __kernel_strcpy(d, s)) | ||
| 57 | #else | ||
| 58 | #define strcpy(d, s) __kernel_strcpy(d, s) | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #define __HAVE_ARCH_STRNCPY | ||
| 62 | static inline char *strncpy(char *dest, const char *src, size_t n) | ||
| 63 | { | ||
| 64 | char *xdest = dest; | ||
| 65 | |||
| 66 | asm volatile ("\n" | ||
| 67 | " jra 2f\n" | ||
| 68 | "1: move.b (%1),(%0)+\n" | ||
| 69 | " jeq 2f\n" | ||
| 70 | " addq.l #1,%1\n" | ||
| 71 | "2: subq.l #1,%2\n" | ||
| 72 | " jcc 1b\n" | ||
| 73 | : "+a" (dest), "+a" (src), "+d" (n) | ||
| 74 | : : "memory"); | ||
| 75 | return xdest; | ||
| 76 | } | ||
| 77 | |||
| 78 | #define __HAVE_ARCH_STRCAT | ||
| 79 | #define strcat(d, s) ({ \ | ||
| 80 | char *__d = (d); \ | ||
| 81 | strcpy(__d + strlen(__d), (s)); \ | ||
| 82 | }) | ||
| 83 | |||
| 84 | #define __HAVE_ARCH_STRCHR | ||
| 85 | static inline char *strchr(const char *s, int c) | ||
| 86 | { | ||
| 87 | char sc, ch = c; | ||
| 88 | |||
| 89 | for (; (sc = *s++) != ch; ) { | ||
| 90 | if (!sc) | ||
| 91 | return NULL; | ||
| 92 | } | ||
| 93 | return (char *)s - 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | #define __HAVE_ARCH_STRCMP | ||
| 97 | static inline int strcmp(const char *cs, const char *ct) | ||
| 98 | { | ||
| 99 | char res; | ||
| 100 | |||
| 101 | asm ("\n" | ||
| 102 | "1: move.b (%0)+,%2\n" /* get *cs */ | ||
| 103 | " cmp.b (%1)+,%2\n" /* compare a byte */ | ||
| 104 | " jne 2f\n" /* not equal, break out */ | ||
| 105 | " tst.b %2\n" /* at end of cs? */ | ||
| 106 | " jne 1b\n" /* no, keep going */ | ||
| 107 | " jra 3f\n" /* strings are equal */ | ||
| 108 | "2: sub.b -(%1),%2\n" /* *cs - *ct */ | ||
| 109 | "3:" | ||
| 110 | : "+a" (cs), "+a" (ct), "=d" (res)); | ||
| 111 | return res; | ||
| 112 | } | ||
| 113 | |||
| 114 | #define __HAVE_ARCH_MEMSET | ||
| 115 | extern void *memset(void *, int, __kernel_size_t); | ||
| 116 | #define memset(d, c, n) __builtin_memset(d, c, n) | ||
| 117 | |||
| 118 | #define __HAVE_ARCH_MEMCPY | ||
| 119 | extern void *memcpy(void *, const void *, __kernel_size_t); | ||
| 120 | #define memcpy(d, s, n) __builtin_memcpy(d, s, n) | ||
| 121 | |||
| 122 | #define __HAVE_ARCH_MEMMOVE | ||
| 123 | extern void *memmove(void *, const void *, __kernel_size_t); | ||
| 124 | |||
| 125 | #define __HAVE_ARCH_MEMCMP | ||
| 126 | extern int memcmp(const void *, const void *, __kernel_size_t); | ||
| 127 | #define memcmp(d, s, n) __builtin_memcmp(d, s, n) | ||
| 128 | |||
| 129 | #endif | ||
| 130 | |||
| 131 | #endif /* _M68K_STRING_H_ */ | ||
diff --git a/arch/m68k/include/asm/string_no.h b/arch/m68k/include/asm/string_no.h deleted file mode 100644 index af09e17000fc..000000000000 --- a/arch/m68k/include/asm/string_no.h +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | #ifndef _M68KNOMMU_STRING_H_ | ||
| 2 | #define _M68KNOMMU_STRING_H_ | ||
| 3 | |||
| 4 | #ifdef __KERNEL__ /* only set these up for kernel code */ | ||
| 5 | |||
| 6 | #include <asm/setup.h> | ||
| 7 | #include <asm/page.h> | ||
| 8 | |||
| 9 | #define __HAVE_ARCH_STRCPY | ||
| 10 | static inline char * strcpy(char * dest,const char *src) | ||
| 11 | { | ||
| 12 | char *xdest = dest; | ||
| 13 | |||
| 14 | __asm__ __volatile__ | ||
| 15 | ("1:\tmoveb %1@+,%0@+\n\t" | ||
| 16 | "jne 1b" | ||
| 17 | : "=a" (dest), "=a" (src) | ||
| 18 | : "0" (dest), "1" (src) : "memory"); | ||
| 19 | return xdest; | ||
| 20 | } | ||
| 21 | |||
| 22 | #define __HAVE_ARCH_STRNCPY | ||
| 23 | static inline char * strncpy(char *dest, const char *src, size_t n) | ||
| 24 | { | ||
| 25 | char *xdest = dest; | ||
| 26 | |||
| 27 | if (n == 0) | ||
| 28 | return xdest; | ||
| 29 | |||
| 30 | __asm__ __volatile__ | ||
| 31 | ("1:\tmoveb %1@+,%0@+\n\t" | ||
| 32 | "jeq 2f\n\t" | ||
| 33 | "subql #1,%2\n\t" | ||
| 34 | "jne 1b\n\t" | ||
| 35 | "2:" | ||
| 36 | : "=a" (dest), "=a" (src), "=d" (n) | ||
| 37 | : "0" (dest), "1" (src), "2" (n) | ||
| 38 | : "memory"); | ||
| 39 | return xdest; | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | #ifndef CONFIG_COLDFIRE | ||
| 44 | |||
| 45 | #define __HAVE_ARCH_STRCMP | ||
| 46 | static inline int strcmp(const char * cs,const char * ct) | ||
| 47 | { | ||
| 48 | char __res; | ||
| 49 | |||
| 50 | __asm__ | ||
| 51 | ("1:\tmoveb %0@+,%2\n\t" /* get *cs */ | ||
| 52 | "cmpb %1@+,%2\n\t" /* compare a byte */ | ||
| 53 | "jne 2f\n\t" /* not equal, break out */ | ||
| 54 | "tstb %2\n\t" /* at end of cs? */ | ||
| 55 | "jne 1b\n\t" /* no, keep going */ | ||
| 56 | "jra 3f\n\t" /* strings are equal */ | ||
| 57 | "2:\tsubb %1@-,%2\n\t" /* *cs - *ct */ | ||
| 58 | "3:" | ||
| 59 | : "=a" (cs), "=a" (ct), "=d" (__res) | ||
| 60 | : "0" (cs), "1" (ct)); | ||
| 61 | |||
| 62 | return __res; | ||
| 63 | } | ||
| 64 | |||
| 65 | #define __HAVE_ARCH_STRNCMP | ||
| 66 | static inline int strncmp(const char * cs,const char * ct,size_t count) | ||
| 67 | { | ||
| 68 | char __res; | ||
| 69 | |||
| 70 | if (!count) | ||
| 71 | return 0; | ||
| 72 | __asm__ | ||
| 73 | ("1:\tmovb %0@+,%3\n\t" /* get *cs */ | ||
| 74 | "cmpb %1@+,%3\n\t" /* compare a byte */ | ||
| 75 | "jne 3f\n\t" /* not equal, break out */ | ||
| 76 | "tstb %3\n\t" /* at end of cs? */ | ||
| 77 | "jeq 4f\n\t" /* yes, all done */ | ||
| 78 | "subql #1,%2\n\t" /* no, adjust count */ | ||
| 79 | "jne 1b\n\t" /* more to do, keep going */ | ||
| 80 | "2:\tmoveq #0,%3\n\t" /* strings are equal */ | ||
| 81 | "jra 4f\n\t" | ||
| 82 | "3:\tsubb %1@-,%3\n\t" /* *cs - *ct */ | ||
| 83 | "4:" | ||
| 84 | : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res) | ||
| 85 | : "0" (cs), "1" (ct), "2" (count)); | ||
| 86 | return __res; | ||
| 87 | } | ||
| 88 | |||
| 89 | #endif /* CONFIG_COLDFIRE */ | ||
| 90 | |||
| 91 | #define __HAVE_ARCH_MEMSET | ||
| 92 | extern void * memset(void * s, int c, size_t count); | ||
| 93 | |||
| 94 | #define __HAVE_ARCH_MEMCPY | ||
| 95 | extern void * memcpy(void *d, const void *s, size_t count); | ||
| 96 | |||
| 97 | #else /* KERNEL */ | ||
| 98 | |||
| 99 | /* | ||
| 100 | * let user libraries deal with these, | ||
| 101 | * IMHO the kernel has no place defining these functions for user apps | ||
| 102 | */ | ||
| 103 | |||
| 104 | #define __HAVE_ARCH_STRCPY 1 | ||
| 105 | #define __HAVE_ARCH_STRNCPY 1 | ||
| 106 | #define __HAVE_ARCH_STRCAT 1 | ||
| 107 | #define __HAVE_ARCH_STRNCAT 1 | ||
| 108 | #define __HAVE_ARCH_STRCMP 1 | ||
| 109 | #define __HAVE_ARCH_STRNCMP 1 | ||
| 110 | #define __HAVE_ARCH_STRNICMP 1 | ||
| 111 | #define __HAVE_ARCH_STRCHR 1 | ||
| 112 | #define __HAVE_ARCH_STRRCHR 1 | ||
| 113 | #define __HAVE_ARCH_STRSTR 1 | ||
| 114 | #define __HAVE_ARCH_STRLEN 1 | ||
| 115 | #define __HAVE_ARCH_STRNLEN 1 | ||
| 116 | #define __HAVE_ARCH_MEMSET 1 | ||
| 117 | #define __HAVE_ARCH_MEMCPY 1 | ||
| 118 | #define __HAVE_ARCH_MEMMOVE 1 | ||
| 119 | #define __HAVE_ARCH_MEMSCAN 1 | ||
| 120 | #define __HAVE_ARCH_MEMCMP 1 | ||
| 121 | #define __HAVE_ARCH_MEMCHR 1 | ||
| 122 | #define __HAVE_ARCH_STRTOK 1 | ||
| 123 | |||
| 124 | #endif /* KERNEL */ | ||
| 125 | |||
| 126 | #endif /* _M68K_STRING_H_ */ | ||
