mcount.S 4.4 KB

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