wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 1 | /* $Id: string.h,v 1.13 2000/02/19 14:12:14 harald Exp $ |
| 2 | * |
| 3 | * This file is subject to the terms and conditions of the GNU General Public |
| 4 | * License. See the file "COPYING" in the main directory of this archive |
| 5 | * for more details. |
| 6 | * |
| 7 | * Copyright (c) 1994, 1995, 1996, 1997, 1998 by Ralf Baechle |
| 8 | */ |
| 9 | #ifndef __ASM_MIPS_STRING_H |
| 10 | #define __ASM_MIPS_STRING_H |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | |
| 14 | #define __HAVE_ARCH_STRCPY |
| 15 | extern __inline__ char *strcpy(char *__dest, __const__ char *__src) |
| 16 | { |
| 17 | char *__xdest = __dest; |
| 18 | |
| 19 | __asm__ __volatile__( |
| 20 | ".set\tnoreorder\n\t" |
| 21 | ".set\tnoat\n" |
| 22 | "1:\tlbu\t$1,(%1)\n\t" |
| 23 | "addiu\t%1,1\n\t" |
| 24 | "sb\t$1,(%0)\n\t" |
| 25 | "bnez\t$1,1b\n\t" |
| 26 | "addiu\t%0,1\n\t" |
| 27 | ".set\tat\n\t" |
| 28 | ".set\treorder" |
| 29 | : "=r" (__dest), "=r" (__src) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | : "0" (__dest), "1" (__src) |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 31 | : "$1","memory"); |
| 32 | |
| 33 | return __xdest; |
| 34 | } |
| 35 | |
| 36 | #define __HAVE_ARCH_STRNCPY |
| 37 | extern __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n) |
| 38 | { |
| 39 | char *__xdest = __dest; |
| 40 | |
| 41 | if (__n == 0) |
| 42 | return __xdest; |
| 43 | |
| 44 | __asm__ __volatile__( |
| 45 | ".set\tnoreorder\n\t" |
| 46 | ".set\tnoat\n" |
| 47 | "1:\tlbu\t$1,(%1)\n\t" |
| 48 | "subu\t%2,1\n\t" |
| 49 | "sb\t$1,(%0)\n\t" |
| 50 | "beqz\t$1,2f\n\t" |
| 51 | "addiu\t%0,1\n\t" |
| 52 | "bnez\t%2,1b\n\t" |
| 53 | "addiu\t%1,1\n" |
| 54 | "2:\n\t" |
| 55 | ".set\tat\n\t" |
| 56 | ".set\treorder" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | : "=r" (__dest), "=r" (__src), "=r" (__n) |
| 58 | : "0" (__dest), "1" (__src), "2" (__n) |
| 59 | : "$1","memory"); |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 60 | |
| 61 | return __dest; |
| 62 | } |
| 63 | |
| 64 | #define __HAVE_ARCH_STRCMP |
| 65 | extern __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct) |
| 66 | { |
| 67 | int __res; |
| 68 | |
| 69 | __asm__ __volatile__( |
| 70 | ".set\tnoreorder\n\t" |
| 71 | ".set\tnoat\n\t" |
| 72 | "lbu\t%2,(%0)\n" |
| 73 | "1:\tlbu\t$1,(%1)\n\t" |
| 74 | "addiu\t%0,1\n\t" |
| 75 | "bne\t$1,%2,2f\n\t" |
| 76 | "addiu\t%1,1\n\t" |
| 77 | "bnez\t%2,1b\n\t" |
| 78 | "lbu\t%2,(%0)\n\t" |
| 79 | #if defined(CONFIG_CPU_R3000) |
| 80 | "nop\n\t" |
| 81 | #endif |
| 82 | "move\t%2,$1\n" |
| 83 | "2:\tsubu\t%2,$1\n" |
| 84 | "3:\t.set\tat\n\t" |
| 85 | ".set\treorder" |
| 86 | : "=r" (__cs), "=r" (__ct), "=r" (__res) |
| 87 | : "0" (__cs), "1" (__ct) |
| 88 | : "$1"); |
| 89 | |
| 90 | return __res; |
| 91 | } |
| 92 | |
| 93 | #define __HAVE_ARCH_STRNCMP |
| 94 | extern __inline__ int |
| 95 | strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count) |
| 96 | { |
| 97 | int __res; |
| 98 | |
| 99 | __asm__ __volatile__( |
| 100 | ".set\tnoreorder\n\t" |
| 101 | ".set\tnoat\n" |
| 102 | "1:\tlbu\t%3,(%0)\n\t" |
| 103 | "beqz\t%2,2f\n\t" |
| 104 | "lbu\t$1,(%1)\n\t" |
| 105 | "subu\t%2,1\n\t" |
| 106 | "bne\t$1,%3,3f\n\t" |
| 107 | "addiu\t%0,1\n\t" |
| 108 | "bnez\t%3,1b\n\t" |
| 109 | "addiu\t%1,1\n" |
| 110 | "2:\n\t" |
| 111 | #if defined(CONFIG_CPU_R3000) |
| 112 | "nop\n\t" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 113 | #endif |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 114 | "move\t%3,$1\n" |
| 115 | "3:\tsubu\t%3,$1\n\t" |
| 116 | ".set\tat\n\t" |
| 117 | ".set\treorder" |
| 118 | : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res) |
| 119 | : "0" (__cs), "1" (__ct), "2" (__count) |
| 120 | : "$1"); |
| 121 | |
| 122 | return __res; |
| 123 | } |
| 124 | |
| 125 | #undef __HAVE_ARCH_MEMSET |
| 126 | extern void *memset(void *__s, int __c, size_t __count); |
| 127 | |
| 128 | #undef __HAVE_ARCH_MEMCPY |
| 129 | extern void *memcpy(void *__to, __const__ void *__from, size_t __n); |
| 130 | |
| 131 | #undef __HAVE_ARCH_MEMMOVE |
| 132 | extern void *memmove(void *__dest, __const__ void *__src, size_t __n); |
| 133 | |
| 134 | /* Don't build bcopy at all ... */ |
| 135 | #define __HAVE_ARCH_BCOPY |
| 136 | |
| 137 | #define __HAVE_ARCH_MEMSCAN |
| 138 | extern __inline__ void *memscan(void *__addr, int __c, size_t __size) |
| 139 | { |
| 140 | char *__end = (char *)__addr + __size; |
| 141 | |
| 142 | __asm__(".set\tpush\n\t" |
| 143 | ".set\tnoat\n\t" |
| 144 | ".set\treorder\n\t" |
| 145 | "1:\tbeq\t%0,%1,2f\n\t" |
| 146 | "addiu\t%0,1\n\t" |
| 147 | "lb\t$1,-1(%0)\n\t" |
| 148 | "bne\t$1,%4,1b\n" |
| 149 | "2:\t.set\tpop" |
| 150 | : "=r" (__addr), "=r" (__end) |
| 151 | : "0" (__addr), "1" (__end), "r" (__c) |
| 152 | : "$1"); |
| 153 | |
| 154 | return __addr; |
| 155 | } |
| 156 | |
| 157 | #endif /* __ASM_MIPS_STRING_H */ |