mcount.S 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * MIPS specific _mcount support
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive for
  6. * more details.
  7. *
  8. * Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China
  9. * Author: Wu Zhangjin <wuzj@lemote.com>
  10. */
  11. #include <asm/regdef.h>
  12. #include <asm/stackframe.h>
  13. #include <asm/ftrace.h>
  14. .text
  15. .set noreorder
  16. .set noat
  17. .macro MCOUNT_SAVE_REGS
  18. PTR_SUBU sp, PT_SIZE
  19. PTR_S ra, PT_R31(sp)
  20. PTR_S AT, PT_R1(sp)
  21. PTR_S a0, PT_R4(sp)
  22. PTR_S a1, PT_R5(sp)
  23. PTR_S a2, PT_R6(sp)
  24. PTR_S a3, PT_R7(sp)
  25. #ifdef CONFIG_64BIT
  26. PTR_S a4, PT_R8(sp)
  27. PTR_S a5, PT_R9(sp)
  28. PTR_S a6, PT_R10(sp)
  29. PTR_S a7, PT_R11(sp)
  30. #endif
  31. .endm
  32. .macro MCOUNT_RESTORE_REGS
  33. PTR_L ra, PT_R31(sp)
  34. PTR_L AT, PT_R1(sp)
  35. PTR_L a0, PT_R4(sp)
  36. PTR_L a1, PT_R5(sp)
  37. PTR_L a2, PT_R6(sp)
  38. PTR_L a3, PT_R7(sp)
  39. #ifdef CONFIG_64BIT
  40. PTR_L a4, PT_R8(sp)
  41. PTR_L a5, PT_R9(sp)
  42. PTR_L a6, PT_R10(sp)
  43. PTR_L a7, PT_R11(sp)
  44. #endif
  45. #ifdef CONFIG_64BIT
  46. PTR_ADDIU sp, PT_SIZE
  47. #else
  48. PTR_ADDIU sp, (PT_SIZE + 8)
  49. #endif
  50. .endm
  51. .macro RETURN_BACK
  52. jr ra
  53. move ra, AT
  54. .endm
  55. NESTED(_mcount, PT_SIZE, ra)
  56. PTR_LA t0, ftrace_stub
  57. PTR_L t1, ftrace_trace_function /* Prepare t1 for (1) */
  58. bne t0, t1, static_trace
  59. nop
  60. b ftrace_stub
  61. nop
  62. static_trace:
  63. MCOUNT_SAVE_REGS
  64. move a0, ra /* arg1: next ip, selfaddr */
  65. jalr t1 /* (1) call *ftrace_trace_function */
  66. move a1, AT /* arg2: the caller's next ip, parent */
  67. MCOUNT_RESTORE_REGS
  68. .globl ftrace_stub
  69. ftrace_stub:
  70. RETURN_BACK
  71. END(_mcount)
  72. .set at
  73. .set reorder