1/* strncpy_from_user.S: Sparc strncpy from userspace.
2 *
3 *  Copyright(C) 1996 David S. Miller
4 */
5
6#include <asm/ptrace.h>
7#include <asm/errno.h>
8
9	.text
10	.align	4
11
12	/* Must return:
13	 *
14	 * -EFAULT		for an exception
15	 * count		if we hit the buffer limit
16	 * bytes copied		if we hit a null byte
17	 */
18
19	.globl	__strncpy_from_user
20__strncpy_from_user:
21	/* %o0=dest, %o1=src, %o2=count */
22	mov	%o2, %o3
231:
24	subcc	%o2, 1, %o2
25	bneg	2f
26	 nop
2710:
28	ldub	[%o1], %o4
29	add	%o0, 1, %o0
30	cmp	%o4, 0
31	add	%o1, 1, %o1
32	bne	1b
33	 stb	%o4, [%o0 - 1]
342:
35	add	%o2, 1, %o0
36	retl
37	 sub	%o3, %o0, %o0
38
39	.section .fixup,#alloc,#execinstr
40	.align	4
414:
42	retl
43	 mov	-EFAULT, %o0
44
45	.section __ex_table,#alloc
46	.align	4
47	.word	10b, 4b
48