8282* +++++++++
8383**/
8484 .macro SAVE_ABI_REGS
85- mv t4, sp // Save original SP in T4
8685 addi sp , sp , -FREGS_SIZE_ON_STACK
87-
8886 REG_S t0, FREGS_EPC(sp )
8987 REG_S x1, FREGS_RA(sp )
90- REG_S t4, FREGS_SP(sp ) // Put original SP on stack
9188#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
9289 REG_S x8, FREGS_S0(sp )
9390#endif
108105 REG_S x15, FREGS_A5(sp )
109106 REG_S x16, FREGS_A6(sp )
110107 REG_S x17, FREGS_A7(sp )
108+ mv a0 , sp
109+ addi a0 , a0 , FREGS_SIZE_ON_STACK
110+ REG_S a0 , FREGS_SP(sp ) // Put original SP on stack
111111 .endm
112112
113- .macro RESTORE_ABI_REGS, all= 0
113+ .macro RESTORE_ABI_REGS
114114 REG_L t0, FREGS_EPC(sp )
115115 REG_L x1, FREGS_RA(sp )
116116#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
139139
140140 .macro PREPARE_ARGS
141141 addi a0 , t0, -MCOUNT_JALR_SIZE // ip (callsite's jalr insn)
142+ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS
143+ mv a1 , ra // parent_ip
144+ REG_L a2 , -16 (t0) // op
145+ REG_L ra, FTRACE_OPS_FUNC(a2 ) // op->func
146+ #else
147+ la a1 , function_trace_op
148+ REG_L a2 , 0 (a1 ) // op
149+ mv a1 , ra // parent_ip
150+ #endif
151+ mv a3 , sp // regs
152+ .endm
153+
154+ SYM_FUNC_START (ftrace_caller)
142155#ifdef CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS
143156 /*
144157 * When CALL_OPS is enabled (2 or 4) nops [8B] are placed before the
158171 * t0 is set to ip+8 after the jalr is executed at the callsite,
159172 * so we find the associated op at t0-16.
160173 */
161- mv a1 , ra // parent_ip
162- REG_L a2 , -16 (t0) // op
163- REG_L ra, FTRACE_OPS_FUNC(a2 ) // op->func
164- #else
165- la a1 , function_trace_op
166- REG_L a2 , 0 (a1 ) // op
167- mv a1 , ra // parent_ip
168- #endif
169- mv a3 , sp // regs
170- .endm
174+ REG_L t1, -16 (t0) // op Should be SZ_REG instead of 16
171175
172- SYM_FUNC_START (ftrace_caller)
173- mv t1, zero
176+ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
177+ /*
178+ * If the op has a direct call, handle it immediately without
179+ * saving/restoring registers.
180+ */
181+ REG_L t1, FTRACE_OPS_DIRECT_CALL(t1)
182+ bnez t1, ftrace_caller_direct
183+ #endif
184+ #endif
174185 SAVE_ABI_REGS
175186 PREPARE_ARGS
176187
@@ -182,10 +193,14 @@ SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
182193 jalr ra, 0 (ra)
183194#endif
184195 RESTORE_ABI_REGS
185- bnez t1, .Ldirect
196+ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
197+ bnez t1, ftrace_caller_direct
198+ #endif
186199 jr t0
187- .Ldirect:
200+ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
201+ SYM_INNER_LABEL (ftrace_caller_direct, SYM_L_LOCAL)
188202 jr t1
203+ #endif
189204SYM_FUNC_END (ftrace_caller)
190205
191206#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
0 commit comments