mcount-dyn.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2017 Andes Technology Corporation */
  3. #include <linux/init.h>
  4. #include <linux/linkage.h>
  5. #include <asm/asm.h>
  6. #include <asm/csr.h>
  7. #include <asm/unistd.h>
  8. #include <asm/thread_info.h>
  9. #include <asm/asm-offsets.h>
  10. #include <asm-generic/export.h>
  11. #include <asm/ftrace.h>
  12. .text
  13. .macro SAVE_ABI_STATE
  14. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  15. addi sp, sp, -48
  16. sd s0, 32(sp)
  17. sd ra, 40(sp)
  18. addi s0, sp, 48
  19. sd t0, 24(sp)
  20. sd t1, 16(sp)
  21. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  22. sd t2, 8(sp)
  23. #endif
  24. #else
  25. addi sp, sp, -16
  26. sd s0, 0(sp)
  27. sd ra, 8(sp)
  28. addi s0, sp, 16
  29. #endif
  30. .endm
  31. .macro RESTORE_ABI_STATE
  32. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  33. ld s0, 32(sp)
  34. ld ra, 40(sp)
  35. addi sp, sp, 48
  36. #else
  37. ld ra, 8(sp)
  38. ld s0, 0(sp)
  39. addi sp, sp, 16
  40. #endif
  41. .endm
  42. .macro RESTORE_GRAPH_ARGS
  43. ld a0, 24(sp)
  44. ld a1, 16(sp)
  45. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  46. ld a2, 8(sp)
  47. #endif
  48. .endm
  49. ENTRY(ftrace_graph_caller)
  50. addi sp, sp, -16
  51. sd s0, 0(sp)
  52. sd ra, 8(sp)
  53. addi s0, sp, 16
  54. ftrace_graph_call:
  55. .global ftrace_graph_call
  56. /*
  57. * Calling ftrace_enable/disable_ftrace_graph_caller would overwrite the
  58. * call below. Check ftrace_modify_all_code for details.
  59. */
  60. call ftrace_stub
  61. ld ra, 8(sp)
  62. ld s0, 0(sp)
  63. addi sp, sp, 16
  64. ret
  65. ENDPROC(ftrace_graph_caller)
  66. ENTRY(ftrace_caller)
  67. /*
  68. * a0: the address in the caller when calling ftrace_caller
  69. * a1: the caller's return address
  70. * a2: the address of global variable function_trace_op
  71. */
  72. ld a1, -8(s0)
  73. addi a0, ra, -MCOUNT_INSN_SIZE
  74. la t5, function_trace_op
  75. ld a2, 0(t5)
  76. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  77. /*
  78. * the graph tracer (specifically, prepare_ftrace_return) needs these
  79. * arguments but for now the function tracer occupies the regs, so we
  80. * save them in temporary regs to recover later.
  81. */
  82. addi t0, s0, -8
  83. mv t1, a0
  84. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  85. ld t2, -16(s0)
  86. #endif
  87. #endif
  88. SAVE_ABI_STATE
  89. ftrace_call:
  90. .global ftrace_call
  91. /*
  92. * For the dynamic ftrace to work, here we should reserve at least
  93. * 8 bytes for a functional auipc-jalr pair. The following call
  94. * serves this purpose.
  95. *
  96. * Calling ftrace_update_ftrace_func would overwrite the nops below.
  97. * Check ftrace_modify_all_code for details.
  98. */
  99. call ftrace_stub
  100. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  101. RESTORE_GRAPH_ARGS
  102. call ftrace_graph_caller
  103. #endif
  104. RESTORE_ABI_STATE
  105. ret
  106. ENDPROC(ftrace_caller)
  107. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  108. .macro SAVE_ALL
  109. addi sp, sp, -(PT_SIZE_ON_STACK+16)
  110. sd s0, (PT_SIZE_ON_STACK)(sp)
  111. sd ra, (PT_SIZE_ON_STACK+8)(sp)
  112. addi s0, sp, (PT_SIZE_ON_STACK+16)
  113. sd x1, PT_RA(sp)
  114. sd x2, PT_SP(sp)
  115. sd x3, PT_GP(sp)
  116. sd x4, PT_TP(sp)
  117. sd x5, PT_T0(sp)
  118. sd x6, PT_T1(sp)
  119. sd x7, PT_T2(sp)
  120. sd x8, PT_S0(sp)
  121. sd x9, PT_S1(sp)
  122. sd x10, PT_A0(sp)
  123. sd x11, PT_A1(sp)
  124. sd x12, PT_A2(sp)
  125. sd x13, PT_A3(sp)
  126. sd x14, PT_A4(sp)
  127. sd x15, PT_A5(sp)
  128. sd x16, PT_A6(sp)
  129. sd x17, PT_A7(sp)
  130. sd x18, PT_S2(sp)
  131. sd x19, PT_S3(sp)
  132. sd x20, PT_S4(sp)
  133. sd x21, PT_S5(sp)
  134. sd x22, PT_S6(sp)
  135. sd x23, PT_S7(sp)
  136. sd x24, PT_S8(sp)
  137. sd x25, PT_S9(sp)
  138. sd x26, PT_S10(sp)
  139. sd x27, PT_S11(sp)
  140. sd x28, PT_T3(sp)
  141. sd x29, PT_T4(sp)
  142. sd x30, PT_T5(sp)
  143. sd x31, PT_T6(sp)
  144. .endm
  145. .macro RESTORE_ALL
  146. ld x1, PT_RA(sp)
  147. ld x2, PT_SP(sp)
  148. ld x3, PT_GP(sp)
  149. ld x4, PT_TP(sp)
  150. ld x5, PT_T0(sp)
  151. ld x6, PT_T1(sp)
  152. ld x7, PT_T2(sp)
  153. ld x8, PT_S0(sp)
  154. ld x9, PT_S1(sp)
  155. ld x10, PT_A0(sp)
  156. ld x11, PT_A1(sp)
  157. ld x12, PT_A2(sp)
  158. ld x13, PT_A3(sp)
  159. ld x14, PT_A4(sp)
  160. ld x15, PT_A5(sp)
  161. ld x16, PT_A6(sp)
  162. ld x17, PT_A7(sp)
  163. ld x18, PT_S2(sp)
  164. ld x19, PT_S3(sp)
  165. ld x20, PT_S4(sp)
  166. ld x21, PT_S5(sp)
  167. ld x22, PT_S6(sp)
  168. ld x23, PT_S7(sp)
  169. ld x24, PT_S8(sp)
  170. ld x25, PT_S9(sp)
  171. ld x26, PT_S10(sp)
  172. ld x27, PT_S11(sp)
  173. ld x28, PT_T3(sp)
  174. ld x29, PT_T4(sp)
  175. ld x30, PT_T5(sp)
  176. ld x31, PT_T6(sp)
  177. ld s0, (PT_SIZE_ON_STACK)(sp)
  178. ld ra, (PT_SIZE_ON_STACK+8)(sp)
  179. addi sp, sp, (PT_SIZE_ON_STACK+16)
  180. .endm
  181. .macro RESTORE_GRAPH_REG_ARGS
  182. ld a0, PT_T0(sp)
  183. ld a1, PT_T1(sp)
  184. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  185. ld a2, PT_T2(sp)
  186. #endif
  187. .endm
  188. /*
  189. * Most of the contents are the same as ftrace_caller.
  190. */
  191. ENTRY(ftrace_regs_caller)
  192. /*
  193. * a3: the address of all registers in the stack
  194. */
  195. ld a1, -8(s0)
  196. addi a0, ra, -MCOUNT_INSN_SIZE
  197. la t5, function_trace_op
  198. ld a2, 0(t5)
  199. addi a3, sp, -(PT_SIZE_ON_STACK+16)
  200. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  201. addi t0, s0, -8
  202. mv t1, a0
  203. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  204. ld t2, -16(s0)
  205. #endif
  206. #endif
  207. SAVE_ALL
  208. ftrace_regs_call:
  209. .global ftrace_regs_call
  210. call ftrace_stub
  211. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  212. RESTORE_GRAPH_REG_ARGS
  213. call ftrace_graph_caller
  214. #endif
  215. RESTORE_ALL
  216. ret
  217. ENDPROC(ftrace_regs_caller)
  218. #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */