1/*
2Copyright (c) 2009 Nick Clifton <nickc@redhat.com>
3 */
4	.file	"strncpy.S"
5
6	.section .text
7	.global  _strncpy
8	.type	 _strncpy,@function
9_strncpy:
10#ifdef __RX_DISALLOW_STRING_INSNS__
11	cmp	#0, r3
12	beq	3f
13
14	mov	r1, r4		; Preserve R1 for the return value.
15
162:	mov.b	[r2+], r5	; Copy bytes until...
17	mov.b	r5, [r4+]
18	sub	#1, r3
19	beq	3f		; ... our count reaches zero
20	cmp	#0, r5
21	bne	2b		; ... or we have written a NUL byte
22
234:	mov.b	r5, [r4+]	; Continue to write further NUL bytes
24	sub	#1, r3
25	bne	4b		; until the count reaches zero.
26
273:	rts
28
29#else
30	mov	r1, r4		; Save a copy of the dest pointer.
31	mov	r3, r5		; Save a copy of the byte count
32	smovu	    		; Copy the bytes
33	cmp	#0, r3		; If we have copied the number of bytes requested
34	beq	1f  		;  then skip the next bit:
35	add	r4, r5, r1	; Point to the last byte that we are supposed to write.
36	sub	r3, r1		; Subtract the number of bytes left to be written.
37	mov	#0, r2		; Fill the remaining bytes with NULs,
38	sstr.b
391:
40	mov	r4, r1		; Return the destination pointer
41	rts
42#endif
43	.size _strncpy, . - _strncpy
44
45