strnlen_user.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 1996, 1998, 1999, 2004 by Ralf Baechle
  7. * Copyright (c) 1999 Silicon Graphics, Inc.
  8. */
  9. #include <asm/asm.h>
  10. #include <asm/asm-offsets.h>
  11. #include <asm/export.h>
  12. #include <asm/regdef.h>
  13. #define EX(insn,reg,addr,handler) \
  14. 9: insn reg, addr; \
  15. .section __ex_table,"a"; \
  16. PTR_WD 9b, handler; \
  17. .previous
  18. /*
  19. * Return the size of a string including the ending NUL character up to a
  20. * maximum of a1 or 0 in case of error.
  21. *
  22. * Note: for performance reasons we deliberately accept that a user may
  23. * make strlen_user and strnlen_user access the first few KSEG0
  24. * bytes. There's nothing secret there. On 64-bit accessing beyond
  25. * the maximum is a tad hairier ...
  26. */
  27. LEAF(__strnlen_user_asm)
  28. move v0, a0
  29. PTR_ADDU a1, a0 # stop pointer
  30. 1:
  31. #ifdef CONFIG_CPU_DADDI_WORKAROUNDS
  32. .set noat
  33. li AT, 1
  34. #endif
  35. beq v0, a1, 1f # limit reached?
  36. #ifdef CONFIG_EVA
  37. .set push
  38. .set eva
  39. EX(lbe, t0, (v0), .Lfault)
  40. .set pop
  41. #else
  42. EX(lb, t0, (v0), .Lfault)
  43. #endif
  44. .set noreorder
  45. bnez t0, 1b
  46. 1:
  47. #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
  48. PTR_ADDIU v0, 1
  49. #else
  50. PTR_ADDU v0, AT
  51. .set at
  52. #endif
  53. .set reorder
  54. PTR_SUBU v0, a0
  55. jr ra
  56. END(__strnlen_user_asm)
  57. .Lfault:
  58. move v0, zero
  59. jr ra
  60. EXPORT_SYMBOL(__strnlen_user_asm)