2 * MIPS specific _mcount support
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
8 * Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China
9 * Author: Wu Zhangjin <wuzhangjin@gmail.com>
12 #include <asm/regdef.h>
13 #include <asm/stackframe.h>
14 #include <asm/ftrace.h>
20 .macro MCOUNT_SAVE_REGS
36 .macro MCOUNT_RESTORE_REGS
52 PTR_ADDIU sp, (PT_SIZE + 8)
61 #ifdef CONFIG_DYNAMIC_FTRACE
63 NESTED(ftrace_caller, PT_SIZE, ra)
68 lw t1, function_trace_stop
73 #ifdef KBUILD_MCOUNT_RA_ADDRESS
74 PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
77 move a0, ra /* arg1: next ip, selfaddr */
80 nop /* a placeholder for the call to a real tracing function */
81 move a1, AT /* arg2: the caller's next ip, parent */
83 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84 .globl ftrace_graph_call
96 #else /* ! CONFIG_DYNAMIC_FTRACE */
98 NESTED(_mcount, PT_SIZE, ra)
99 lw t1, function_trace_stop
102 PTR_LA t1, ftrace_stub
103 PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
104 bne t1, t2, static_trace
107 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
108 PTR_L t3, ftrace_graph_return
109 bne t1, t3, ftrace_graph_caller
111 PTR_LA t1, ftrace_graph_entry_stub
112 PTR_L t3, ftrace_graph_entry
113 bne t1, t3, ftrace_graph_caller
122 move a0, ra /* arg1: next ip, selfaddr */
123 jalr t2 /* (1) call *ftrace_trace_function */
124 move a1, AT /* arg2: the caller's next ip, parent */
132 #endif /* ! CONFIG_DYNAMIC_FTRACE */
134 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
136 NESTED(ftrace_graph_caller, PT_SIZE, ra)
137 #ifdef CONFIG_DYNAMIC_FTRACE
138 PTR_L a1, PT_R31(sp) /* load the original ra from the stack */
139 #ifdef KBUILD_MCOUNT_RA_ADDRESS
140 PTR_L t0, PT_R12(sp) /* load the original t0 from the stack */
144 move a1, ra /* arg2: next ip, selfaddr */
147 #ifdef KBUILD_MCOUNT_RA_ADDRESS
148 bnez t0, 1f /* non-leaf func: t0 saved the location of the return address */
150 PTR_LA t0, PT_R1(sp) /* leaf func: get the location of at(old ra) from our own stack */
151 1: move a0, t0 /* arg1: the location of the return address */
153 PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */
155 jal prepare_ftrace_return
156 #ifdef CONFIG_FRAME_POINTER
157 move a2, fp /* arg3: frame pointer */
160 PTR_LA a2, PT_SIZE(sp)
162 PTR_LA a2, (PT_SIZE+8)(sp)
168 END(ftrace_graph_caller)
171 .globl return_to_handler
176 jal ftrace_return_to_handler
179 /* restore the real parent address: v0 -> ra */
185 PTR_ADDIU sp, PT_SIZE
186 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */