]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/mips/lib/strncpy_user.S
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
[karo-tx-linux.git] / arch / mips / lib / strncpy_user.S
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  *
6  * Copyright (C) 1996, 1999 by Ralf Baechle
7  * Copyright (C) 2011 MIPS Technologies, Inc.
8  */
9 #include <linux/errno.h>
10 #include <asm/asm.h>
11 #include <asm/asm-offsets.h>
12 #include <asm/export.h>
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  * 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
28  * pointer which wraps into the kernel space.  We don't deal with that.  If
29  * it happens at most some bytes of the exceptions handlers will be copied.
30  */
31
32         .macro __BUILD_STRNCPY_ASM func
33 LEAF(__strncpy_from_\func\()_asm)
34         LONG_L          v0, TI_ADDR_LIMIT($28)  # pointer ok?
35         and             v0, a1
36         bnez            v0, .Lfault\@
37
38 FEXPORT(__strncpy_from_\func\()_nocheck_asm)
39         move            t0, zero
40         move            v1, a1
41 .ifeqs "\func","kernel"
42 1:      EX(lbu, v0, (v1), .Lfault\@)
43 .else
44 1:      EX(lbue, v0, (v1), .Lfault\@)
45 .endif
46         PTR_ADDIU       v1, 1
47         R10KCBARRIER(0(ra))
48         sb              v0, (a0)
49         beqz            v0, 2f
50         PTR_ADDIU       t0, 1
51         PTR_ADDIU       a0, 1
52         bne             t0, a2, 1b
53 2:      PTR_ADDU        v0, a1, t0
54         xor             v0, a1
55         bltz            v0, .Lfault\@
56         move            v0, t0
57         jr              ra                      # return n
58         END(__strncpy_from_\func\()_asm)
59
60 .Lfault\@:
61         li              v0, -EFAULT
62         jr              ra
63
64         .section        __ex_table,"a"
65         PTR             1b, .Lfault\@
66         .previous
67
68         .endm
69
70 #ifndef CONFIG_EVA
71         /* Set aliases */
72         .global __strncpy_from_user_asm
73         .global __strncpy_from_user_nocheck_asm
74         .set __strncpy_from_user_asm, __strncpy_from_kernel_asm
75         .set __strncpy_from_user_nocheck_asm, __strncpy_from_kernel_nocheck_asm
76 EXPORT_SYMBOL(__strncpy_from_user_asm)
77 EXPORT_SYMBOL(__strncpy_from_user_nocheck_asm)
78 #endif
79
80 __BUILD_STRNCPY_ASM kernel
81 EXPORT_SYMBOL(__strncpy_from_kernel_asm)
82 EXPORT_SYMBOL(__strncpy_from_kernel_nocheck_asm)
83
84 #ifdef CONFIG_EVA
85         .set push
86         .set eva
87 __BUILD_STRNCPY_ASM user
88         .set pop
89 EXPORT_SYMBOL(__strncpy_from_user_asm)
90 EXPORT_SYMBOL(__strncpy_from_user_nocheck_asm)
91 #endif