strnlen_user.S 903 B

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