mcount.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. bne t1, t2, static_trace
  105. nop
  106. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  107. PTR_L t3, ftrace_graph_return
  108. bne t1, t3, ftrace_graph_caller
  109. nop
  110. PTR_LA t1, ftrace_graph_entry_stub
  111. PTR_L t3, ftrace_graph_entry
  112. bne t1, t3, ftrace_graph_caller
  113. nop
  114. #endif
  115. b ftrace_stub
  116. #ifdef CONFIG_32BIT
  117. addiu sp, sp, 8
  118. #else
  119. nop
  120. #endif
  121. static_trace:
  122. MCOUNT_SAVE_REGS
  123. move a0, ra /* arg1: self return address */
  124. jalr t2 /* (1) call *ftrace_trace_function */
  125. move a1, AT /* arg2: parent's return address */
  126. MCOUNT_RESTORE_REGS
  127. #ifdef CONFIG_32BIT
  128. addiu sp, sp, 8
  129. #endif
  130. .globl ftrace_stub
  131. ftrace_stub:
  132. RETURN_BACK
  133. END(_mcount)
  134. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  135. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  136. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  137. #ifndef CONFIG_DYNAMIC_FTRACE
  138. MCOUNT_SAVE_REGS
  139. #endif
  140. /* arg1: Get the location of the parent's return address */
  141. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  142. #ifdef CONFIG_DYNAMIC_FTRACE
  143. PTR_L a0, PT_R12(sp)
  144. #else
  145. move a0, MCOUNT_RA_ADDRESS_REG
  146. #endif
  147. bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
  148. nop
  149. #endif
  150. PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
  151. 1:
  152. /* arg2: Get self return address */
  153. #ifdef CONFIG_DYNAMIC_FTRACE
  154. PTR_L a1, PT_R31(sp)
  155. #else
  156. move a1, ra
  157. #endif
  158. /* arg3: Get frame pointer of current stack */
  159. #ifdef CONFIG_64BIT
  160. PTR_LA a2, PT_SIZE(sp)
  161. #else
  162. PTR_LA a2, (PT_SIZE+8)(sp)
  163. #endif
  164. jal prepare_ftrace_return
  165. nop
  166. MCOUNT_RESTORE_REGS
  167. #ifndef CONFIG_DYNAMIC_FTRACE
  168. #ifdef CONFIG_32BIT
  169. addiu sp, sp, 8
  170. #endif
  171. #endif
  172. RETURN_BACK
  173. END(ftrace_graph_caller)
  174. .align 2
  175. .globl return_to_handler
  176. return_to_handler:
  177. PTR_SUBU sp, PT_SIZE
  178. PTR_S v0, PT_R2(sp)
  179. jal ftrace_return_to_handler
  180. PTR_S v1, PT_R3(sp)
  181. /* restore the real parent address: v0 -> ra */
  182. move ra, v0
  183. PTR_L v0, PT_R2(sp)
  184. PTR_L v1, PT_R3(sp)
  185. jr ra
  186. PTR_ADDIU sp, PT_SIZE
  187. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  188. .set at
  189. .set reorder