mcount-dyn.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. #define FENTRY_RA_OFFSET 12
  14. #define ABI_SIZE_ON_STACK 72
  15. #define ABI_A0 0
  16. #define ABI_A1 8
  17. #define ABI_A2 16
  18. #define ABI_A3 24
  19. #define ABI_A4 32
  20. #define ABI_A5 40
  21. #define ABI_A6 48
  22. #define ABI_A7 56
  23. #define ABI_RA 64
  24. .macro SAVE_ABI
  25. addi sp, sp, -SZREG
  26. addi sp, sp, -ABI_SIZE_ON_STACK
  27. REG_S a0, ABI_A0(sp)
  28. REG_S a1, ABI_A1(sp)
  29. REG_S a2, ABI_A2(sp)
  30. REG_S a3, ABI_A3(sp)
  31. REG_S a4, ABI_A4(sp)
  32. REG_S a5, ABI_A5(sp)
  33. REG_S a6, ABI_A6(sp)
  34. REG_S a7, ABI_A7(sp)
  35. REG_S ra, ABI_RA(sp)
  36. .endm
  37. .macro RESTORE_ABI
  38. REG_L a0, ABI_A0(sp)
  39. REG_L a1, ABI_A1(sp)
  40. REG_L a2, ABI_A2(sp)
  41. REG_L a3, ABI_A3(sp)
  42. REG_L a4, ABI_A4(sp)
  43. REG_L a5, ABI_A5(sp)
  44. REG_L a6, ABI_A6(sp)
  45. REG_L a7, ABI_A7(sp)
  46. REG_L ra, ABI_RA(sp)
  47. addi sp, sp, ABI_SIZE_ON_STACK
  48. addi sp, sp, SZREG
  49. .endm
  50. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  51. .macro SAVE_ALL
  52. addi sp, sp, -SZREG
  53. addi sp, sp, -PT_SIZE_ON_STACK
  54. REG_S x1, PT_EPC(sp)
  55. addi sp, sp, PT_SIZE_ON_STACK
  56. REG_L x1, (sp)
  57. addi sp, sp, -PT_SIZE_ON_STACK
  58. REG_S x1, PT_RA(sp)
  59. REG_L x1, PT_EPC(sp)
  60. REG_S x2, PT_SP(sp)
  61. REG_S x3, PT_GP(sp)
  62. REG_S x4, PT_TP(sp)
  63. REG_S x5, PT_T0(sp)
  64. REG_S x6, PT_T1(sp)
  65. REG_S x7, PT_T2(sp)
  66. REG_S x8, PT_S0(sp)
  67. REG_S x9, PT_S1(sp)
  68. REG_S x10, PT_A0(sp)
  69. REG_S x11, PT_A1(sp)
  70. REG_S x12, PT_A2(sp)
  71. REG_S x13, PT_A3(sp)
  72. REG_S x14, PT_A4(sp)
  73. REG_S x15, PT_A5(sp)
  74. REG_S x16, PT_A6(sp)
  75. REG_S x17, PT_A7(sp)
  76. REG_S x18, PT_S2(sp)
  77. REG_S x19, PT_S3(sp)
  78. REG_S x20, PT_S4(sp)
  79. REG_S x21, PT_S5(sp)
  80. REG_S x22, PT_S6(sp)
  81. REG_S x23, PT_S7(sp)
  82. REG_S x24, PT_S8(sp)
  83. REG_S x25, PT_S9(sp)
  84. REG_S x26, PT_S10(sp)
  85. REG_S x27, PT_S11(sp)
  86. REG_S x28, PT_T3(sp)
  87. REG_S x29, PT_T4(sp)
  88. REG_S x30, PT_T5(sp)
  89. REG_S x31, PT_T6(sp)
  90. .endm
  91. .macro RESTORE_ALL
  92. REG_L x1, PT_RA(sp)
  93. addi sp, sp, PT_SIZE_ON_STACK
  94. REG_S x1, (sp)
  95. addi sp, sp, -PT_SIZE_ON_STACK
  96. REG_L x1, PT_EPC(sp)
  97. REG_L x2, PT_SP(sp)
  98. REG_L x3, PT_GP(sp)
  99. REG_L x4, PT_TP(sp)
  100. REG_L x5, PT_T0(sp)
  101. REG_L x6, PT_T1(sp)
  102. REG_L x7, PT_T2(sp)
  103. REG_L x8, PT_S0(sp)
  104. REG_L x9, PT_S1(sp)
  105. REG_L x10, PT_A0(sp)
  106. REG_L x11, PT_A1(sp)
  107. REG_L x12, PT_A2(sp)
  108. REG_L x13, PT_A3(sp)
  109. REG_L x14, PT_A4(sp)
  110. REG_L x15, PT_A5(sp)
  111. REG_L x16, PT_A6(sp)
  112. REG_L x17, PT_A7(sp)
  113. REG_L x18, PT_S2(sp)
  114. REG_L x19, PT_S3(sp)
  115. REG_L x20, PT_S4(sp)
  116. REG_L x21, PT_S5(sp)
  117. REG_L x22, PT_S6(sp)
  118. REG_L x23, PT_S7(sp)
  119. REG_L x24, PT_S8(sp)
  120. REG_L x25, PT_S9(sp)
  121. REG_L x26, PT_S10(sp)
  122. REG_L x27, PT_S11(sp)
  123. REG_L x28, PT_T3(sp)
  124. REG_L x29, PT_T4(sp)
  125. REG_L x30, PT_T5(sp)
  126. REG_L x31, PT_T6(sp)
  127. addi sp, sp, PT_SIZE_ON_STACK
  128. addi sp, sp, SZREG
  129. .endm
  130. #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
  131. ENTRY(ftrace_caller)
  132. SAVE_ABI
  133. addi a0, ra, -FENTRY_RA_OFFSET
  134. la a1, function_trace_op
  135. REG_L a2, 0(a1)
  136. REG_L a1, ABI_SIZE_ON_STACK(sp)
  137. mv a3, sp
  138. ftrace_call:
  139. .global ftrace_call
  140. call ftrace_stub
  141. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  142. addi a0, sp, ABI_SIZE_ON_STACK
  143. REG_L a1, ABI_RA(sp)
  144. addi a1, a1, -FENTRY_RA_OFFSET
  145. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  146. mv a2, s0
  147. #endif
  148. ftrace_graph_call:
  149. .global ftrace_graph_call
  150. call ftrace_stub
  151. #endif
  152. RESTORE_ABI
  153. ret
  154. ENDPROC(ftrace_caller)
  155. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  156. ENTRY(ftrace_regs_caller)
  157. SAVE_ALL
  158. addi a0, ra, -FENTRY_RA_OFFSET
  159. la a1, function_trace_op
  160. REG_L a2, 0(a1)
  161. REG_L a1, PT_SIZE_ON_STACK(sp)
  162. mv a3, sp
  163. ftrace_regs_call:
  164. .global ftrace_regs_call
  165. call ftrace_stub
  166. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  167. addi a0, sp, PT_RA
  168. REG_L a1, PT_EPC(sp)
  169. addi a1, a1, -FENTRY_RA_OFFSET
  170. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  171. mv a2, s0
  172. #endif
  173. ftrace_graph_regs_call:
  174. .global ftrace_graph_regs_call
  175. call ftrace_stub
  176. #endif
  177. RESTORE_ALL
  178. ret
  179. ENDPROC(ftrace_regs_caller)
  180. #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */