2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* S390 version
|
2012-07-20 09:15:04 +00:00
|
|
|
* Copyright IBM Corp. 1999
|
2005-04-16 22:20:36 +00:00
|
|
|
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _S390_STRING_H_
|
|
|
|
#define _S390_STRING_H_
|
|
|
|
|
|
|
|
#ifndef _LINUX_TYPES_H
|
|
|
|
#include <linux/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define __HAVE_ARCH_MEMCHR /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_MEMCMP /* arch function */
|
|
|
|
#define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */
|
|
|
|
#define __HAVE_ARCH_MEMSCAN /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */
|
|
|
|
#define __HAVE_ARCH_STRCAT /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_STRCMP /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRCPY /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_STRLCAT /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRLCPY /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRLEN /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_STRNCAT /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRNCPY /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRNLEN /* inline & arch function */
|
|
|
|
#define __HAVE_ARCH_STRRCHR /* arch function */
|
|
|
|
#define __HAVE_ARCH_STRSTR /* arch function */
|
|
|
|
|
|
|
|
/* Prototypes for non-inlined arch strings functions. */
|
|
|
|
extern int memcmp(const void *, const void *, size_t);
|
|
|
|
extern void *memcpy(void *, const void *, size_t);
|
|
|
|
extern void *memset(void *, int, size_t);
|
|
|
|
extern int strcmp(const char *,const char *);
|
|
|
|
extern size_t strlcat(char *, const char *, size_t);
|
|
|
|
extern size_t strlcpy(char *, const char *, size_t);
|
|
|
|
extern char *strncat(char *, const char *, size_t);
|
|
|
|
extern char *strncpy(char *, const char *, size_t);
|
|
|
|
extern char *strrchr(const char *, int);
|
|
|
|
extern char *strstr(const char *, const char *);
|
|
|
|
|
|
|
|
#undef __HAVE_ARCH_MEMMOVE
|
|
|
|
#undef __HAVE_ARCH_STRCHR
|
|
|
|
#undef __HAVE_ARCH_STRNCHR
|
|
|
|
#undef __HAVE_ARCH_STRNCMP
|
|
|
|
#undef __HAVE_ARCH_STRNICMP
|
|
|
|
#undef __HAVE_ARCH_STRPBRK
|
|
|
|
#undef __HAVE_ARCH_STRSEP
|
|
|
|
#undef __HAVE_ARCH_STRSPN
|
|
|
|
|
|
|
|
#if !defined(IN_ARCH_STRING_C)
|
|
|
|
|
|
|
|
static inline void *memchr(const void * s, int c, size_t n)
|
|
|
|
{
|
|
|
|
register int r0 asm("0") = (char) c;
|
|
|
|
const void *ret = s + n;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: srst %0,%1\n"
|
|
|
|
" jo 0b\n"
|
|
|
|
" jl 1f\n"
|
|
|
|
" la %0,0\n"
|
|
|
|
"1:"
|
|
|
|
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
return (void *) ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *memscan(void *s, int c, size_t n)
|
|
|
|
{
|
|
|
|
register int r0 asm("0") = (char) c;
|
|
|
|
const void *ret = s + n;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: srst %0,%1\n"
|
|
|
|
" jo 0b\n"
|
|
|
|
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
return (void *) ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *strcat(char *dst, const char *src)
|
|
|
|
{
|
|
|
|
register int r0 asm("0") = 0;
|
|
|
|
unsigned long dummy;
|
|
|
|
char *ret = dst;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: srst %0,%1\n"
|
|
|
|
" jo 0b\n"
|
|
|
|
"1: mvst %0,%2\n"
|
|
|
|
" jo 1b"
|
|
|
|
: "=&a" (dummy), "+a" (dst), "+a" (src)
|
|
|
|
: "d" (r0), "0" (0) : "cc", "memory" );
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *strcpy(char *dst, const char *src)
|
|
|
|
{
|
2009-03-26 14:24:37 +00:00
|
|
|
#if __GNUC__ < 4
|
2005-04-16 22:20:36 +00:00
|
|
|
register int r0 asm("0") = 0;
|
|
|
|
char *ret = dst;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: mvst %0,%1\n"
|
|
|
|
" jo 0b"
|
|
|
|
: "+&a" (dst), "+&a" (src) : "d" (r0)
|
|
|
|
: "cc", "memory");
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
2009-03-26 14:24:37 +00:00
|
|
|
#else
|
|
|
|
return __builtin_strcpy(dst, src);
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t strlen(const char *s)
|
|
|
|
{
|
2009-03-26 14:24:37 +00:00
|
|
|
#if __GNUC__ < 4
|
2005-04-16 22:20:36 +00:00
|
|
|
register unsigned long r0 asm("0") = 0;
|
|
|
|
const char *tmp = s;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: srst %0,%1\n"
|
|
|
|
" jo 0b"
|
|
|
|
: "+d" (r0), "+a" (tmp) : : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
return r0 - (unsigned long) s;
|
2009-03-26 14:24:37 +00:00
|
|
|
#else
|
|
|
|
return __builtin_strlen(s);
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t strnlen(const char * s, size_t n)
|
|
|
|
{
|
|
|
|
register int r0 asm("0") = 0;
|
|
|
|
const char *tmp = s;
|
|
|
|
const char *end = s + n;
|
|
|
|
|
2006-09-28 14:56:43 +00:00
|
|
|
asm volatile(
|
|
|
|
"0: srst %0,%1\n"
|
|
|
|
" jo 0b"
|
|
|
|
: "+a" (end), "+a" (tmp) : "d" (r0) : "cc");
|
2005-04-16 22:20:36 +00:00
|
|
|
return end - s;
|
|
|
|
}
|
[S390] allow usage of string functions in linux/string.h
In introducing a trivial "strstarts()" function in linux/string.h, we
hit the following error on s390:
In file included from include/linux/bitmap.h:8,
from include/linux/cpumask.h:142,
from include/linux/smp.h:12,
from /home/rusty/devel/kernel/patches/linux-2.6/arch/s390/include/asm/spinlock.h:14,
from include/linux/spinlock.h:88,
from include/linux/seqlock.h:29,
from include/linux/time.h:8,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from arch/s390/lib/string.c:13:
include/linux/string.h: In function 'strstarts':
include/linux/string.h:124: error: implicit declaration of function 'strlen'
include/linux/string.h:124: warning: incompatible implicit declaration of built-in function 'strlen'
Because when including asm/string.h from arch/s390/lib/string.c we
don't declare the string ops we are about to define, and
linux/string.h barfs.
The fix is to declare them in this IN_ARCH_STRING_C case, but in
general I wonder if there's a neater fix.
Reported-by: linux-next
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2009-03-26 14:24:33 +00:00
|
|
|
#else /* IN_ARCH_STRING_C */
|
|
|
|
void *memchr(const void * s, int c, size_t n);
|
|
|
|
void *memscan(void *s, int c, size_t n);
|
|
|
|
char *strcat(char *dst, const char *src);
|
|
|
|
char *strcpy(char *dst, const char *src);
|
|
|
|
size_t strlen(const char *s);
|
|
|
|
size_t strnlen(const char * s, size_t n);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* !IN_ARCH_STRING_C */
|
|
|
|
|
|
|
|
#endif /* __S390_STRING_H_ */
|