mcount.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. * Author: Wu Zhangjin <wuzj@lemote.com>
  10. */
  11. #include <asm/regdef.h>
  12. #include <asm/stackframe.h>
  13. #include <asm/ftrace.h>
  14. .text
  15. .set noreorder
  16. .set noat
  17. .macro MCOUNT_SAVE_REGS
  18. PTR_SUBU sp, PT_SIZE
  19. PTR_S ra, PT_R31(sp)
  20. PTR_S AT, PT_R1(sp)
  21. PTR_S a0, PT_R4(sp)
  22. PTR_S a1, PT_R5(sp)
  23. PTR_S a2, PT_R6(sp)
  24. PTR_S a3, PT_R7(sp)
  25. #ifdef CONFIG_64BIT
  26. PTR_S a4, PT_R8(sp)
  27. PTR_S a5, PT_R9(sp)
  28. PTR_S a6, PT_R10(sp)
  29. PTR_S a7, PT_R11(sp)
  30. #endif
  31. .endm
  32. .macro MCOUNT_RESTORE_REGS
  33. PTR_L ra, PT_R31(sp)
  34. PTR_L AT, PT_R1(sp)
  35. PTR_L a0, PT_R4(sp)
  36. PTR_L a1, PT_R5(sp)
  37. PTR_L a2, PT_R6(sp)
  38. PTR_L a3, PT_R7(sp)
  39. #ifdef CONFIG_64BIT
  40. PTR_L a4, PT_R8(sp)
  41. PTR_L a5, PT_R9(sp)
  42. PTR_L a6, PT_R10(sp)
  43. PTR_L a7, PT_R11(sp)
  44. #endif
  45. #ifdef CONFIG_64BIT
  46. PTR_ADDIU sp, PT_SIZE
  47. #else
  48. PTR_ADDIU sp, (PT_SIZE + 8)
  49. #endif
  50. .endm
  51. .macro RETURN_BACK
  52. jr ra
  53. move ra, AT
  54. .endm
  55. #ifdef CONFIG_DYNAMIC_FTRACE
  56. NESTED(ftrace_caller, PT_SIZE, ra)
  57. .globl _mcount
  58. _mcount:
  59. b ftrace_stub
  60. nop
  61. lw t1, function_trace_stop
  62. bnez t1, ftrace_stub
  63. nop
  64. MCOUNT_SAVE_REGS
  65. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  66. PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
  67. #endif
  68. move a0, ra /* arg1: next ip, selfaddr */
  69. .globl ftrace_call
  70. ftrace_call:
  71. nop /* a placeholder for the call to a real tracing function */
  72. move a1, AT /* arg2: the caller's next ip, parent */
  73. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  74. .globl ftrace_graph_call
  75. ftrace_graph_call:
  76. nop
  77. nop
  78. #endif
  79. MCOUNT_RESTORE_REGS
  80. .globl ftrace_stub
  81. ftrace_stub:
  82. RETURN_BACK
  83. END(ftrace_caller)
  84. #else /* ! CONFIG_DYNAMIC_FTRACE */
  85. NESTED(_mcount, PT_SIZE, ra)
  86. lw t1, function_trace_stop
  87. bnez t1, ftrace_stub
  88. nop
  89. PTR_LA t1, ftrace_stub
  90. PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
  91. bne t1, t2, static_trace
  92. nop
  93. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  94. PTR_L t3, ftrace_graph_return
  95. bne t1, t3, ftrace_graph_caller
  96. nop
  97. PTR_LA t1, ftrace_graph_entry_stub
  98. PTR_L t3, ftrace_graph_entry
  99. bne t1, t3, ftrace_graph_caller
  100. nop
  101. #endif
  102. b ftrace_stub
  103. nop
  104. static_trace:
  105. MCOUNT_SAVE_REGS
  106. move a0, ra /* arg1: next ip, selfaddr */
  107. jalr t2 /* (1) call *ftrace_trace_function */
  108. move a1, AT /* arg2: the caller's next ip, parent */
  109. MCOUNT_RESTORE_REGS
  110. .globl ftrace_stub
  111. ftrace_stub:
  112. RETURN_BACK
  113. END(_mcount)
  114. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  115. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  116. NESTED(ftrace_graph_caller, PT_SIZE, ra)
  117. #ifdef CONFIG_DYNAMIC_FTRACE
  118. PTR_L a1, PT_R31(sp) /* load the original ra from the stack */
  119. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  120. PTR_L t0, PT_R12(sp) /* load the original t0 from the stack */
  121. #endif
  122. #else
  123. MCOUNT_SAVE_REGS
  124. move a1, ra /* arg2: next ip, selfaddr */
  125. #endif
  126. #ifdef KBUILD_MCOUNT_RA_ADDRESS
  127. bnez t0, 1f /* non-leaf func: t0 saved the location of the return address */
  128. nop
  129. PTR_LA t0, PT_R1(sp) /* leaf func: get the location of at(old ra) from our own stack */
  130. 1: move a0, t0 /* arg1: the location of the return address */
  131. #else
  132. PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */
  133. #endif
  134. jal prepare_ftrace_return
  135. #ifdef CONFIG_FRAME_POINTER
  136. move a2, fp /* arg3: frame pointer */
  137. #else
  138. #ifdef CONFIG_64BIT
  139. PTR_LA a2, PT_SIZE(sp)
  140. #else
  141. PTR_LA a2, (PT_SIZE+8)(sp)
  142. #endif
  143. #endif
  144. MCOUNT_RESTORE_REGS
  145. RETURN_BACK
  146. END(ftrace_graph_caller)
  147. .align 2
  148. .globl return_to_handler
  149. return_to_handler:
  150. PTR_SUBU sp, PT_SIZE
  151. PTR_S v0, PT_R2(sp)
  152. jal ftrace_return_to_handler
  153. PTR_S v1, PT_R3(sp)
  154. /* restore the real parent address: v0 -> ra */
  155. move ra, v0
  156. PTR_L v0, PT_R2(sp)
  157. PTR_L v1, PT_R3(sp)
  158. jr ra
  159. PTR_ADDIU sp, PT_SIZE
  160. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  161. .set at
  162. .set reorder