strnlen_user.S 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Returns 0 if exception before NUL or reaching the supplied limit (N),
  4. * a value greater than N if the string is longer than the limit, else
  5. * strlen.
  6. *
  7. * Inputs:
  8. * in0: address of buffer
  9. * in1: string length limit N
  10. * Outputs:
  11. * r8: 0 in case of fault, strlen(buffer)+1 otherwise
  12. *
  13. * Copyright (C) 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
  14. */
  15. #include <asm/asmmacro.h>
  16. #include <asm/export.h>
  17. GLOBAL_ENTRY(__strnlen_user)
  18. .prologue
  19. alloc r2=ar.pfs,2,0,0,0
  20. .save ar.lc, r16
  21. mov r16=ar.lc // preserve ar.lc
  22. .body
  23. add r3=-1,in1
  24. ;;
  25. mov ar.lc=r3
  26. mov r9=0
  27. ;;
  28. // XXX braindead strlen loop---this needs to be optimized
  29. .Loop1:
  30. EXCLR(.Lexit, ld1 r8=[in0],1)
  31. add r9=1,r9
  32. ;;
  33. cmp.eq p6,p0=r8,r0
  34. (p6) br.cond.dpnt .Lexit
  35. br.cloop.dptk.few .Loop1
  36. add r9=1,in1 // NUL not found---return N+1
  37. ;;
  38. .Lexit:
  39. mov r8=r9
  40. mov ar.lc=r16 // restore ar.lc
  41. br.ret.sptk.many rp
  42. END(__strnlen_user)
  43. EXPORT_SYMBOL(__strnlen_user)