Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 | 2 | /* |
1da177e4 | 3 | * S390 version |
a53c8fab | 4 | * Copyright IBM Corp. 1999 |
1da177e4 LT |
5 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), |
6 | */ | |
7 | ||
8 | #ifndef _S390_STRING_H_ | |
9 | #define _S390_STRING_H_ | |
10 | ||
1da177e4 LT |
11 | #ifndef _LINUX_TYPES_H |
12 | #include <linux/types.h> | |
13 | #endif | |
14 | ||
15 | #define __HAVE_ARCH_MEMCHR /* inline & arch function */ | |
16 | #define __HAVE_ARCH_MEMCMP /* arch function */ | |
17 | #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */ | |
b4623d4e | 18 | #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */ |
1da177e4 LT |
19 | #define __HAVE_ARCH_MEMSCAN /* inline & arch function */ |
20 | #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */ | |
21 | #define __HAVE_ARCH_STRCAT /* inline & arch function */ | |
22 | #define __HAVE_ARCH_STRCMP /* arch function */ | |
23 | #define __HAVE_ARCH_STRCPY /* inline & arch function */ | |
24 | #define __HAVE_ARCH_STRLCAT /* arch function */ | |
25 | #define __HAVE_ARCH_STRLCPY /* arch function */ | |
26 | #define __HAVE_ARCH_STRLEN /* inline & arch function */ | |
27 | #define __HAVE_ARCH_STRNCAT /* arch function */ | |
28 | #define __HAVE_ARCH_STRNCPY /* arch function */ | |
29 | #define __HAVE_ARCH_STRNLEN /* inline & arch function */ | |
30 | #define __HAVE_ARCH_STRRCHR /* arch function */ | |
31 | #define __HAVE_ARCH_STRSTR /* arch function */ | |
32 | ||
33 | /* Prototypes for non-inlined arch strings functions. */ | |
34 | extern int memcmp(const void *, const void *, size_t); | |
35 | extern void *memcpy(void *, const void *, size_t); | |
36 | extern void *memset(void *, int, size_t); | |
b4623d4e | 37 | extern void *memmove(void *, const void *, size_t); |
1da177e4 LT |
38 | extern int strcmp(const char *,const char *); |
39 | extern size_t strlcat(char *, const char *, size_t); | |
40 | extern size_t strlcpy(char *, const char *, size_t); | |
41 | extern char *strncat(char *, const char *, size_t); | |
42 | extern char *strncpy(char *, const char *, size_t); | |
43 | extern char *strrchr(const char *, int); | |
44 | extern char *strstr(const char *, const char *); | |
45 | ||
1da177e4 LT |
46 | #undef __HAVE_ARCH_STRCHR |
47 | #undef __HAVE_ARCH_STRNCHR | |
48 | #undef __HAVE_ARCH_STRNCMP | |
1da177e4 LT |
49 | #undef __HAVE_ARCH_STRPBRK |
50 | #undef __HAVE_ARCH_STRSEP | |
51 | #undef __HAVE_ARCH_STRSPN | |
52 | ||
53 | #if !defined(IN_ARCH_STRING_C) | |
54 | ||
55 | static inline void *memchr(const void * s, int c, size_t n) | |
56 | { | |
57 | register int r0 asm("0") = (char) c; | |
58 | const void *ret = s + n; | |
59 | ||
94c12cc7 MS |
60 | asm volatile( |
61 | "0: srst %0,%1\n" | |
62 | " jo 0b\n" | |
63 | " jl 1f\n" | |
64 | " la %0,0\n" | |
65 | "1:" | |
7a71fd1c | 66 | : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory"); |
1da177e4 LT |
67 | return (void *) ret; |
68 | } | |
69 | ||
70 | static inline void *memscan(void *s, int c, size_t n) | |
71 | { | |
72 | register int r0 asm("0") = (char) c; | |
73 | const void *ret = s + n; | |
74 | ||
94c12cc7 MS |
75 | asm volatile( |
76 | "0: srst %0,%1\n" | |
77 | " jo 0b\n" | |
7a71fd1c | 78 | : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory"); |
1da177e4 LT |
79 | return (void *) ret; |
80 | } | |
81 | ||
82 | static inline char *strcat(char *dst, const char *src) | |
83 | { | |
84 | register int r0 asm("0") = 0; | |
85 | unsigned long dummy; | |
86 | char *ret = dst; | |
87 | ||
94c12cc7 MS |
88 | asm volatile( |
89 | "0: srst %0,%1\n" | |
90 | " jo 0b\n" | |
91 | "1: mvst %0,%2\n" | |
92 | " jo 1b" | |
93 | : "=&a" (dummy), "+a" (dst), "+a" (src) | |
94 | : "d" (r0), "0" (0) : "cc", "memory" ); | |
1da177e4 LT |
95 | return ret; |
96 | } | |
97 | ||
98 | static inline char *strcpy(char *dst, const char *src) | |
99 | { | |
100 | register int r0 asm("0") = 0; | |
101 | char *ret = dst; | |
102 | ||
94c12cc7 MS |
103 | asm volatile( |
104 | "0: mvst %0,%1\n" | |
105 | " jo 0b" | |
106 | : "+&a" (dst), "+&a" (src) : "d" (r0) | |
107 | : "cc", "memory"); | |
1da177e4 LT |
108 | return ret; |
109 | } | |
110 | ||
111 | static inline size_t strlen(const char *s) | |
112 | { | |
113 | register unsigned long r0 asm("0") = 0; | |
114 | const char *tmp = s; | |
115 | ||
94c12cc7 MS |
116 | asm volatile( |
117 | "0: srst %0,%1\n" | |
118 | " jo 0b" | |
7a71fd1c | 119 | : "+d" (r0), "+a" (tmp) : : "cc", "memory"); |
1da177e4 LT |
120 | return r0 - (unsigned long) s; |
121 | } | |
122 | ||
123 | static inline size_t strnlen(const char * s, size_t n) | |
124 | { | |
125 | register int r0 asm("0") = 0; | |
126 | const char *tmp = s; | |
127 | const char *end = s + n; | |
128 | ||
94c12cc7 MS |
129 | asm volatile( |
130 | "0: srst %0,%1\n" | |
131 | " jo 0b" | |
7a71fd1c | 132 | : "+a" (end), "+a" (tmp) : "d" (r0) : "cc", "memory"); |
1da177e4 LT |
133 | return end - s; |
134 | } | |
6faf2507 RR |
135 | #else /* IN_ARCH_STRING_C */ |
136 | void *memchr(const void * s, int c, size_t n); | |
137 | void *memscan(void *s, int c, size_t n); | |
138 | char *strcat(char *dst, const char *src); | |
139 | char *strcpy(char *dst, const char *src); | |
140 | size_t strlen(const char *s); | |
141 | size_t strnlen(const char * s, size_t n); | |
1da177e4 LT |
142 | #endif /* !IN_ARCH_STRING_C */ |
143 | ||
1da177e4 | 144 | #endif /* __S390_STRING_H_ */ |