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 | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 6 | * Copyright (C) 1996, 1999 by Ralf Baechle |
| 7 | * Copyright (C) 2011 MIPS Technologies, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | #include <linux/errno.h> |
| 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 | * Returns: -EFAULT if exception before terminator, N if the entire |
| 22 | * buffer filled, else strlen. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * Ugly special case have to check: we might get passed a user space |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 27 | * pointer which wraps into the kernel space. We don't deal with that. If |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * it happens at most some bytes of the exceptions handlers will be copied. |
| 29 | */ |
| 30 | |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 31 | .macro __BUILD_STRNCPY_ASM func |
| 32 | LEAF(__strncpy_from_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok? |
| 34 | and v0, a1 |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 35 | bnez v0, .Lfault\@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 37 | FEXPORT(__strncpy_from_\func\()_nocheck_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | .set noreorder |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 39 | move t0, zero |
| 40 | move v1, a1 |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 41 | 1: EX(lbu, v0, (v1), .Lfault\@) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | PTR_ADDIU v1, 1 |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 43 | R10KCBARRIER(0(ra)) |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 44 | beqz v0, 2f |
| 45 | sb v0, (a0) |
| 46 | PTR_ADDIU t0, 1 |
| 47 | bne t0, a2, 1b |
| 48 | PTR_ADDIU a0, 1 |
| 49 | 2: PTR_ADDU v0, a1, t0 |
| 50 | xor v0, a1 |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 51 | bltz v0, .Lfault\@ |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 52 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | jr ra # return n |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 54 | move v0, t0 |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 55 | END(__strncpy_from_\func\()_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 57 | .Lfault\@: jr ra |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 58 | li v0, -EFAULT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | .section __ex_table,"a" |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 61 | PTR 1b, .Lfault\@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .previous |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame^] | 63 | |
| 64 | .endm |
| 65 | |
| 66 | __BUILD_STRNCPY_ASM user |