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
50 PTR_ADDIU sp, (PT_SIZE + 8)
59 #ifdef CONFIG_DYNAMIC_FTRACE
61 NESTED(ftrace_caller, PT_SIZE, ra)
66 lw t1, function_trace_stop
71 #ifdef KBUILD_MCOUNT_RA_ADDRESS
72 PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
75 move a0, ra /* arg1: next ip, selfaddr */
78 nop /* a placeholder for the call to a real tracing function */
79 move a1, AT /* arg2: the caller's next ip, parent */
81 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
82 .globl ftrace_graph_call
94 #else /* ! CONFIG_DYNAMIC_FTRACE */
96 NESTED(_mcount, PT_SIZE, ra)
97 lw t1, function_trace_stop
100 PTR_LA t1, ftrace_stub
101 PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
102 bne t1, t2, static_trace
105 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
106 PTR_L t3, ftrace_graph_return
107 bne t1, t3, ftrace_graph_caller
109 PTR_LA t1, ftrace_graph_entry_stub
110 PTR_L t3, ftrace_graph_entry
111 bne t1, t3, ftrace_graph_caller
120 move a0, ra /* arg1: next ip, selfaddr */
121 jalr t2 /* (1) call *ftrace_trace_function */
122 move a1, AT /* arg2: the caller's next ip, parent */
130 #endif /* ! CONFIG_DYNAMIC_FTRACE */
132 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
134 NESTED(ftrace_graph_caller, PT_SIZE, ra)
135 #ifndef CONFIG_DYNAMIC_FTRACE
139 /* arg1: Get the location of the parent's return address */
140 #ifdef KBUILD_MCOUNT_RA_ADDRESS
141 #ifdef CONFIG_DYNAMIC_FTRACE
146 bnez a0, 1f /* non-leaf func: stored in t0 */
149 PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
152 /* arg2: Get self return address */
153 #ifdef CONFIG_DYNAMIC_FTRACE
159 /* arg3: Get frame pointer of current stack */
160 #ifdef CONFIG_FRAME_POINTER
162 #else /* ! CONFIG_FRAME_POINTER */
164 PTR_LA a2, PT_SIZE(sp)
166 PTR_LA a2, (PT_SIZE+8)(sp)
170 jal prepare_ftrace_return
174 END(ftrace_graph_caller)
177 .globl return_to_handler
182 jal ftrace_return_to_handler
185 /* restore the real parent address: v0 -> ra */
191 PTR_ADDIU sp, PT_SIZE
192 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */