strnlen_user.S 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <asm/export.h>
  16. GLOBAL_ENTRY(__strnlen_user)
  17. .prologue
  18. alloc r2=ar.pfs,2,0,0,0
  19. .save ar.lc, r16
  20. mov r16=ar.lc // preserve ar.lc
  21. .body
  22. add r3=-1,in1
  23. ;;
  24. mov ar.lc=r3
  25. mov r9=0
  26. ;;
  27. // XXX braindead strlen loop---this needs to be optimized
  28. .Loop1:
  29. EXCLR(.Lexit, ld1 r8=[in0],1)
  30. add r9=1,r9
  31. ;;
  32. cmp.eq p6,p0=r8,r0
  33. (p6) br.cond.dpnt .Lexit
  34. br.cloop.dptk.few .Loop1
  35. add r9=1,in1 // NUL not found---return N+1
  36. ;;
  37. .Lexit:
  38. mov r8=r9
  39. mov ar.lc=r16 // restore ar.lc
  40. br.ret.sptk.many rp
  41. END(__strnlen_user)
  42. EXPORT_SYMBOL(__strnlen_user)