strlen_user.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. move v0, a0
  29. .ifeqs "\func", "kernel"
  30. 1: EX(lbu, v1, (v0), .Lfault\@)
  31. .else
  32. 1: EX(lbue, v1, (v0), .Lfault\@)
  33. .endif
  34. PTR_ADDIU v0, 1
  35. bnez v1, 1b
  36. PTR_SUBU v0, a0
  37. jr ra
  38. END(__strlen_\func\()_asm)
  39. .Lfault\@: move v0, zero
  40. jr ra
  41. .endm
  42. #ifndef CONFIG_EVA
  43. /* Set aliases */
  44. .global __strlen_user_asm
  45. .set __strlen_user_asm, __strlen_kernel_asm
  46. #endif
  47. __BUILD_STRLEN_ASM kernel
  48. #ifdef CONFIG_EVA
  49. .set push
  50. .set eva
  51. __BUILD_STRLEN_ASM user
  52. .set pop
  53. #endif