mcount.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. MCOUNT_SAVE_REGS
  69. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  70. PTR_S MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
  71. #endif
  72. PTR_SUBU a0, ra, 8 /* arg1: self address */
  73. PTR_LA t1, _stext
  74. sltu t2, a0, t1 /* t2 = (a0 < _stext) */
  75. PTR_LA t1, _etext
  76. sltu t3, t1, a0 /* t3 = (a0 > _etext) */
  77. or t1, t2, t3
  78. beqz t1, ftrace_call
  79. nop
  80. #if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT)
  81. PTR_SUBU a0, a0, 16 /* arg1: adjust to module's recorded callsite */
  82. #else
  83. PTR_SUBU a0, a0, 12
  84. #endif
  85. .globl ftrace_call
  86. ftrace_call:
  87. nop /* a placeholder for the call to a real tracing function */
  88. move a1, AT /* arg2: parent's return address */
  89. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  90. .globl ftrace_graph_call
  91. ftrace_graph_call:
  92. nop
  93. nop
  94. #endif
  95. MCOUNT_RESTORE_REGS
  96. .globl ftrace_stub
  97. ftrace_stub:
  98. RETURN_BACK
  99. END(ftrace_caller)
  100. #else /* ! CONFIG_DYNAMIC_FTRACE */
  101. NESTED(_mcount, PT_SIZE, ra)
  102. PTR_LA t1, ftrace_stub
  103. PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
  104. beq t1, t2, fgraph_trace
  105. nop
  106. MCOUNT_SAVE_REGS
  107. move a0, ra /* arg1: self return address */
  108. jalr t2 /* (1) call *ftrace_trace_function */
  109. move a1, AT /* arg2: parent's return address */
  110. MCOUNT_RESTORE_REGS
  111. fgraph_trace:
  112. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  113. PTR_LA t1, ftrace_stub
  114. PTR_L t3, ftrace_graph_return
  115. bne t1, t3, ftrace_graph_caller
  116. nop
  117. PTR_LA t1, ftrace_graph_entry_stub
  118. PTR_L t3, ftrace_graph_entry
  119. bne t1, t3, ftrace_graph_caller
  120. nop
  121. #endif
  122. #ifdef CONFIG_32BIT
  123. addiu sp, sp, 8
  124. #endif
  125. .globl ftrace_stub
  126. ftrace_stub:
  127. RETURN_BACK
  128. END(_mcount)
  129. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  130. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  131. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  132. #ifndef CONFIG_DYNAMIC_FTRACE
  133. MCOUNT_SAVE_REGS
  134. #endif
  135. /* arg1: Get the location of the parent's return address */
  136. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  137. #ifdef CONFIG_DYNAMIC_FTRACE
  138. PTR_L a0, PT_R12(sp)
  139. #else
  140. move a0, MCOUNT_RA_ADDRESS_REG
  141. #endif
  142. bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
  143. nop
  144. #endif
  145. PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
  146. 1:
  147. /* arg2: Get self return address */
  148. #ifdef CONFIG_DYNAMIC_FTRACE
  149. PTR_L a1, PT_R31(sp)
  150. #else
  151. move a1, ra
  152. #endif
  153. /* arg3: Get frame pointer of current stack */
  154. #ifdef CONFIG_64BIT
  155. PTR_LA a2, PT_SIZE(sp)
  156. #else
  157. PTR_LA a2, (PT_SIZE+8)(sp)
  158. #endif
  159. jal prepare_ftrace_return
  160. nop
  161. MCOUNT_RESTORE_REGS
  162. #ifndef CONFIG_DYNAMIC_FTRACE
  163. #ifdef CONFIG_32BIT
  164. addiu sp, sp, 8
  165. #endif
  166. #endif
  167. RETURN_BACK
  168. END(ftrace_graph_caller)
  169. .align 2
  170. .globl return_to_handler
  171. return_to_handler:
  172. PTR_SUBU sp, PT_SIZE
  173. PTR_S v0, PT_R2(sp)
  174. jal ftrace_return_to_handler
  175. PTR_S v1, PT_R3(sp)
  176. /* restore the real parent address: v0 -> ra */
  177. move ra, v0
  178. PTR_L v0, PT_R2(sp)
  179. PTR_L v1, PT_R3(sp)
  180. jr ra
  181. PTR_ADDIU sp, PT_SIZE
  182. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  183. .set at
  184. .set reorder