blob: 13aaa9927ad124957fbc2329229771c2641b1bd1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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. Hill0131f2b2013-03-25 13:41:18 -05006 * Copyright (C) 1996, 1999 by Ralf Baechle
7 * Copyright (C) 2011 MIPS Technologies, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9#include <linux/errno.h>
10#include <asm/asm.h>
Sam Ravnborg048eb582005-09-09 22:32:31 +020011#include <asm/asm-offsets.h>
Paul Burtond6cb6712016-11-07 11:14:14 +000012#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/regdef.h>
14
15#define EX(insn,reg,addr,handler) \
169: insn reg, addr; \
17 .section __ex_table,"a"; \
Thomas Bogendoerferfa62f392022-01-25 15:19:44 +010018 PTR_WD 9b, handler; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 .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 Baechle70342282013-01-22 12:59:30 +010028 * pointer which wraps into the kernel space. We don't deal with that. If
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * it happens at most some bytes of the exceptions handlers will be copied.
30 */
31
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020032LEAF(__strncpy_from_user_asm)
Steven J. Hill0131f2b2013-03-25 13:41:18 -050033 move t0, zero
34 move v1, a1
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020035#ifdef CONFIG_EVA
36 .set push
37 .set eva
381: EX(lbue, v0, (v1), .Lfault)
39 .set pop
40#else
411: EX(lbu, v0, (v1), .Lfault)
42#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 PTR_ADDIU v1, 1
Thomas Bogendoerfer930bff82007-11-25 11:47:56 +010044 R10KCBARRIER(0(ra))
Maciej W. Rozycki465ca5d62014-04-04 03:32:29 +010045 sb v0, (a0)
Steven J. Hill0131f2b2013-03-25 13:41:18 -050046 beqz v0, 2f
Steven J. Hill0131f2b2013-03-25 13:41:18 -050047 PTR_ADDIU t0, 1
Maciej W. Rozycki465ca5d62014-04-04 03:32:29 +010048 PTR_ADDIU a0, 1
Steven J. Hill0131f2b2013-03-25 13:41:18 -050049 bne t0, a2, 1b
Steven J. Hill0131f2b2013-03-25 13:41:18 -0500502: PTR_ADDU v0, a1, t0
51 xor v0, a1
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020052 bltz v0, .Lfault
Maciej W. Rozycki465ca5d62014-04-04 03:32:29 +010053 move v0, t0
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 jr ra # return n
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020055 END(__strncpy_from_user_asm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020057.Lfault:
Maciej W. Rozycki465ca5d62014-04-04 03:32:29 +010058 li v0, -EFAULT
59 jr ra
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 .section __ex_table,"a"
Thomas Bogendoerferfa62f392022-01-25 15:19:44 +010062 PTR_WD 1b, .Lfault
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .previous
Markos Chandrascc59fe52014-01-02 16:36:49 +000064
Thomas Bogendoerfer04324f42021-04-01 14:56:37 +020065 EXPORT_SYMBOL(__strncpy_from_user_asm)