Loading...
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 */
8#include <linux/errno.h>
9#include <asm/asm.h>
10#include <asm/asm-offsets.h>
11#include <asm/regdef.h>
12
13#define EX(insn,reg,addr,handler) \
149: insn reg, addr; \
15 .section __ex_table,"a"; \
16 PTR 9b, handler; \
17 .previous
18
19/*
20 * Returns: -EFAULT if exception before terminator, N if the entire
21 * buffer filled, else strlen.
22 */
23
24/*
25 * Ugly special case have to check: we might get passed a user space
26 * pointer which wraps into the kernel space. We don't deal with that. If
27 * it happens at most some bytes of the exceptions handlers will be copied.
28 */
29
30LEAF(__strncpy_from_user_asm)
31 LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
32 and v0, a1
33 bnez v0, .Lfault
34
35FEXPORT(__strncpy_from_user_nocheck_asm)
36 move v0, zero
37 move v1, a1
38 .set noreorder
391: EX(lbu, t0, (v1), .Lfault)
40 PTR_ADDIU v1, 1
41 R10KCBARRIER(0(ra))
42 beqz t0, 2f
43 sb t0, (a0)
44 PTR_ADDIU v0, 1
45 .set reorder
46 PTR_ADDIU a0, 1
47 bne v0, a2, 1b
482: PTR_ADDU t0, a1, v0
49 xor t0, a1
50 bltz t0, .Lfault
51 jr ra # return n
52 END(__strncpy_from_user_asm)
53
54.Lfault: li v0, -EFAULT
55 jr ra
56
57 .section __ex_table,"a"
58 PTR 1b, .Lfault
59 .previous
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) \
169: 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
33LEAF(__strncpy_from_\func\()_asm)
34 LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
35 and v0, a1
36 bnez v0, .Lfault\@
37
38 move t0, zero
39 move v1, a1
40.ifeqs "\func","kernel"
411: EX(lbu, v0, (v1), .Lfault\@)
42.else
431: EX(lbue, v0, (v1), .Lfault\@)
44.endif
45 PTR_ADDIU v1, 1
46 R10KCBARRIER(0(ra))
47 sb v0, (a0)
48 beqz v0, 2f
49 PTR_ADDIU t0, 1
50 PTR_ADDIU a0, 1
51 bne t0, a2, 1b
522: PTR_ADDU v0, a1, t0
53 xor v0, a1
54 bltz v0, .Lfault\@
55 move v0, t0
56 jr ra # return n
57 END(__strncpy_from_\func\()_asm)
58
59.Lfault\@:
60 li v0, -EFAULT
61 jr ra
62
63 .section __ex_table,"a"
64 PTR 1b, .Lfault\@
65 .previous
66
67 .endm
68
69#ifndef CONFIG_EVA
70 /* Set aliases */
71 .global __strncpy_from_user_asm
72 .set __strncpy_from_user_asm, __strncpy_from_kernel_asm
73EXPORT_SYMBOL(__strncpy_from_user_asm)
74#endif
75
76__BUILD_STRNCPY_ASM kernel
77EXPORT_SYMBOL(__strncpy_from_kernel_asm)
78
79#ifdef CONFIG_EVA
80 .set push
81 .set eva
82__BUILD_STRNCPY_ASM user
83 .set pop
84EXPORT_SYMBOL(__strncpy_from_user_asm)
85#endif