#ifndef _M68K_STRING_H_
|
#ifndef _M68K_STRING_H_
|
#define _M68K_STRING_H_
|
#define _M68K_STRING_H_
|
|
|
#define __HAVE_ARCH_STRCPY
|
#define __HAVE_ARCH_STRCPY
|
extern inline char * strcpy(char * dest,const char *src)
|
extern inline char * strcpy(char * dest,const char *src)
|
{
|
{
|
char *xdest = dest;
|
char *xdest = dest;
|
|
|
__asm__ __volatile__
|
__asm__ __volatile__
|
("1:\tmoveb %1@+,%0@+\n\t"
|
("1:\tmoveb %1@+,%0@+\n\t"
|
"jne 1b"
|
"jne 1b"
|
: "=a" (dest), "=a" (src)
|
: "=a" (dest), "=a" (src)
|
: "0" (dest), "1" (src) : "memory");
|
: "0" (dest), "1" (src) : "memory");
|
return xdest;
|
return xdest;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRNCPY
|
#define __HAVE_ARCH_STRNCPY
|
extern inline char * strncpy(char *dest, const char *src, size_t n)
|
extern inline char * strncpy(char *dest, const char *src, size_t n)
|
{
|
{
|
char *xdest = dest;
|
char *xdest = dest;
|
|
|
if (n == 0)
|
if (n == 0)
|
return xdest;
|
return xdest;
|
|
|
__asm__ __volatile__
|
__asm__ __volatile__
|
("1:\tmoveb %1@+,%0@+\n\t"
|
("1:\tmoveb %1@+,%0@+\n\t"
|
"jeq 2f\n\t"
|
"jeq 2f\n\t"
|
"subql #1,%2\n\t"
|
"subql #1,%2\n\t"
|
"jne 1b\n\t"
|
"jne 1b\n\t"
|
"2:"
|
"2:"
|
: "=a" (dest), "=a" (src), "=d" (n)
|
: "=a" (dest), "=a" (src), "=d" (n)
|
: "0" (dest), "1" (src), "2" (n)
|
: "0" (dest), "1" (src), "2" (n)
|
: "memory");
|
: "memory");
|
return xdest;
|
return xdest;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRCAT
|
#define __HAVE_ARCH_STRCAT
|
extern inline char * strcat(char * dest, const char * src)
|
extern inline char * strcat(char * dest, const char * src)
|
{
|
{
|
char *tmp = dest;
|
char *tmp = dest;
|
|
|
while (*dest)
|
while (*dest)
|
dest++;
|
dest++;
|
while ((*dest++ = *src++))
|
while ((*dest++ = *src++))
|
;
|
;
|
|
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRNCAT
|
#define __HAVE_ARCH_STRNCAT
|
extern inline char * strncat(char *dest, const char *src, size_t count)
|
extern inline char * strncat(char *dest, const char *src, size_t count)
|
{
|
{
|
char *tmp = dest;
|
char *tmp = dest;
|
|
|
if (count) {
|
if (count) {
|
while (*dest)
|
while (*dest)
|
dest++;
|
dest++;
|
while ((*dest++ = *src++)) {
|
while ((*dest++ = *src++)) {
|
if (--count == 0) {
|
if (--count == 0) {
|
*dest++='\0';
|
*dest++='\0';
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRCHR
|
#define __HAVE_ARCH_STRCHR
|
extern inline char * strchr(const char * s, int c)
|
extern inline char * strchr(const char * s, int c)
|
{
|
{
|
const char ch = c;
|
const char ch = c;
|
|
|
for(; *s != ch; ++s)
|
for(; *s != ch; ++s)
|
if (*s == '\0')
|
if (*s == '\0')
|
return( NULL );
|
return( NULL );
|
return( (char *) s);
|
return( (char *) s);
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRPBRK
|
#define __HAVE_ARCH_STRPBRK
|
extern inline char * strpbrk(const char * cs,const char * ct)
|
extern inline char * strpbrk(const char * cs,const char * ct)
|
{
|
{
|
const char *sc1,*sc2;
|
const char *sc1,*sc2;
|
|
|
for( sc1 = cs; *sc1 != '\0'; ++sc1)
|
for( sc1 = cs; *sc1 != '\0'; ++sc1)
|
for( sc2 = ct; *sc2 != '\0'; ++sc2)
|
for( sc2 = ct; *sc2 != '\0'; ++sc2)
|
if (*sc1 == *sc2)
|
if (*sc1 == *sc2)
|
return((char *) sc1);
|
return((char *) sc1);
|
return( NULL );
|
return( NULL );
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRSPN
|
#define __HAVE_ARCH_STRSPN
|
extern inline size_t strspn(const char *s, const char *accept)
|
extern inline size_t strspn(const char *s, const char *accept)
|
{
|
{
|
const char *p;
|
const char *p;
|
const char *a;
|
const char *a;
|
size_t count = 0;
|
size_t count = 0;
|
|
|
for (p = s; *p != '\0'; ++p)
|
for (p = s; *p != '\0'; ++p)
|
{
|
{
|
for (a = accept; *a != '\0'; ++a)
|
for (a = accept; *a != '\0'; ++a)
|
if (*p == *a)
|
if (*p == *a)
|
break;
|
break;
|
if (*a == '\0')
|
if (*a == '\0')
|
return count;
|
return count;
|
else
|
else
|
++count;
|
++count;
|
}
|
}
|
|
|
return count;
|
return count;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRTOK
|
#define __HAVE_ARCH_STRTOK
|
extern inline char * strtok(char * s,const char * ct)
|
extern inline char * strtok(char * s,const char * ct)
|
{
|
{
|
char *sbegin, *send;
|
char *sbegin, *send;
|
|
|
sbegin = s ? s : ___strtok;
|
sbegin = s ? s : ___strtok;
|
if (!sbegin) {
|
if (!sbegin) {
|
return NULL;
|
return NULL;
|
}
|
}
|
sbegin += strspn(sbegin,ct);
|
sbegin += strspn(sbegin,ct);
|
if (*sbegin == '\0') {
|
if (*sbegin == '\0') {
|
___strtok = NULL;
|
___strtok = NULL;
|
return( NULL );
|
return( NULL );
|
}
|
}
|
send = strpbrk( sbegin, ct);
|
send = strpbrk( sbegin, ct);
|
if (send && *send != '\0')
|
if (send && *send != '\0')
|
*send++ = '\0';
|
*send++ = '\0';
|
___strtok = send;
|
___strtok = send;
|
return (sbegin);
|
return (sbegin);
|
}
|
}
|
|
|
/* strstr !! */
|
/* strstr !! */
|
|
|
#define __HAVE_ARCH_STRLEN
|
#define __HAVE_ARCH_STRLEN
|
extern inline size_t strlen(const char * s)
|
extern inline size_t strlen(const char * s)
|
{
|
{
|
const char *sc;
|
const char *sc;
|
for (sc = s; *sc != '\0'; ++sc) ;
|
for (sc = s; *sc != '\0'; ++sc) ;
|
return(sc - s);
|
return(sc - s);
|
}
|
}
|
|
|
/* strnlen !! */
|
/* strnlen !! */
|
|
|
#define __HAVE_ARCH_STRCMP
|
#define __HAVE_ARCH_STRCMP
|
extern inline int strcmp(const char * cs,const char * ct)
|
extern inline int strcmp(const char * cs,const char * ct)
|
{
|
{
|
char __res;
|
char __res;
|
|
|
__asm__
|
__asm__
|
("1:\tmoveb %0@+,%2\n\t" /* get *cs */
|
("1:\tmoveb %0@+,%2\n\t" /* get *cs */
|
"cmpb %1@+,%2\n\t" /* compare a byte */
|
"cmpb %1@+,%2\n\t" /* compare a byte */
|
"jne 2f\n\t" /* not equal, break out */
|
"jne 2f\n\t" /* not equal, break out */
|
"tstb %2\n\t" /* at end of cs? */
|
"tstb %2\n\t" /* at end of cs? */
|
"jne 1b\n\t" /* no, keep going */
|
"jne 1b\n\t" /* no, keep going */
|
"jra 3f\n\t" /* strings are equal */
|
"jra 3f\n\t" /* strings are equal */
|
"2:\tsubb %1@-,%2\n\t" /* *cs - *ct */
|
"2:\tsubb %1@-,%2\n\t" /* *cs - *ct */
|
"3:"
|
"3:"
|
: "=a" (cs), "=a" (ct), "=d" (__res)
|
: "=a" (cs), "=a" (ct), "=d" (__res)
|
: "0" (cs), "1" (ct));
|
: "0" (cs), "1" (ct));
|
return __res;
|
return __res;
|
}
|
}
|
|
|
#define __HAVE_ARCH_STRNCMP
|
#define __HAVE_ARCH_STRNCMP
|
extern inline int strncmp(const char * cs,const char * ct,size_t count)
|
extern inline int strncmp(const char * cs,const char * ct,size_t count)
|
{
|
{
|
char __res;
|
char __res;
|
|
|
if (!count)
|
if (!count)
|
return 0;
|
return 0;
|
__asm__
|
__asm__
|
("1:\tmovb %0@+,%3\n\t" /* get *cs */
|
("1:\tmovb %0@+,%3\n\t" /* get *cs */
|
"cmpb %1@+,%3\n\t" /* compare a byte */
|
"cmpb %1@+,%3\n\t" /* compare a byte */
|
"jne 3f\n\t" /* not equal, break out */
|
"jne 3f\n\t" /* not equal, break out */
|
"tstb %3\n\t" /* at end of cs? */
|
"tstb %3\n\t" /* at end of cs? */
|
"jeq 4f\n\t" /* yes, all done */
|
"jeq 4f\n\t" /* yes, all done */
|
"subql #1,%2\n\t" /* no, adjust count */
|
"subql #1,%2\n\t" /* no, adjust count */
|
"jne 1b\n\t" /* more to do, keep going */
|
"jne 1b\n\t" /* more to do, keep going */
|
"2:\tmoveq #0,%3\n\t" /* strings are equal */
|
"2:\tmoveq #0,%3\n\t" /* strings are equal */
|
"jra 4f\n\t"
|
"jra 4f\n\t"
|
"3:\tsubb %1@-,%3\n\t" /* *cs - *ct */
|
"3:\tsubb %1@-,%3\n\t" /* *cs - *ct */
|
"4:"
|
"4:"
|
: "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
|
: "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
|
: "0" (cs), "1" (ct), "2" (count));
|
: "0" (cs), "1" (ct), "2" (count));
|
return __res;
|
return __res;
|
}
|
}
|
|
|
#define __HAVE_ARCH_MEMSET
|
#define __HAVE_ARCH_MEMSET
|
extern inline void * memset(void * s,int c,size_t count)
|
extern inline void * memset(void * s,int c,size_t count)
|
{
|
{
|
void *xs = s;
|
void *xs = s;
|
size_t temp;
|
size_t temp;
|
|
|
if (!count)
|
if (!count)
|
return xs;
|
return xs;
|
c &= 0xff;
|
c &= 0xff;
|
if ((long) s & 1)
|
if ((long) s & 1)
|
{
|
{
|
char *cs = s;
|
char *cs = s;
|
*cs++ = c;
|
*cs++ = c;
|
s = cs;
|
s = cs;
|
count--;
|
count--;
|
}
|
}
|
c |= c << 8;
|
c |= c << 8;
|
if (count > 2 && (long) s & 2)
|
if (count > 2 && (long) s & 2)
|
{
|
{
|
short *ss = s;
|
short *ss = s;
|
*ss++ = c;
|
*ss++ = c;
|
s = ss;
|
s = ss;
|
count -= 2;
|
count -= 2;
|
}
|
}
|
temp = count >> 2;
|
temp = count >> 2;
|
if (temp)
|
if (temp)
|
{
|
{
|
long *ls = s;
|
long *ls = s;
|
c |= c << 16;
|
c |= c << 16;
|
temp--;
|
temp--;
|
do
|
do
|
*ls++ = c;
|
*ls++ = c;
|
while (temp--);
|
while (temp--);
|
s = ls;
|
s = ls;
|
}
|
}
|
if (count & 2)
|
if (count & 2)
|
{
|
{
|
short *ss = s;
|
short *ss = s;
|
*ss++ = c;
|
*ss++ = c;
|
s = ss;
|
s = ss;
|
}
|
}
|
if (count & 1)
|
if (count & 1)
|
{
|
{
|
char *cs = s;
|
char *cs = s;
|
*cs = c;
|
*cs = c;
|
}
|
}
|
return xs;
|
return xs;
|
}
|
}
|
|
|
#define __HAVE_ARCH_MEMCPY
|
#define __HAVE_ARCH_MEMCPY
|
#define memcpy(to, from, n) \
|
#define memcpy(to, from, n) \
|
(__builtin_constant_p(n) ? \
|
(__builtin_constant_p(n) ? \
|
__builtin_memcpy((to),(from),(n)) : \
|
__builtin_memcpy((to),(from),(n)) : \
|
memcpy((to),(from),(n)))
|
memcpy((to),(from),(n)))
|
|
|
#define __HAVE_ARCH_MEMMOVE
|
#define __HAVE_ARCH_MEMMOVE
|
extern inline void * memmove(void * dest,const void * src, size_t n)
|
extern inline void * memmove(void * dest,const void * src, size_t n)
|
{
|
{
|
void *xdest = dest;
|
void *xdest = dest;
|
size_t temp;
|
size_t temp;
|
|
|
if (!n)
|
if (!n)
|
return xdest;
|
return xdest;
|
|
|
if (dest < src)
|
if (dest < src)
|
{
|
{
|
if ((long) dest & 1)
|
if ((long) dest & 1)
|
{
|
{
|
char *cdest = dest;
|
char *cdest = dest;
|
const char *csrc = src;
|
const char *csrc = src;
|
*cdest++ = *csrc++;
|
*cdest++ = *csrc++;
|
dest = cdest;
|
dest = cdest;
|
src = csrc;
|
src = csrc;
|
n--;
|
n--;
|
}
|
}
|
if (n > 2 && (long) dest & 2)
|
if (n > 2 && (long) dest & 2)
|
{
|
{
|
short *sdest = dest;
|
short *sdest = dest;
|
const short *ssrc = src;
|
const short *ssrc = src;
|
*sdest++ = *ssrc++;
|
*sdest++ = *ssrc++;
|
dest = sdest;
|
dest = sdest;
|
src = ssrc;
|
src = ssrc;
|
n -= 2;
|
n -= 2;
|
}
|
}
|
temp = n >> 2;
|
temp = n >> 2;
|
if (temp)
|
if (temp)
|
{
|
{
|
long *ldest = dest;
|
long *ldest = dest;
|
const long *lsrc = src;
|
const long *lsrc = src;
|
temp--;
|
temp--;
|
do
|
do
|
*ldest++ = *lsrc++;
|
*ldest++ = *lsrc++;
|
while (temp--);
|
while (temp--);
|
dest = ldest;
|
dest = ldest;
|
src = lsrc;
|
src = lsrc;
|
}
|
}
|
if (n & 2)
|
if (n & 2)
|
{
|
{
|
short *sdest = dest;
|
short *sdest = dest;
|
const short *ssrc = src;
|
const short *ssrc = src;
|
*sdest++ = *ssrc++;
|
*sdest++ = *ssrc++;
|
dest = sdest;
|
dest = sdest;
|
src = ssrc;
|
src = ssrc;
|
}
|
}
|
if (n & 1)
|
if (n & 1)
|
{
|
{
|
char *cdest = dest;
|
char *cdest = dest;
|
const char *csrc = src;
|
const char *csrc = src;
|
*cdest = *csrc;
|
*cdest = *csrc;
|
}
|
}
|
}
|
}
|
else
|
else
|
{
|
{
|
dest = (char *) dest + n;
|
dest = (char *) dest + n;
|
src = (const char *) src + n;
|
src = (const char *) src + n;
|
if ((long) dest & 1)
|
if ((long) dest & 1)
|
{
|
{
|
char *cdest = dest;
|
char *cdest = dest;
|
const char *csrc = src;
|
const char *csrc = src;
|
*--cdest = *--csrc;
|
*--cdest = *--csrc;
|
dest = cdest;
|
dest = cdest;
|
src = csrc;
|
src = csrc;
|
n--;
|
n--;
|
}
|
}
|
if (n > 2 && (long) dest & 2)
|
if (n > 2 && (long) dest & 2)
|
{
|
{
|
short *sdest = dest;
|
short *sdest = dest;
|
const short *ssrc = src;
|
const short *ssrc = src;
|
*--sdest = *--ssrc;
|
*--sdest = *--ssrc;
|
dest = sdest;
|
dest = sdest;
|
src = ssrc;
|
src = ssrc;
|
n -= 2;
|
n -= 2;
|
}
|
}
|
temp = n >> 2;
|
temp = n >> 2;
|
if (temp)
|
if (temp)
|
{
|
{
|
long *ldest = dest;
|
long *ldest = dest;
|
const long *lsrc = src;
|
const long *lsrc = src;
|
temp--;
|
temp--;
|
do
|
do
|
*--ldest = *--lsrc;
|
*--ldest = *--lsrc;
|
while (temp--);
|
while (temp--);
|
dest = ldest;
|
dest = ldest;
|
src = lsrc;
|
src = lsrc;
|
}
|
}
|
if (n & 2)
|
if (n & 2)
|
{
|
{
|
short *sdest = dest;
|
short *sdest = dest;
|
const short *ssrc = src;
|
const short *ssrc = src;
|
*--sdest = *--ssrc;
|
*--sdest = *--ssrc;
|
dest = sdest;
|
dest = sdest;
|
src = ssrc;
|
src = ssrc;
|
}
|
}
|
if (n & 1)
|
if (n & 1)
|
{
|
{
|
char *cdest = dest;
|
char *cdest = dest;
|
const char *csrc = src;
|
const char *csrc = src;
|
*--cdest = *--csrc;
|
*--cdest = *--csrc;
|
}
|
}
|
}
|
}
|
return xdest;
|
return xdest;
|
}
|
}
|
|
|
#define __HAVE_ARCH_MEMCMP
|
#define __HAVE_ARCH_MEMCMP
|
#define memcmp(cs, ct, n) \
|
#define memcmp(cs, ct, n) \
|
(__builtin_constant_p(n) ? \
|
(__builtin_constant_p(n) ? \
|
__builtin_memcmp((cs),(ct),(n)) : \
|
__builtin_memcmp((cs),(ct),(n)) : \
|
memcmp((cs),(ct),(n)))
|
memcmp((cs),(ct),(n)))
|
|
|
#endif /* _M68K_STRING_H_ */
|
#endif /* _M68K_STRING_H_ */
|
|
|