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> |
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"; \ |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 18 | PTR_WD 9b, handler; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | .previous |
| 20 | |
| 21 | /* |
| 22 | * Returns: -EFAULT if exception before terminator, N if the entire |
| 23 | * buffer filled, else strlen. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * 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] | 28 | * 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] | 29 | * it happens at most some bytes of the exceptions handlers will be copied. |
| 30 | */ |
| 31 | |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 32 | LEAF(__strncpy_from_user_asm) |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 33 | move t0, zero |
| 34 | move v1, a1 |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 35 | #ifdef CONFIG_EVA |
| 36 | .set push |
| 37 | .set eva |
| 38 | 1: EX(lbue, v0, (v1), .Lfault) |
| 39 | .set pop |
| 40 | #else |
| 41 | 1: EX(lbu, v0, (v1), .Lfault) |
| 42 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | PTR_ADDIU v1, 1 |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 44 | R10KCBARRIER(0(ra)) |
Maciej W. Rozycki | 465ca5d6 | 2014-04-04 03:32:29 +0100 | [diff] [blame] | 45 | sb v0, (a0) |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 46 | beqz v0, 2f |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 47 | PTR_ADDIU t0, 1 |
Maciej W. Rozycki | 465ca5d6 | 2014-04-04 03:32:29 +0100 | [diff] [blame] | 48 | PTR_ADDIU a0, 1 |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 49 | bne t0, a2, 1b |
Steven J. Hill | 0131f2b | 2013-03-25 13:41:18 -0500 | [diff] [blame] | 50 | 2: PTR_ADDU v0, a1, t0 |
| 51 | xor v0, a1 |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 52 | bltz v0, .Lfault |
Maciej W. Rozycki | 465ca5d6 | 2014-04-04 03:32:29 +0100 | [diff] [blame] | 53 | move v0, t0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | jr ra # return n |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 55 | END(__strncpy_from_user_asm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 57 | .Lfault: |
Maciej W. Rozycki | 465ca5d6 | 2014-04-04 03:32:29 +0100 | [diff] [blame] | 58 | li v0, -EFAULT |
| 59 | jr ra |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | .section __ex_table,"a" |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 62 | PTR_WD 1b, .Lfault |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .previous |
Markos Chandras | cc59fe5 | 2014-01-02 16:36:49 +0000 | [diff] [blame] | 64 | |
Thomas Bogendoerfer | 04324f4 | 2021-04-01 14:56:37 +0200 | [diff] [blame] | 65 | EXPORT_SYMBOL(__strncpy_from_user_asm) |