strlen_user.S 1.3 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. * Copyright (C) 2011 MIPS Technologies, Inc.
  9. */
  10. #include <asm/asm.h>
  11. #include <asm/asm-offsets.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 9b, handler; \
  17. .previous
  18. /*
  19. * Return the size of a string (including the ending 0)
  20. *
  21. * Return 0 for error
  22. */
  23. .macro __BUILD_STRLEN_ASM func
  24. LEAF(__strlen_\func\()_asm)
  25. LONG_L v0, TI_ADDR_LIMIT($28) # pointer ok?
  26. and v0, a0
  27. bnez v0, .Lfault\@
  28. FEXPORT(__strlen_\func\()_nocheck_asm)
  29. move v0, a0
  30. .ifeqs "\func", "kernel"
  31. 1: EX(lbu, v1, (v0), .Lfault\@)
  32. .else
  33. 1: EX(lbue, v1, (v0), .Lfault\@)
  34. .endif
  35. PTR_ADDIU v0, 1
  36. bnez v1, 1b
  37. PTR_SUBU v0, a0
  38. jr ra
  39. END(__strlen_\func\()_asm)
  40. .Lfault\@: move v0, zero
  41. jr ra
  42. .endm
  43. #ifndef CONFIG_EVA
  44. /* Set aliases */
  45. .global __strlen_user_asm
  46. .global __strlen_user_nocheck_asm
  47. .set __strlen_user_asm, __strlen_kernel_asm
  48. .set __strlen_user_nocheck_asm, __strlen_kernel_nocheck_asm
  49. #endif
  50. __BUILD_STRLEN_ASM kernel
  51. #ifdef CONFIG_EVA
  52. .set push
  53. .set eva
  54. __BUILD_STRLEN_ASM user
  55. .set pop
  56. #endif