1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2017 Andes Technology Corporation */
4 #include <linux/init.h>
5 #include <linux/linkage.h>
6 #include <linux/cfi_types.h>
9 #include <asm/unistd.h>
10 #include <asm/thread_info.h>
11 #include <asm/asm-offsets.h>
12 #include <asm-generic/export.h>
13 #include <asm/ftrace.h>
25 * The call to ftrace_return_to_handler would overwrite the return
26 * register if a0 was not saved.
28 .macro SAVE_RET_ABI_STATE
37 .macro RESTORE_ABI_STATE
43 .macro RESTORE_RET_ABI_STATE
51 SYM_TYPED_FUNC_START(ftrace_stub)
52 #ifdef CONFIG_DYNAMIC_FTRACE
54 .set MCOUNT_NAME, ftrace_stub
57 SYM_FUNC_END(ftrace_stub)
59 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60 ENTRY(return_to_handler)
62 * On implementing the frame point test, the ideal way is to compare the
63 * s0 (frame pointer, if enabled) on entry and the sp (stack pointer) on return.
64 * However, the psABI of variable-length-argument functions does not allow this.
66 * So alternatively we check the *old* frame pointer position, that is, the
67 * value stored in -16(s0) on entry, and the s0 on return.
71 call ftrace_return_to_handler
75 ENDPROC(return_to_handler)
78 #ifndef CONFIG_DYNAMIC_FTRACE
81 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
82 la t0, ftrace_graph_return
84 bne t1, t4, do_ftrace_graph_caller
86 la t3, ftrace_graph_entry
88 la t6, ftrace_graph_entry_stub
89 bne t2, t6, do_ftrace_graph_caller
91 la t3, ftrace_trace_function
96 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
98 * A pseudo representation for the function graph tracer:
99 * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
101 do_ftrace_graph_caller:
104 #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
105 REG_L a2, -2*SZREG(s0)
108 call prepare_ftrace_return
114 * A pseudo representation for the function tracer:
115 * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
127 EXPORT_SYMBOL(MCOUNT_NAME)