/* SPDX-License-Identifier: GPL-2.0 */1/*2* arch/alpha/lib/strncpy.S3* Contributed by Richard Henderson ([email protected])4*5* Copy no more than COUNT bytes of the null-terminated string from6* SRC to DST. If SRC does not cover all of COUNT, the balance is7* zeroed.8*9* Or, rather, if the kernel cared about that weird ANSI quirk. This10* version has cropped that bit o' nastiness as well as assuming that11* __stxncpy is in range of a branch.12*/13#include <linux/export.h>14.set noat15.set noreorder1617.text1819.align 420.globl strncpy21.ent strncpy22strncpy:23.frame $30, 0, $2624.prologue 02526mov $16, $0 # set return value now27beq $18, $zerolen28unop29bsr $23, __stxncpy # do the work of the copy3031unop32bne $18, $multiword # do we have full words left?33subq $24, 1, $3 # nope34subq $27, 1, $43536or $3, $24, $3 # clear the bits between the last37or $4, $27, $4 # written byte and the last byte in COUNT38andnot $3, $4, $439zap $1, $4, $14041stq_u $1, 0($16)42ret4344.align 445$multiword:46subq $27, 1, $2 # clear the final bits in the prev word47or $2, $27, $248zapnot $1, $2, $149subq $18, 1, $185051stq_u $1, 0($16)52addq $16, 8, $1653unop54beq $18, 1f5556nop57unop58nop59blbc $18, 0f6061stq_u $31, 0($16) # zero one word62subq $18, 1, $1863addq $16, 8, $1664beq $18, 1f65660: stq_u $31, 0($16) # zero two words67subq $18, 2, $1868stq_u $31, 8($16)69addq $16, 16, $1670bne $18, 0b71721: ldq_u $1, 0($16) # clear the leading bits in the final word73subq $24, 1, $274or $2, $24, $27576zap $1, $2, $177stq_u $1, 0($16)78$zerolen:79ret8081.end strncpy82EXPORT_SYMBOL(strncpy)838485