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> |
Paul Burton | d6cb671 | 2016-11-07 11:14:14 +0000 | [diff] [blame] | 12 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/regdef.h> |
| 14 | |
| 15 | #define EX(insn,reg,addr,handler) \ |
| 16 | 9: insn reg, addr; \ |
| 17 | .section __ex_table,"a"; \ |
| 18 | PTR 9b, handler; \ |
| 19 | .previous |
| 20 | |
| 21 | /* |
| 22 | * Return the size of a string (including the ending 0) |
| 23 | * |
| 24 | * Return 0 for error |
| 25 | */ |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 26 | .macro __BUILD_STRLEN_ASM func |
| 27 | LEAF(__strlen_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok? |
| 29 | and v0, a0 |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 30 | bnez v0, .Lfault\@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | move v0, a0 |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 33 | .ifeqs "\func", "kernel" |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 34 | 1: EX(lbu, v1, (v0), .Lfault\@) |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 35 | .else |
| 36 | 1: EX(lbue, v1, (v0), .Lfault\@) |
| 37 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | PTR_ADDIU v0, 1 |
Steven J. Hill | b1bac37 | 2013-03-25 13:41:47 -0500 | [diff] [blame] | 39 | bnez v1, 1b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | PTR_SUBU v0, a0 |
| 41 | jr ra |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 42 | END(__strlen_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 44 | .Lfault\@: move v0, zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | jr ra |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 46 | .endm |
| 47 | |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 48 | #ifndef CONFIG_EVA |
| 49 | /* Set aliases */ |
| 50 | .global __strlen_user_asm |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 51 | .set __strlen_user_asm, __strlen_kernel_asm |
Arnd Bergmann | b668970 | 2017-01-17 16:18:35 +0100 | [diff] [blame] | 52 | EXPORT_SYMBOL(__strlen_user_asm) |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
| 55 | __BUILD_STRLEN_ASM kernel |
Arnd Bergmann | b668970 | 2017-01-17 16:18:35 +0100 | [diff] [blame] | 56 | EXPORT_SYMBOL(__strlen_kernel_asm) |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 57 | |
| 58 | #ifdef CONFIG_EVA |
| 59 | |
| 60 | .set push |
| 61 | .set eva |
Markos Chandras | 5cc4949 | 2014-01-02 15:55:58 +0000 | [diff] [blame] | 62 | __BUILD_STRLEN_ASM user |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 63 | .set pop |
Arnd Bergmann | b668970 | 2017-01-17 16:18:35 +0100 | [diff] [blame] | 64 | EXPORT_SYMBOL(__strlen_user_asm) |
Markos Chandras | 05397054 | 2014-01-02 16:04:38 +0000 | [diff] [blame] | 65 | #endif |