mcount.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. nop
  108. static_trace:
  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. .globl ftrace_stub
  115. ftrace_stub:
  116. RETURN_BACK
  117. END(_mcount)
  118. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  119. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  120. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  121. #ifndef CONFIG_DYNAMIC_FTRACE
  122. MCOUNT_SAVE_REGS
  123. #endif
  124. /* arg1: Get the location of the parent's return address */
  125. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  126. #ifdef CONFIG_DYNAMIC_FTRACE
  127. PTR_L a0, PT_R12(sp)
  128. #else
  129. move a0, MCOUNT_RA_ADDRESS_REG
  130. #endif
  131. bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
  132. nop
  133. #endif
  134. PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
  135. 1:
  136. /* arg2: Get self return address */
  137. #ifdef CONFIG_DYNAMIC_FTRACE
  138. PTR_L a1, PT_R31(sp)
  139. #else
  140. move a1, ra
  141. #endif
  142. /* arg3: Get frame pointer of current stack */
  143. #ifdef CONFIG_FRAME_POINTER
  144. move a2, fp
  145. #else /* ! CONFIG_FRAME_POINTER */
  146. #ifdef CONFIG_64BIT
  147. PTR_LA a2, PT_SIZE(sp)
  148. #else
  149. PTR_LA a2, (PT_SIZE+8)(sp)
  150. #endif
  151. #endif
  152. jal prepare_ftrace_return
  153. nop
  154. MCOUNT_RESTORE_REGS
  155. RETURN_BACK
  156. END(ftrace_graph_caller)
  157. .align 2
  158. .globl return_to_handler
  159. return_to_handler:
  160. PTR_SUBU sp, PT_SIZE
  161. PTR_S v0, PT_R2(sp)
  162. jal ftrace_return_to_handler
  163. PTR_S v1, PT_R3(sp)
  164. /* restore the real parent address: v0 -> ra */
  165. move ra, v0
  166. PTR_L v0, PT_R2(sp)
  167. PTR_L v1, PT_R3(sp)
  168. jr ra
  169. PTR_ADDIU sp, PT_SIZE
  170. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  171. .set at
  172. .set reorder