| 1 | |
| 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 ([email protected]),
|
| 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
|
| 19 | #define __HAVE_ARCH_MEMCMP
|
| 20 | #define __HAVE_ARCH_MEMCPY
|
| 21 | #define __HAVE_ARCH_MEMSCAN
|
| 22 | #define __HAVE_ARCH_MEMSET
|
| 23 | #define __HAVE_ARCH_STRCAT
|
| 24 | #define __HAVE_ARCH_STRCMP
|
| 25 | #define __HAVE_ARCH_STRCPY
|
| 26 | #define __HAVE_ARCH_STRLCAT
|
| 27 | #define __HAVE_ARCH_STRLCPY
|
| 28 | #define __HAVE_ARCH_STRLEN
|
| 29 | #define __HAVE_ARCH_STRNCAT
|
| 30 | #define __HAVE_ARCH_STRNCPY
|
| 31 | #define __HAVE_ARCH_STRNLEN
|
| 32 | #define __HAVE_ARCH_STRRCHR
|
| 33 | #define __HAVE_ARCH_STRSTR
|
| 34 |
|
| 35 |
|
| 36 | extern int memcmp(const void *, const void *, size_t);
|
| 37 | extern void *memcpy(void *, const void *, size_t);
|
| 38 | extern void *memset(void *, int, size_t);
|
| 39 | extern int strcmp(const char *,const char *);
|
| 40 | extern size_t strlcat(char *, const char *, size_t);
|
| 41 | extern size_t strlcpy(char *, const char *, size_t);
|
| 42 | extern char *strncat(char *, const char *, size_t);
|
| 43 | extern char *strncpy(char *, const char *, size_t);
|
| 44 | extern char *strrchr(const char *, int);
|
| 45 | extern 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 |
|
| 58 | static 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 |
|
| 63 | 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");
|
| 70 | return (void *) ret;
|
| 71 | }
|
| 72 |
|
| 73 | static 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 |
|
| 78 | asm volatile(
|
| 79 | "0: srst %0,%1\n"
|
| 80 | " jo 0b\n"
|
| 81 | : "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
|
| 82 | return (void *) ret;
|
| 83 | }
|
| 84 |
|
| 85 | static 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 |
|
| 91 | 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" );
|
| 98 | return ret;
|
| 99 | }
|
| 100 |
|
| 101 | static inline char *strcpy(char *dst, const char *src)
|
| 102 | {
|
| 103 | register int r0 asm("0") = 0;
|
| 104 | char *ret = dst;
|
| 105 |
|
| 106 | asm volatile(
|
| 107 | "0: mvst %0,%1\n"
|
| 108 | " jo 0b"
|
| 109 | : "+&a" (dst), "+&a" (src) : "d" (r0)
|
| 110 | : "cc", "memory");
|
| 111 | return ret;
|
| 112 | }
|
| 113 |
|
| 114 | static inline size_t strlen(const char *s)
|
| 115 | {
|
| 116 | register unsigned long r0 asm("0") = 0;
|
| 117 | const char *tmp = s;
|
| 118 |
|
| 119 | asm volatile(
|
| 120 | "0: srst %0,%1\n"
|
| 121 | " jo 0b"
|
| 122 | : "+d" (r0), "+a" (tmp) : : "cc");
|
| 123 | return r0 - (unsigned long) s;
|
| 124 | }
|
| 125 |
|
| 126 | static inline size_t strnlen(const char * s, size_t n)
|
| 127 | {
|
| 128 | register int r0 asm("0") = 0;
|
| 129 | const char *tmp = s;
|
| 130 | const char *end = s + n;
|
| 131 |
|
| 132 | asm volatile(
|
| 133 | "0: srst %0,%1\n"
|
| 134 | " jo 0b"
|
| 135 | : "+a" (end), "+a" (tmp) : "d" (r0) : "cc");
|
| 136 | return end - s;
|
| 137 | }
|
| 138 |
|
| 139 | #endif
|
| 140 |
|
| 141 | #endif
|
| 142 |
|
| 143 | #endif
|