mcount.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * Copyright (C) 2010 DSLab, Lanzhou University, China
  10. * Author: Wu Zhangjin <wuzhangjin@gmail.com>
  11. */
  12. #include <asm/regdef.h>
  13. #include <asm/stackframe.h>
  14. #include <asm/ftrace.h>
  15. .text
  16. .set noreorder
  17. .set noat
  18. .macro MCOUNT_SAVE_REGS
  19. PTR_SUBU sp, PT_SIZE
  20. PTR_S ra, PT_R31(sp)
  21. PTR_S AT, PT_R1(sp)
  22. PTR_S a0, PT_R4(sp)
  23. PTR_S a1, PT_R5(sp)
  24. PTR_S a2, PT_R6(sp)
  25. PTR_S a3, PT_R7(sp)
  26. #ifdef CONFIG_64BIT
  27. PTR_S a4, PT_R8(sp)
  28. PTR_S a5, PT_R9(sp)
  29. PTR_S a6, PT_R10(sp)
  30. PTR_S a7, PT_R11(sp)
  31. #endif
  32. .endm
  33. .macro MCOUNT_RESTORE_REGS
  34. PTR_L ra, PT_R31(sp)
  35. PTR_L AT, PT_R1(sp)
  36. PTR_L a0, PT_R4(sp)
  37. PTR_L a1, PT_R5(sp)
  38. PTR_L a2, PT_R6(sp)
  39. PTR_L a3, PT_R7(sp)
  40. #ifdef CONFIG_64BIT
  41. PTR_L a4, PT_R8(sp)
  42. PTR_L a5, PT_R9(sp)
  43. PTR_L a6, PT_R10(sp)
  44. PTR_L a7, PT_R11(sp)
  45. #endif
  46. PTR_ADDIU sp, PT_SIZE
  47. .endm
  48. .macro RETURN_BACK
  49. jr ra
  50. move ra, AT
  51. .endm
  52. /*
  53. * The -mmcount-ra-address option of gcc 4.5 uses register $12 to pass
  54. * the location of the parent's return address.
  55. */
  56. #define MCOUNT_RA_ADDRESS_REG $12
  57. #ifdef CONFIG_DYNAMIC_FTRACE
  58. NESTED(ftrace_caller, PT_SIZE, ra)
  59. .globl _mcount
  60. _mcount:
  61. b ftrace_stub
  62. #ifdef CONFIG_32BIT
  63. addiu sp,sp,8
  64. #else
  65. nop
  66. #endif
  67. /* When tracing is activated, it calls ftrace_caller+8 (aka here) */
  68. lw t1, function_trace_stop
  69. bnez t1, ftrace_stub
  70. nop
  71. MCOUNT_SAVE_REGS
  72. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  73. PTR_S MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
  74. #endif
  75. move a0, ra /* arg1: self return address */
  76. .globl ftrace_call
  77. ftrace_call:
  78. nop /* a placeholder for the call to a real tracing function */
  79. move a1, AT /* arg2: parent's return address */
  80. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  81. .globl ftrace_graph_call
  82. ftrace_graph_call:
  83. nop
  84. nop
  85. #endif
  86. MCOUNT_RESTORE_REGS
  87. .globl ftrace_stub
  88. ftrace_stub:
  89. RETURN_BACK
  90. END(ftrace_caller)
  91. #else /* ! CONFIG_DYNAMIC_FTRACE */
  92. NESTED(_mcount, PT_SIZE, ra)
  93. lw t1, function_trace_stop
  94. bnez t1, ftrace_stub
  95. nop
  96. PTR_LA t1, ftrace_stub
  97. PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
  98. bne t1, t2, static_trace
  99. nop
  100. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  101. PTR_L t3, ftrace_graph_return
  102. bne t1, t3, ftrace_graph_caller
  103. nop
  104. PTR_LA t1, ftrace_graph_entry_stub
  105. PTR_L t3, ftrace_graph_entry
  106. bne t1, t3, ftrace_graph_caller
  107. nop
  108. #endif
  109. b ftrace_stub
  110. nop
  111. static_trace:
  112. MCOUNT_SAVE_REGS
  113. move a0, ra /* arg1: self return address */
  114. jalr t2 /* (1) call *ftrace_trace_function */
  115. move a1, AT /* arg2: parent's return address */
  116. MCOUNT_RESTORE_REGS
  117. .globl ftrace_stub
  118. ftrace_stub:
  119. RETURN_BACK
  120. END(_mcount)
  121. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  122. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  123. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  124. #ifndef CONFIG_DYNAMIC_FTRACE
  125. MCOUNT_SAVE_REGS
  126. #endif
  127. /* arg1: Get the location of the parent's return address */
  128. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  129. #ifdef CONFIG_DYNAMIC_FTRACE
  130. PTR_L a0, PT_R12(sp)
  131. #else
  132. move a0, MCOUNT_RA_ADDRESS_REG
  133. #endif
  134. bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
  135. nop
  136. #endif
  137. PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
  138. 1:
  139. /* arg2: Get self return address */
  140. #ifdef CONFIG_DYNAMIC_FTRACE
  141. PTR_L a1, PT_R31(sp)
  142. #else
  143. move a1, ra
  144. #endif
  145. /* arg3: Get frame pointer of current stack */
  146. #ifdef CONFIG_FRAME_POINTER
  147. move a2, fp
  148. #else /* ! CONFIG_FRAME_POINTER */
  149. #ifdef CONFIG_64BIT
  150. PTR_LA a2, PT_SIZE(sp)
  151. #else
  152. PTR_LA a2, (PT_SIZE+8)(sp)
  153. #endif
  154. #endif
  155. jal prepare_ftrace_return
  156. nop
  157. MCOUNT_RESTORE_REGS
  158. RETURN_BACK
  159. END(ftrace_graph_caller)
  160. .align 2
  161. .globl return_to_handler
  162. return_to_handler:
  163. PTR_SUBU sp, PT_SIZE
  164. PTR_S v0, PT_R2(sp)
  165. jal ftrace_return_to_handler
  166. PTR_S v1, PT_R3(sp)
  167. /* restore the real parent address: v0 -> ra */
  168. move ra, v0
  169. PTR_L v0, PT_R2(sp)
  170. PTR_L v1, PT_R3(sp)
  171. jr ra
  172. PTR_ADDIU sp, PT_SIZE
  173. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  174. .set at
  175. .set reorder