mcount.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifdef CONFIG_DYNAMIC_FTRACE
  56. NESTED(ftrace_caller, PT_SIZE, ra)
  57. .globl _mcount
  58. _mcount:
  59. b ftrace_stub
  60. nop
  61. lw t0, function_trace_stop
  62. bnez t0, ftrace_stub
  63. nop
  64. MCOUNT_SAVE_REGS
  65. move a0, ra /* arg1: next ip, selfaddr */
  66. .globl ftrace_call
  67. ftrace_call:
  68. nop /* a placeholder for the call to a real tracing function */
  69. move a1, AT /* arg2: the caller's next ip, parent */
  70. MCOUNT_RESTORE_REGS
  71. .globl ftrace_stub
  72. ftrace_stub:
  73. RETURN_BACK
  74. END(ftrace_caller)
  75. #else /* ! CONFIG_DYNAMIC_FTRACE */
  76. NESTED(_mcount, PT_SIZE, ra)
  77. lw t0, function_trace_stop
  78. bnez t0, ftrace_stub
  79. nop
  80. PTR_LA t0, ftrace_stub
  81. PTR_L t1, ftrace_trace_function /* Prepare t1 for (1) */
  82. bne t0, t1, static_trace
  83. nop
  84. b ftrace_stub
  85. nop
  86. static_trace:
  87. MCOUNT_SAVE_REGS
  88. move a0, ra /* arg1: next ip, selfaddr */
  89. jalr t1 /* (1) call *ftrace_trace_function */
  90. move a1, AT /* arg2: the caller's next ip, parent */
  91. MCOUNT_RESTORE_REGS
  92. .globl ftrace_stub
  93. ftrace_stub:
  94. RETURN_BACK
  95. END(_mcount)
  96. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  97. .set at
  98. .set reorder