Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1996, 1999 by Ralf Baechle
0007  * Copyright (C) 2011 MIPS Technologies, Inc.
0008  */
0009 #include <linux/errno.h>
0010 #include <asm/asm.h>
0011 #include <asm/asm-offsets.h>
0012 #include <asm/export.h>
0013 #include <asm/regdef.h>
0014 
0015 #define EX(insn,reg,addr,handler)           \
0016 9:  insn    reg, addr;              \
0017     .section __ex_table,"a";            \
0018     PTR_WD  9b, handler;                \
0019     .previous
0020 
0021 /*
0022  * Returns: -EFAULT if exception before terminator, N if the entire
0023  * buffer filled, else strlen.
0024  */
0025 
0026 /*
0027  * Ugly special case have to check: we might get passed a user space
0028  * pointer which wraps into the kernel space.  We don't deal with that.  If
0029  * it happens at most some bytes of the exceptions handlers will be copied.
0030  */
0031 
0032 LEAF(__strncpy_from_user_asm)
0033     move        t0, zero
0034     move        v1, a1
0035 #ifdef CONFIG_EVA
0036     .set push
0037     .set eva
0038 1:  EX(lbue, v0, (v1), .Lfault)
0039     .set pop
0040 #else
0041 1:  EX(lbu, v0, (v1), .Lfault)
0042 #endif
0043     PTR_ADDIU   v1, 1
0044     R10KCBARRIER(0(ra))
0045     sb      v0, (a0)
0046     beqz        v0, 2f
0047     PTR_ADDIU   t0, 1
0048     PTR_ADDIU   a0, 1
0049     bne     t0, a2, 1b
0050 2:  PTR_ADDU    v0, a1, t0
0051     xor     v0, a1
0052     bltz        v0, .Lfault
0053     move        v0, t0
0054     jr      ra          # return n
0055     END(__strncpy_from_user_asm)
0056 
0057 .Lfault:
0058     li      v0, -EFAULT
0059     jr      ra
0060 
0061     .section    __ex_table,"a"
0062     PTR_WD      1b, .Lfault
0063     .previous
0064 
0065     EXPORT_SYMBOL(__strncpy_from_user_asm)