0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <asm/export.h>
0015 .set noat
0016 .set noreorder
0017
0018 .text
0019
0020 .align 4
0021 .globl strncpy
0022 .ent strncpy
0023 strncpy:
0024 .frame $30, 0, $26
0025 .prologue 0
0026
0027 mov $16, $0 # set return value now
0028 beq $18, $zerolen
0029 unop
0030 bsr $23, __stxncpy # do the work of the copy
0031
0032 unop
0033 bne $18, $multiword # do we have full words left?
0034 subq $24, 1, $3 # nope
0035 subq $27, 1, $4
0036
0037 or $3, $24, $3 # clear the bits between the last
0038 or $4, $27, $4 # written byte and the last byte in COUNT
0039 andnot $3, $4, $4
0040 zap $1, $4, $1
0041
0042 stq_u $1, 0($16)
0043 ret
0044
0045 .align 4
0046 $multiword:
0047 subq $27, 1, $2 # clear the final bits in the prev word
0048 or $2, $27, $2
0049 zapnot $1, $2, $1
0050 subq $18, 1, $18
0051
0052 stq_u $1, 0($16)
0053 addq $16, 8, $16
0054 unop
0055 beq $18, 1f
0056
0057 nop
0058 unop
0059 nop
0060 blbc $18, 0f
0061
0062 stq_u $31, 0($16) # zero one word
0063 subq $18, 1, $18
0064 addq $16, 8, $16
0065 beq $18, 1f
0066
0067 0: stq_u $31, 0($16) # zero two words
0068 subq $18, 2, $18
0069 stq_u $31, 8($16)
0070 addq $16, 16, $16
0071 bne $18, 0b
0072
0073 1: ldq_u $1, 0($16) # clear the leading bits in the final word
0074 subq $24, 1, $2
0075 or $2, $24, $2
0076
0077 zap $1, $2, $1
0078 stq_u $1, 0($16)
0079 $zerolen:
0080 ret
0081
0082 .end strncpy
0083 EXPORT_SYMBOL(strncpy)