Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Steven J. Hill | b1bac37 | 2013-03-25 13:41:47 -0500 | [diff] [blame] | 6 | * Copyright (C) 1996, 1998, 1999, 2004 by Ralf Baechle |
| 7 | * Copyright (C) 1999 Silicon Graphics, Inc. |
| 8 | * Copyright (C) 2011 MIPS Technologies, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | #include <asm/asm.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 11 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/regdef.h> |
| 13 | |
| 14 | #define EX(insn,reg,addr,handler) \ |
| 15 | 9: insn reg, addr; \ |
| 16 | .section __ex_table,"a"; \ |
| 17 | PTR 9b, handler; \ |
| 18 | .previous |
| 19 | |
| 20 | /* |
| 21 | * Return the size of a string (including the ending 0) |
| 22 | * |
| 23 | * Return 0 for error |
| 24 | */ |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 25 | .macro __BUILD_STRLEN_ASM func |
| 26 | LEAF(__strlen_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok? |
| 28 | and v0, a0 |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 29 | bnez v0, .Lfault\@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | move v0, a0 |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 32 | .ifeqs "\func", "kernel" |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 33 | 1: EX(lbu, v1, (v0), .Lfault\@) |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 34 | .else |
| 35 | 1: EX(lbue, v1, (v0), .Lfault\@) |
| 36 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | PTR_ADDIU v0, 1 |
Steven J. Hill | b1bac37 | 2013-03-25 13:41:47 -0500 | [diff] [blame] | 38 | bnez v1, 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | PTR_SUBU v0, a0 |
| 40 | jr ra |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 41 | END(__strlen_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 43 | .Lfault\@: move v0, zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | jr ra |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 45 | .endm |
| 46 | |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 47 | #ifndef CONFIG_EVA |
| 48 | /* Set aliases */ |
| 49 | .global __strlen_user_asm |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 50 | .set __strlen_user_asm, __strlen_kernel_asm |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | __BUILD_STRLEN_ASM kernel |
| 54 | |
| 55 | #ifdef CONFIG_EVA |
| 56 | |
| 57 | .set push |
| 58 | .set eva |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 59 | __BUILD_STRLEN_ASM user |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 60 | .set pop |
| 61 | #endif |