mcount.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  71. .globl ftrace_graph_call
  72. ftrace_graph_call:
  73. nop
  74. nop
  75. #endif
  76. MCOUNT_RESTORE_REGS
  77. .globl ftrace_stub
  78. ftrace_stub:
  79. RETURN_BACK
  80. END(ftrace_caller)
  81. #else /* ! CONFIG_DYNAMIC_FTRACE */
  82. NESTED(_mcount, PT_SIZE, ra)
  83. lw t0, function_trace_stop
  84. bnez t0, ftrace_stub
  85. nop
  86. PTR_LA t0, ftrace_stub
  87. PTR_L t1, ftrace_trace_function /* Prepare t1 for (1) */
  88. bne t0, t1, static_trace
  89. nop
  90. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  91. PTR_L t2, ftrace_graph_return
  92. bne t0, t2, ftrace_graph_caller
  93. nop
  94. PTR_LA t0, ftrace_graph_entry_stub
  95. PTR_L t2, ftrace_graph_entry
  96. bne t0, t2, ftrace_graph_caller
  97. nop
  98. #endif
  99. b ftrace_stub
  100. nop
  101. static_trace:
  102. MCOUNT_SAVE_REGS
  103. move a0, ra /* arg1: next ip, selfaddr */
  104. jalr t1 /* (1) call *ftrace_trace_function */
  105. move a1, AT /* arg2: the caller's next ip, parent */
  106. MCOUNT_RESTORE_REGS
  107. .globl ftrace_stub
  108. ftrace_stub:
  109. RETURN_BACK
  110. END(_mcount)
  111. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  112. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  113. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  114. #ifdef CONFIG_DYNAMIC_FTRACE
  115. PTR_L a1, PT_R31(sp) /* load the original ra from the stack */
  116. #else
  117. MCOUNT_SAVE_REGS
  118. move a1, ra /* arg2: next ip, selfaddr */
  119. #endif
  120. PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */
  121. jal prepare_ftrace_return
  122. move a2, fp /* arg3: frame pointer */
  123. MCOUNT_RESTORE_REGS
  124. RETURN_BACK
  125. END(ftrace_graph_caller)
  126. .align 2
  127. .globl return_to_handler
  128. return_to_handler:
  129. PTR_SUBU sp, PT_SIZE
  130. PTR_S v0, PT_R2(sp)
  131. jal ftrace_return_to_handler
  132. PTR_S v1, PT_R3(sp)
  133. /* restore the real parent address: v0 -> ra */
  134. move ra, v0
  135. PTR_L v0, PT_R2(sp)
  136. PTR_L v1, PT_R3(sp)
  137. jr ra
  138. PTR_ADDIU sp, PT_SIZE
  139. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  140. .set at
  141. .set reorder