at v2.6.23 135 lines 3.3 kB view raw
1#ifndef _BLACKFIN_STRING_H_ 2#define _BLACKFIN_STRING_H_ 3 4#ifdef __KERNEL__ /* only set these up for kernel code */ 5 6#define __HAVE_ARCH_STRCPY 7extern inline char *strcpy(char *dest, const char *src) 8{ 9 char *xdest = dest; 10 char temp = 0; 11 12 __asm__ __volatile__ ( 13 "1:" 14 "%2 = B [%1++] (Z);" 15 "B [%0++] = %2;" 16 "CC = %2;" 17 "if cc jump 1b (bp);" 18 : "+&a" (dest), "+&a" (src), "=&d" (temp) 19 : 20 : "memory", "CC"); 21 22 return xdest; 23} 24 25#define __HAVE_ARCH_STRNCPY 26extern inline char *strncpy(char *dest, const char *src, size_t n) 27{ 28 char *xdest = dest; 29 char temp = 0; 30 31 if (n == 0) 32 return xdest; 33 34 __asm__ __volatile__ ( 35 "1:" 36 "%3 = B [%1++] (Z);" 37 "B [%0++] = %3;" 38 "CC = %3;" 39 "if ! cc jump 2f;" 40 "%2 += -1;" 41 "CC = %2 == 0;" 42 "if ! cc jump 1b (bp);" 43 "jump 4f;" 44 "2:" 45 /* if src is shorter than n, we need to null pad bytes now */ 46 "%3 = 0;" 47 "3:" 48 "%2 += -1;" 49 "CC = %2 == 0;" 50 "if cc jump 4f;" 51 "B [%0++] = %3;" 52 "jump 3b;" 53 "4:" 54 : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp) 55 : 56 : "memory", "CC"); 57 58 return xdest; 59} 60 61#define __HAVE_ARCH_STRCMP 62extern inline int strcmp(const char *cs, const char *ct) 63{ 64 /* need to use int's here so the char's in the assembly don't get 65 * sign extended incorrectly when we don't want them to be 66 */ 67 int __res1, __res2; 68 69 __asm__ __volatile__ ( 70 "1:" 71 "%2 = B[%0++] (Z);" /* get *cs */ 72 "%3 = B[%1++] (Z);" /* get *ct */ 73 "CC = %2 == %3;" /* compare a byte */ 74 "if ! cc jump 2f;" /* not equal, break out */ 75 "CC = %2;" /* at end of cs? */ 76 "if cc jump 1b (bp);" /* no, keep going */ 77 "jump.s 3f;" /* strings are equal */ 78 "2:" 79 "%2 = %2 - %3;" /* *cs - *ct */ 80 "3:" 81 : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2) 82 : 83 : "memory", "CC"); 84 85 return __res1; 86} 87 88#define __HAVE_ARCH_STRNCMP 89extern inline int strncmp(const char *cs, const char *ct, size_t count) 90{ 91 /* need to use int's here so the char's in the assembly don't get 92 * sign extended incorrectly when we don't want them to be 93 */ 94 int __res1, __res2; 95 96 if (!count) 97 return 0; 98 99 __asm__ __volatile__ ( 100 "1:" 101 "%3 = B[%0++] (Z);" /* get *cs */ 102 "%4 = B[%1++] (Z);" /* get *ct */ 103 "CC = %3 == %4;" /* compare a byte */ 104 "if ! cc jump 3f;" /* not equal, break out */ 105 "CC = %3;" /* at end of cs? */ 106 "if ! cc jump 4f;" /* yes, all done */ 107 "%2 += -1;" /* no, adjust count */ 108 "CC = %2 == 0;" 109 "if ! cc jump 1b;" /* more to do, keep going */ 110 "2:" 111 "%3 = 0;" /* strings are equal */ 112 "jump.s 4f;" 113 "3:" 114 "%3 = %3 - %4;" /* *cs - *ct */ 115 "4:" 116 : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2) 117 : 118 : "memory", "CC"); 119 120 return __res1; 121} 122 123#define __HAVE_ARCH_MEMSET 124extern void *memset(void *s, int c, size_t count); 125#define __HAVE_ARCH_MEMCPY 126extern void *memcpy(void *d, const void *s, size_t count); 127#define __HAVE_ARCH_MEMCMP 128extern int memcmp(const void *, const void *, __kernel_size_t); 129#define __HAVE_ARCH_MEMCHR 130extern void *memchr(const void *s, int c, size_t n); 131#define __HAVE_ARCH_MEMMOVE 132extern void *memmove(void *dest, const void *src, size_t count); 133 134#endif /*__KERNEL__*/ 135#endif /* _BLACKFIN_STRING_H_ */