blob: cc57fad8b7ca7728c28824dbc506357a562b3b8a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * arch/alpha/lib/strncpy.S
4 * Contributed by Richard Henderson (rth@tamu.edu)
5 *
6 * Copy no more than COUNT bytes of the null-terminated string from
7 * SRC to DST. If SRC does not cover all of COUNT, the balance is
8 * zeroed.
9 *
10 * Or, rather, if the kernel cared about that weird ANSI quirk. This
11 * version has cropped that bit o' nastiness as well as assuming that
12 * __stxncpy is in range of a branch.
13 */
Al Viro00fc0e02016-01-11 09:51:29 -050014#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 .set noat
16 .set noreorder
17
18 .text
19
20 .align 4
21 .globl strncpy
22 .ent strncpy
23strncpy:
24 .frame $30, 0, $26
25 .prologue 0
26
27 mov $16, $0 # set return value now
28 beq $18, $zerolen
29 unop
30 bsr $23, __stxncpy # do the work of the copy
31
32 unop
33 bne $18, $multiword # do we have full words left?
34 subq $24, 1, $3 # nope
35 subq $27, 1, $4
36
37 or $3, $24, $3 # clear the bits between the last
38 or $4, $27, $4 # written byte and the last byte in COUNT
Ivan Kokshayskyfe4304b2007-12-17 16:19:48 -080039 andnot $3, $4, $4
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 zap $1, $4, $1
41
42 stq_u $1, 0($16)
43 ret
44
45 .align 4
46$multiword:
Ivan Kokshaysky4d5c34e2006-04-25 13:45:19 +040047 subq $27, 1, $2 # clear the final bits in the prev word
48 or $2, $27, $2
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 zapnot $1, $2, $1
50 subq $18, 1, $18
51
52 stq_u $1, 0($16)
53 addq $16, 8, $16
54 unop
55 beq $18, 1f
56
57 nop
58 unop
59 nop
60 blbc $18, 0f
61
62 stq_u $31, 0($16) # zero one word
63 subq $18, 1, $18
64 addq $16, 8, $16
65 beq $18, 1f
66
670: stq_u $31, 0($16) # zero two words
68 subq $18, 2, $18
69 stq_u $31, 8($16)
70 addq $16, 16, $16
71 bne $18, 0b
72
731: ldq_u $1, 0($16) # clear the leading bits in the final word
Ivan Kokshaysky4d5c34e2006-04-25 13:45:19 +040074 subq $24, 1, $2
75 or $2, $24, $2
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 zap $1, $2, $1
78 stq_u $1, 0($16)
79$zerolen:
80 ret
81
82 .end strncpy
Al Viro00fc0e02016-01-11 09:51:29 -050083 EXPORT_SYMBOL(strncpy)