/* SPDX-License-Identifier: GPL-2.0 */1/*2* arch/alpha/lib/ev67-strncat.S3* 21264 version contributed by Rick Gorton <[email protected]>4*5* Append no more than COUNT characters from the null-terminated string SRC6* to the null-terminated string DST. Always null-terminate the new DST.7*8* This differs slightly from the semantics in libc in that we never write9* past count, whereas libc may write to count+1. This follows the generic10* implementation in lib/string.c and is, IMHO, more sensible.11*12* Much of the information about 21264 scheduling/coding comes from:13* Compiler Writer's Guide for the Alpha 2126414* abbreviated as 'CWG' in other comments here15* ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html16* Scheduling notation:17* E - either cluster18* U - upper subcluster; U0 - subcluster U0; U1 - subcluster U119* L - lower subcluster; L0 - subcluster L0; L1 - subcluster L120* Try not to change the actual algorithm if possible for consistency.21*/2223#include <linux/export.h>24.text2526.align 427.globl strncat28.ent strncat29strncat:30.frame $30, 0, $2631.prologue 03233mov $16, $0 # set up return value34beq $18, $zerocount # U :35/* Find the end of the string. */36ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned)37lda $2, -1($31) # E :3839insqh $2, $0, $2 # U :40andnot $16, 7, $16 # E :41nop # E :42or $2, $1, $1 # E :4344nop # E :45nop # E :46cmpbge $31, $1, $2 # E : bits set iff byte == 047bne $2, $found # U :4849$loop: ldq $1, 8($16) # L :50addq $16, 8, $16 # E :51cmpbge $31, $1, $2 # E :52beq $2, $loop # U :5354$found: cttz $2, $3 # U0 :55addq $16, $3, $16 # E :56nop # E :57bsr $23, __stxncpy # L0 :/* Now do the append. */5859/* Worry about the null termination. */6061zapnot $1, $27, $2 # U : was last byte a null?62cmplt $27, $24, $5 # E : did we fill the buffer completely?63bne $2, 0f # U :64ret # L0 :65660: or $5, $18, $2 # E :67nop68bne $2, 2f # U :69and $24, 0x80, $3 # E : no zero next byte7071nop # E :72bne $3, 1f # U :73/* Here there are bytes left in the current word. Clear one. */74addq $24, $24, $24 # E : end-of-count bit <<= 175nop # E :76772: zap $1, $24, $1 # U :78nop # E :79stq_u $1, 0($16) # L :80ret # L0 :81821: /* Here we must clear the first byte of the next DST word */83stb $31, 8($16) # L :84nop # E :85nop # E :86ret # L0 :8788$zerocount:89nop # E :90nop # E :91nop # E :92ret # L0 :9394.end strncat95EXPORT_SYMBOL(strncat)969798