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
60 * The -mmcount-ra-address option of gcc 4.5 uses register $12 to pass
61 * the location of the parent's return address.
63 #define MCOUNT_RA_ADDRESS_REG $12
65 #ifdef CONFIG_DYNAMIC_FTRACE
67 NESTED(ftrace_caller, PT_SIZE, ra)
73 /* When tracing is activated, it calls ftrace_caller+8 (aka here) */
74 lw t1, function_trace_stop
79 #ifdef KBUILD_MCOUNT_RA_ADDRESS
80 PTR_S MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
83 move a0, ra /* arg1: self return address */
86 nop /* a placeholder for the call to a real tracing function */
87 move a1, AT /* arg2: parent's return address */
89 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90 .globl ftrace_graph_call
102 #else /* ! CONFIG_DYNAMIC_FTRACE */
104 NESTED(_mcount, PT_SIZE, ra)
105 lw t1, function_trace_stop
108 PTR_LA t1, ftrace_stub
109 PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
110 bne t1, t2, static_trace
113 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
114 PTR_L t3, ftrace_graph_return
115 bne t1, t3, ftrace_graph_caller
117 PTR_LA t1, ftrace_graph_entry_stub
118 PTR_L t3, ftrace_graph_entry
119 bne t1, t3, ftrace_graph_caller
128 move a0, ra /* arg1: self return address */
129 jalr t2 /* (1) call *ftrace_trace_function */
130 move a1, AT /* arg2: parent's return address */
138 #endif /* ! CONFIG_DYNAMIC_FTRACE */
140 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
142 NESTED(ftrace_graph_caller, PT_SIZE, ra)
143 #ifndef CONFIG_DYNAMIC_FTRACE
147 /* arg1: Get the location of the parent's return address */
148 #ifdef KBUILD_MCOUNT_RA_ADDRESS
149 #ifdef CONFIG_DYNAMIC_FTRACE
152 move a0, MCOUNT_RA_ADDRESS_REG
154 bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
157 PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
160 /* arg2: Get self return address */
161 #ifdef CONFIG_DYNAMIC_FTRACE
167 /* arg3: Get frame pointer of current stack */
168 #ifdef CONFIG_FRAME_POINTER
170 #else /* ! CONFIG_FRAME_POINTER */
172 PTR_LA a2, PT_SIZE(sp)
174 PTR_LA a2, (PT_SIZE+8)(sp)
178 jal prepare_ftrace_return
182 END(ftrace_graph_caller)
185 .globl return_to_handler
190 jal ftrace_return_to_handler
193 /* restore the real parent address: v0 -> ra */
199 PTR_ADDIU sp, PT_SIZE
200 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */