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> |
1da177e4 LT |
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 | |
70342287 | 27 | * pointer which wraps into the kernel space. We don't deal with that. If |
1da177e4 LT |
28 | * it happens at most some bytes of the exceptions handlers will be copied. |
29 | */ | |
30 | ||
cc59fe5b MC |
31 | .macro __BUILD_STRNCPY_ASM func |
32 | LEAF(__strncpy_from_\func\()_asm) | |
1da177e4 LT |
33 | LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok? |
34 | and v0, a1 | |
cc59fe5b | 35 | bnez v0, .Lfault\@ |
1da177e4 | 36 | |
cc59fe5b | 37 | FEXPORT(__strncpy_from_\func\()_nocheck_asm) |
1da177e4 | 38 | .set noreorder |
0131f2b2 SH |
39 | move t0, zero |
40 | move v1, a1 | |
b3c3025b | 41 | .ifeqs "\func","kernel" |
cc59fe5b | 42 | 1: EX(lbu, v0, (v1), .Lfault\@) |
b3c3025b MC |
43 | .else |
44 | 1: EX(lbue, v0, (v1), .Lfault\@) | |
45 | .endif | |
1da177e4 | 46 | PTR_ADDIU v1, 1 |
930bff88 | 47 | R10KCBARRIER(0(ra)) |
0131f2b2 SH |
48 | beqz v0, 2f |
49 | sb v0, (a0) | |
50 | PTR_ADDIU t0, 1 | |
51 | bne t0, a2, 1b | |
52 | PTR_ADDIU a0, 1 | |
53 | 2: PTR_ADDU v0, a1, t0 | |
54 | xor v0, a1 | |
cc59fe5b | 55 | bltz v0, .Lfault\@ |
0131f2b2 | 56 | nop |
1da177e4 | 57 | jr ra # return n |
0131f2b2 | 58 | move v0, t0 |
cc59fe5b | 59 | END(__strncpy_from_\func\()_asm) |
1da177e4 | 60 | |
cc59fe5b | 61 | .Lfault\@: jr ra |
0131f2b2 | 62 | li v0, -EFAULT |
1da177e4 LT |
63 | |
64 | .section __ex_table,"a" | |
cc59fe5b | 65 | PTR 1b, .Lfault\@ |
1da177e4 | 66 | .previous |
cc59fe5b MC |
67 | |
68 | .endm | |
69 | ||
b3c3025b MC |
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 | #endif | |
77 | ||
78 | __BUILD_STRNCPY_ASM kernel | |
79 | ||
80 | #ifdef CONFIG_EVA | |
81 | .set push | |
82 | .set eva | |
cc59fe5b | 83 | __BUILD_STRNCPY_ASM user |
b3c3025b MC |
84 | .set pop |
85 | #endif |