blob: cd0241db5a4688b754d6838497cfc06768b4025e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-s390/string.h
3 *
4 * S390 version
5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 */
8
9#ifndef _S390_STRING_H_
10#define _S390_STRING_H_
11
12#ifdef __KERNEL__
13
14#ifndef _LINUX_TYPES_H
15#include <linux/types.h>
16#endif
17
18#define __HAVE_ARCH_MEMCHR /* inline & arch function */
19#define __HAVE_ARCH_MEMCMP /* arch function */
20#define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */
21#define __HAVE_ARCH_MEMSCAN /* inline & arch function */
22#define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */
23#define __HAVE_ARCH_STRCAT /* inline & arch function */
24#define __HAVE_ARCH_STRCMP /* arch function */
25#define __HAVE_ARCH_STRCPY /* inline & arch function */
26#define __HAVE_ARCH_STRLCAT /* arch function */
27#define __HAVE_ARCH_STRLCPY /* arch function */
28#define __HAVE_ARCH_STRLEN /* inline & arch function */
29#define __HAVE_ARCH_STRNCAT /* arch function */
30#define __HAVE_ARCH_STRNCPY /* arch function */
31#define __HAVE_ARCH_STRNLEN /* inline & arch function */
32#define __HAVE_ARCH_STRRCHR /* arch function */
33#define __HAVE_ARCH_STRSTR /* arch function */
34
35/* Prototypes for non-inlined arch strings functions. */
36extern int memcmp(const void *, const void *, size_t);
37extern void *memcpy(void *, const void *, size_t);
38extern void *memset(void *, int, size_t);
39extern int strcmp(const char *,const char *);
40extern size_t strlcat(char *, const char *, size_t);
41extern size_t strlcpy(char *, const char *, size_t);
42extern char *strncat(char *, const char *, size_t);
43extern char *strncpy(char *, const char *, size_t);
44extern char *strrchr(const char *, int);
45extern char *strstr(const char *, const char *);
46
47#undef __HAVE_ARCH_MEMMOVE
48#undef __HAVE_ARCH_STRCHR
49#undef __HAVE_ARCH_STRNCHR
50#undef __HAVE_ARCH_STRNCMP
51#undef __HAVE_ARCH_STRNICMP
52#undef __HAVE_ARCH_STRPBRK
53#undef __HAVE_ARCH_STRSEP
54#undef __HAVE_ARCH_STRSPN
55
56#if !defined(IN_ARCH_STRING_C)
57
58static inline void *memchr(const void * s, int c, size_t n)
59{
60 register int r0 asm("0") = (char) c;
61 const void *ret = s + n;
62
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020063 asm volatile(
64 "0: srst %0,%1\n"
65 " jo 0b\n"
66 " jl 1f\n"
67 " la %0,0\n"
68 "1:"
69 : "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return (void *) ret;
71}
72
73static inline void *memscan(void *s, int c, size_t n)
74{
75 register int r0 asm("0") = (char) c;
76 const void *ret = s + n;
77
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020078 asm volatile(
79 "0: srst %0,%1\n"
80 " jo 0b\n"
81 : "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return (void *) ret;
83}
84
85static inline char *strcat(char *dst, const char *src)
86{
87 register int r0 asm("0") = 0;
88 unsigned long dummy;
89 char *ret = dst;
90
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020091 asm volatile(
92 "0: srst %0,%1\n"
93 " jo 0b\n"
94 "1: mvst %0,%2\n"
95 " jo 1b"
96 : "=&a" (dummy), "+a" (dst), "+a" (src)
97 : "d" (r0), "0" (0) : "cc", "memory" );
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return ret;
99}
100
101static inline char *strcpy(char *dst, const char *src)
102{
Heiko Carstens1edad852009-03-26 15:24:37 +0100103#if __GNUC__ < 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 register int r0 asm("0") = 0;
105 char *ret = dst;
106
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200107 asm volatile(
108 "0: mvst %0,%1\n"
109 " jo 0b"
110 : "+&a" (dst), "+&a" (src) : "d" (r0)
111 : "cc", "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return ret;
Heiko Carstens1edad852009-03-26 15:24:37 +0100113#else
114 return __builtin_strcpy(dst, src);
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
118static inline size_t strlen(const char *s)
119{
Heiko Carstens1edad852009-03-26 15:24:37 +0100120#if __GNUC__ < 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 register unsigned long r0 asm("0") = 0;
122 const char *tmp = s;
123
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200124 asm volatile(
125 "0: srst %0,%1\n"
126 " jo 0b"
127 : "+d" (r0), "+a" (tmp) : : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return r0 - (unsigned long) s;
Heiko Carstens1edad852009-03-26 15:24:37 +0100129#else
130 return __builtin_strlen(s);
131#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134static inline size_t strnlen(const char * s, size_t n)
135{
136 register int r0 asm("0") = 0;
137 const char *tmp = s;
138 const char *end = s + n;
139
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200140 asm volatile(
141 "0: srst %0,%1\n"
142 " jo 0b"
143 : "+a" (end), "+a" (tmp) : "d" (r0) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return end - s;
145}
Rusty Russell6faf2502009-03-26 15:24:33 +0100146#else /* IN_ARCH_STRING_C */
147void *memchr(const void * s, int c, size_t n);
148void *memscan(void *s, int c, size_t n);
149char *strcat(char *dst, const char *src);
150char *strcpy(char *dst, const char *src);
151size_t strlen(const char *s);
152size_t strnlen(const char * s, size_t n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif /* !IN_ARCH_STRING_C */
154
155#endif /* __KERNEL__ */
156
157#endif /* __S390_STRING_H_ */