xref: /linux/arch/alpha/lib/strncpy.S (revision b6ebbac51bedf9e98e837688bc838f400196da5e)
1/*
2 * arch/alpha/lib/strncpy.S
3 * Contributed by Richard Henderson (rth@tamu.edu)
4 *
5 * Copy no more than COUNT bytes of the null-terminated string from
6 * SRC to DST.  If SRC does not cover all of COUNT, the balance is
7 * zeroed.
8 *
9 * Or, rather, if the kernel cared about that weird ANSI quirk.  This
10 * version has cropped that bit o' nastiness as well as assuming that
11 * __stxncpy is in range of a branch.
12 */
13
14	.set noat
15	.set noreorder
16
17	.text
18
19	.align 4
20	.globl strncpy
21	.ent strncpy
22strncpy:
23	.frame $30, 0, $26
24	.prologue 0
25
26	mov	$16, $0		# set return value now
27	beq	$18, $zerolen
28	unop
29	bsr	$23, __stxncpy	# do the work of the copy
30
31	unop
32	bne	$18, $multiword	# do we have full words left?
33	subq	$24, 1, $3	# nope
34	subq	$27, 1, $4
35
36	or	$3, $24, $3	# clear the bits between the last
37	or	$4, $27, $4	# written byte and the last byte in COUNT
38	andnot	$3, $4, $4
39	zap	$1, $4, $1
40
41	stq_u	$1, 0($16)
42	ret
43
44	.align	4
45$multiword:
46	subq	$27, 1, $2	# clear the final bits in the prev word
47	or	$2, $27, $2
48	zapnot	$1, $2, $1
49	subq	$18, 1, $18
50
51	stq_u	$1, 0($16)
52	addq	$16, 8, $16
53	unop
54	beq	$18, 1f
55
56	nop
57	unop
58	nop
59	blbc	$18, 0f
60
61	stq_u	$31, 0($16)	# zero one word
62	subq	$18, 1, $18
63	addq	$16, 8, $16
64	beq	$18, 1f
65
660:	stq_u	$31, 0($16)	# zero two words
67	subq	$18, 2, $18
68	stq_u	$31, 8($16)
69	addq	$16, 16, $16
70	bne	$18, 0b
71
721:	ldq_u	$1, 0($16)	# clear the leading bits in the final word
73	subq	$24, 1, $2
74	or	$2, $24, $2
75
76	zap	$1, $2, $1
77	stq_u	$1, 0($16)
78$zerolen:
79	ret
80
81	.end	strncpy
82