strncpy.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * arch/alpha/lib/strncpy.S
  3. * Contributed by Richard Henderson (rth@tamu.edu)
  4. *
  5. * Copy no more than COUNT bytes of the null-terminated string from
  6. * SRC to DST. If SRC does not cover all of COUNT, the balance is
  7. * zeroed.
  8. *
  9. * Or, rather, if the kernel cared about that weird ANSI quirk. This
  10. * version has cropped that bit o' nastiness as well as assuming that
  11. * __stxncpy is in range of a branch.
  12. */
  13. #include <asm/export.h>
  14. .set noat
  15. .set noreorder
  16. .text
  17. .align 4
  18. .globl strncpy
  19. .ent strncpy
  20. strncpy:
  21. .frame $30, 0, $26
  22. .prologue 0
  23. mov $16, $0 # set return value now
  24. beq $18, $zerolen
  25. unop
  26. bsr $23, __stxncpy # do the work of the copy
  27. unop
  28. bne $18, $multiword # do we have full words left?
  29. subq $24, 1, $3 # nope
  30. subq $27, 1, $4
  31. or $3, $24, $3 # clear the bits between the last
  32. or $4, $27, $4 # written byte and the last byte in COUNT
  33. andnot $3, $4, $4
  34. zap $1, $4, $1
  35. stq_u $1, 0($16)
  36. ret
  37. .align 4
  38. $multiword:
  39. subq $27, 1, $2 # clear the final bits in the prev word
  40. or $2, $27, $2
  41. zapnot $1, $2, $1
  42. subq $18, 1, $18
  43. stq_u $1, 0($16)
  44. addq $16, 8, $16
  45. unop
  46. beq $18, 1f
  47. nop
  48. unop
  49. nop
  50. blbc $18, 0f
  51. stq_u $31, 0($16) # zero one word
  52. subq $18, 1, $18
  53. addq $16, 8, $16
  54. beq $18, 1f
  55. 0: stq_u $31, 0($16) # zero two words
  56. subq $18, 2, $18
  57. stq_u $31, 8($16)
  58. addq $16, 16, $16
  59. bne $18, 0b
  60. 1: ldq_u $1, 0($16) # clear the leading bits in the final word
  61. subq $24, 1, $2
  62. or $2, $24, $2
  63. zap $1, $2, $1
  64. stq_u $1, 0($16)
  65. $zerolen:
  66. ret
  67. .end strncpy
  68. EXPORT_SYMBOL(strncpy)