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 * Copyright (C) 2010 DSLab, Lanzhou University, China
10 * Author: Wu Zhangjin <wuzhangjin@gmail.com>
13 #include <asm/regdef.h>
14 #include <asm/stackframe.h>
15 #include <asm/ftrace.h>
21 .macro MCOUNT_SAVE_REGS
37 .macro MCOUNT_RESTORE_REGS
51 PTR_ADDIU sp, (PT_SIZE + 8)
60 #ifdef CONFIG_DYNAMIC_FTRACE
62 NESTED(ftrace_caller, PT_SIZE, ra)
67 lw t1, function_trace_stop
72 #ifdef KBUILD_MCOUNT_RA_ADDRESS
73 PTR_S t0, PT_R12(sp) /* save location of parent's return address */
76 move a0, ra /* arg1: self return address */
79 nop /* a placeholder for the call to a real tracing function */
80 move a1, AT /* arg2: parent's return address */
82 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
83 .globl ftrace_graph_call
95 #else /* ! CONFIG_DYNAMIC_FTRACE */
97 NESTED(_mcount, PT_SIZE, ra)
98 lw t1, function_trace_stop
101 PTR_LA t1, ftrace_stub
102 PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
103 bne t1, t2, static_trace
106 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
107 PTR_L t3, ftrace_graph_return
108 bne t1, t3, ftrace_graph_caller
110 PTR_LA t1, ftrace_graph_entry_stub
111 PTR_L t3, ftrace_graph_entry
112 bne t1, t3, ftrace_graph_caller
121 move a0, ra /* arg1: self return address */
122 jalr t2 /* (1) call *ftrace_trace_function */
123 move a1, AT /* arg2: parent's return address */
131 #endif /* ! CONFIG_DYNAMIC_FTRACE */
133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
135 NESTED(ftrace_graph_caller, PT_SIZE, ra)
136 #ifndef CONFIG_DYNAMIC_FTRACE
140 /* arg1: Get the location of the parent's return address */
141 #ifdef KBUILD_MCOUNT_RA_ADDRESS
142 #ifdef CONFIG_DYNAMIC_FTRACE
147 bnez a0, 1f /* non-leaf func: stored in t0 */
150 PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
153 /* arg2: Get self return address */
154 #ifdef CONFIG_DYNAMIC_FTRACE
160 /* arg3: Get frame pointer of current stack */
161 #ifdef CONFIG_FRAME_POINTER
163 #else /* ! CONFIG_FRAME_POINTER */
165 PTR_LA a2, PT_SIZE(sp)
167 PTR_LA a2, (PT_SIZE+8)(sp)
171 jal prepare_ftrace_return
175 END(ftrace_graph_caller)
178 .globl return_to_handler
183 jal ftrace_return_to_handler
186 /* restore the real parent address: v0 -> ra */
192 PTR_ADDIU sp, PT_SIZE
193 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */