strncpy.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * arch/alpha/lib/strncpy.S
  4. * Contributed by Richard Henderson ([email protected])
  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. */
  14. #include <asm/export.h>
  15. .set noat
  16. .set noreorder
  17. .text
  18. .align 4
  19. .globl strncpy
  20. .ent strncpy
  21. strncpy:
  22. .frame $30, 0, $26
  23. .prologue 0
  24. mov $16, $0 # set return value now
  25. beq $18, $zerolen
  26. unop
  27. bsr $23, __stxncpy # do the work of the copy
  28. unop
  29. bne $18, $multiword # do we have full words left?
  30. subq $24, 1, $3 # nope
  31. subq $27, 1, $4
  32. or $3, $24, $3 # clear the bits between the last
  33. or $4, $27, $4 # written byte and the last byte in COUNT
  34. andnot $3, $4, $4
  35. zap $1, $4, $1
  36. stq_u $1, 0($16)
  37. ret
  38. .align 4
  39. $multiword:
  40. subq $27, 1, $2 # clear the final bits in the prev word
  41. or $2, $27, $2
  42. zapnot $1, $2, $1
  43. subq $18, 1, $18
  44. stq_u $1, 0($16)
  45. addq $16, 8, $16
  46. unop
  47. beq $18, 1f
  48. nop
  49. unop
  50. nop
  51. blbc $18, 0f
  52. stq_u $31, 0($16) # zero one word
  53. subq $18, 1, $18
  54. addq $16, 8, $16
  55. beq $18, 1f
  56. 0: stq_u $31, 0($16) # zero two words
  57. subq $18, 2, $18
  58. stq_u $31, 8($16)
  59. addq $16, 16, $16
  60. bne $18, 0b
  61. 1: ldq_u $1, 0($16) # clear the leading bits in the final word
  62. subq $24, 1, $2
  63. or $2, $24, $2
  64. zap $1, $2, $1
  65. stq_u $1, 0($16)
  66. $zerolen:
  67. ret
  68. .end strncpy
  69. EXPORT_SYMBOL(strncpy)