1/*
2 * linux/arch/unicore32/lib/strncpy_from_user.S
3 *
4 * Code specific to PKUnity SoC and UniCore ISA
5 *
6 * Copyright (C) 2001-2010 GUAN Xue-tao
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/linkage.h>
13#include <asm/assembler.h>
14#include <asm/errno.h>
15
16	.text
17	.align	5
18
19/*
20 * Copy a string from user space to kernel space.
21 *  r0 = dst, r1 = src, r2 = byte length
22 * returns the number of characters copied (strlen of copied string),
23 *  -EFAULT on exception, or "len" if we fill the whole buffer
24 */
25ENTRY(__strncpy_from_user)
26	mov	ip, r1
271:	sub.a	r2, r2, #1
28	ldrusr	r3, r1, 1, ns
29	bfs	2f
30	stb.w	r3, [r0]+, #1
31	cxor.a	r3, #0
32	bne	1b
33	sub	r1, r1, #1	@ take NUL character out of count
342:	sub	r0, r1, ip
35	mov	pc, lr
36ENDPROC(__strncpy_from_user)
37
38	.pushsection .fixup,"ax"
39	.align	0
409001:	mov	r3, #0
41	stb	r3, [r0+], #0	@ null terminate
42	mov	r0, #-EFAULT
43	mov	pc, lr
44	.popsection
45
46