Import 2.3.9pre5
[davej-history.git] / arch / mips / lib / strncpy_user.S
blob818765e1204ec669e426315938fecd3bb8d7d54d
1 /*
2  * arch/mips/lib/strncpy_user.S
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (c) 1996 by Ralf Baechle
9  *
10  * $Id: strncpy_user.S,v 1.2 1998/05/04 09:12:54 ralf Exp $
11  */
12 #include <linux/errno.h>
13 #include <asm/asm.h>
14 #include <asm/offset.h>
15 #include <asm/regdef.h>
17 #define EX(insn,reg,addr,handler)                       \
18 9:      insn    reg, addr;                              \
19         .section __ex_table,"a";                        \
20         PTR     9b, handler;                            \
21         .previous
24  * Returns: -EFAULT if exception before terminator, N if the entire
25  * buffer filled, else strlen.
26  */
29  * Ugly special case have to check: we might get passed a user space
30  * pointer which wraps into the kernel space.  We don't deal with that.  If
31  * it happens at most some bytes of the exceptions handlers will be copied.
32  */
34 LEAF(__strncpy_from_user_asm)
35         lw      v0, THREAD_CURDS($28)           # pointer ok?
36         subu    v0, zero, v0
37         and     v0, a1
38         nor     v0, zero, v0
39         beqz    v0, fault
40 EXPORT(__strncpy_from_user_nocheck_asm)
41         move            v0,zero
42         move            v1,a1
43         .set            noreorder
44 1:      EX(lbu,  t0, (v1), fault)
45         LONG_ADDIU      v1,1
46         beqz            t0,2f
47          sb             t0,(a0)
48         LONG_ADDIU      v0,1
49         bne             v0,a2,1b
50          LONG_ADDIU     a0,1
51         .set            reorder
52 2:      LONG_ADDU       t0,a1,v0
53         xor             t0,a1
54         bltz            t0,fault
55         jr              ra                      # return n
56         END(__strncpy_from_user_asm)
58 fault:  li              v0,-EFAULT
59         jr              ra
61         .section        __ex_table,"a"
62         PTR             1b,fault
63         .previous