mcount.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 <wuzhangjin@gmail.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. PTR_ADDIU sp, PT_SIZE
  45. #else
  46. PTR_ADDIU sp, (PT_SIZE + 8)
  47. #endif
  48. .endm
  49. .macro RETURN_BACK
  50. jr ra
  51. move ra, AT
  52. .endm
  53. #ifdef CONFIG_DYNAMIC_FTRACE
  54. NESTED(ftrace_caller, PT_SIZE, ra)
  55. .globl _mcount
  56. _mcount:
  57. b ftrace_stub
  58. nop
  59. lw t1, function_trace_stop
  60. bnez t1, ftrace_stub
  61. nop
  62. MCOUNT_SAVE_REGS
  63. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  64. PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
  65. #endif
  66. move a0, ra /* arg1: next ip, selfaddr */
  67. .globl ftrace_call
  68. ftrace_call:
  69. nop /* a placeholder for the call to a real tracing function */
  70. move a1, AT /* arg2: the caller's next ip, parent */
  71. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  72. .globl ftrace_graph_call
  73. ftrace_graph_call:
  74. nop
  75. nop
  76. #endif
  77. MCOUNT_RESTORE_REGS
  78. .globl ftrace_stub
  79. ftrace_stub:
  80. RETURN_BACK
  81. END(ftrace_caller)
  82. #else /* ! CONFIG_DYNAMIC_FTRACE */
  83. NESTED(_mcount, PT_SIZE, ra)
  84. lw t1, function_trace_stop
  85. bnez t1, ftrace_stub
  86. nop
  87. PTR_LA t1, ftrace_stub
  88. PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
  89. bne t1, t2, static_trace
  90. nop
  91. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  92. PTR_L t3, ftrace_graph_return
  93. bne t1, t3, ftrace_graph_caller
  94. nop
  95. PTR_LA t1, ftrace_graph_entry_stub
  96. PTR_L t3, ftrace_graph_entry
  97. bne t1, t3, ftrace_graph_caller
  98. nop
  99. #endif
  100. b ftrace_stub
  101. nop
  102. static_trace:
  103. MCOUNT_SAVE_REGS
  104. move a0, ra /* arg1: next ip, selfaddr */
  105. jalr t2 /* (1) call *ftrace_trace_function */
  106. move a1, AT /* arg2: the caller's next ip, parent */
  107. MCOUNT_RESTORE_REGS
  108. .globl ftrace_stub
  109. ftrace_stub:
  110. RETURN_BACK
  111. END(_mcount)
  112. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  113. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  114. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  115. #ifndef CONFIG_DYNAMIC_FTRACE
  116. MCOUNT_SAVE_REGS
  117. #endif
  118. /* arg1: Get the location of the parent's return address */
  119. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  120. #ifdef CONFIG_DYNAMIC_FTRACE
  121. PTR_L a0, PT_R12(sp)
  122. #else
  123. move a0, t0
  124. #endif
  125. bnez a0, 1f /* non-leaf func: stored in t0 */
  126. nop
  127. #endif
  128. PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
  129. 1:
  130. /* arg2: Get self return address */
  131. #ifdef CONFIG_DYNAMIC_FTRACE
  132. PTR_L a1, PT_R31(sp)
  133. #else
  134. move a1, ra
  135. #endif
  136. /* arg3: Get frame pointer of current stack */
  137. #ifdef CONFIG_FRAME_POINTER
  138. move a2, fp
  139. #else /* ! CONFIG_FRAME_POINTER */
  140. #ifdef CONFIG_64BIT
  141. PTR_LA a2, PT_SIZE(sp)
  142. #else
  143. PTR_LA a2, (PT_SIZE+8)(sp)
  144. #endif
  145. #endif
  146. jal prepare_ftrace_return
  147. nop
  148. MCOUNT_RESTORE_REGS
  149. RETURN_BACK
  150. END(ftrace_graph_caller)
  151. .align 2
  152. .globl return_to_handler
  153. return_to_handler:
  154. PTR_SUBU sp, PT_SIZE
  155. PTR_S v0, PT_R2(sp)
  156. jal ftrace_return_to_handler
  157. PTR_S v1, PT_R3(sp)
  158. /* restore the real parent address: v0 -> ra */
  159. move ra, v0
  160. PTR_L v0, PT_R2(sp)
  161. PTR_L v1, PT_R3(sp)
  162. jr ra
  163. PTR_ADDIU sp, PT_SIZE
  164. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  165. .set at
  166. .set reorder