]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | * | |
0131f2b2 SH |
6 | * Copyright (C) 1996, 1999 by Ralf Baechle |
7 | * Copyright (C) 2011 MIPS Technologies, Inc. | |
1da177e4 LT |
8 | */ |
9 | #include <linux/errno.h> | |
10 | #include <asm/asm.h> | |
048eb582 | 11 | #include <asm/asm-offsets.h> |
d6cb6715 | 12 | #include <asm/export.h> |
1da177e4 LT |
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 | |
70342287 | 28 | * pointer which wraps into the kernel space. We don't deal with that. If |
1da177e4 LT |
29 | * it happens at most some bytes of the exceptions handlers will be copied. |
30 | */ | |
31 | ||
cc59fe5b MC |
32 | .macro __BUILD_STRNCPY_ASM func |
33 | LEAF(__strncpy_from_\func\()_asm) | |
1da177e4 LT |
34 | LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok? |
35 | and v0, a1 | |
cc59fe5b | 36 | bnez v0, .Lfault\@ |
1da177e4 | 37 | |
0131f2b2 SH |
38 | move t0, zero |
39 | move v1, a1 | |
b3c3025b | 40 | .ifeqs "\func","kernel" |
cc59fe5b | 41 | 1: EX(lbu, v0, (v1), .Lfault\@) |
b3c3025b MC |
42 | .else |
43 | 1: EX(lbue, v0, (v1), .Lfault\@) | |
44 | .endif | |
1da177e4 | 45 | PTR_ADDIU v1, 1 |
930bff88 | 46 | R10KCBARRIER(0(ra)) |
465ca5d6 | 47 | sb v0, (a0) |
0131f2b2 | 48 | beqz v0, 2f |
0131f2b2 | 49 | PTR_ADDIU t0, 1 |
465ca5d6 | 50 | PTR_ADDIU a0, 1 |
0131f2b2 | 51 | bne t0, a2, 1b |
0131f2b2 SH |
52 | 2: PTR_ADDU v0, a1, t0 |
53 | xor v0, a1 | |
cc59fe5b | 54 | bltz v0, .Lfault\@ |
465ca5d6 | 55 | move v0, t0 |
1da177e4 | 56 | jr ra # return n |
cc59fe5b | 57 | END(__strncpy_from_\func\()_asm) |
1da177e4 | 58 | |
465ca5d6 MR |
59 | .Lfault\@: |
60 | li v0, -EFAULT | |
61 | jr ra | |
1da177e4 LT |
62 | |
63 | .section __ex_table,"a" | |
cc59fe5b | 64 | PTR 1b, .Lfault\@ |
1da177e4 | 65 | .previous |
cc59fe5b MC |
66 | |
67 | .endm | |
68 | ||
b3c3025b MC |
69 | #ifndef CONFIG_EVA |
70 | /* Set aliases */ | |
71 | .global __strncpy_from_user_asm | |
b3c3025b | 72 | .set __strncpy_from_user_asm, __strncpy_from_kernel_asm |
b668970e | 73 | EXPORT_SYMBOL(__strncpy_from_user_asm) |
b3c3025b MC |
74 | #endif |
75 | ||
76 | __BUILD_STRNCPY_ASM kernel | |
b668970e | 77 | EXPORT_SYMBOL(__strncpy_from_kernel_asm) |
b3c3025b MC |
78 | |
79 | #ifdef CONFIG_EVA | |
80 | .set push | |
81 | .set eva | |
cc59fe5b | 82 | __BUILD_STRNCPY_ASM user |
b3c3025b | 83 | .set pop |
b668970e | 84 | EXPORT_SYMBOL(__strncpy_from_user_asm) |
b3c3025b | 85 | #endif |