mcount.S 4.1 KB

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