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)
61 * The -mmcount-ra-address option of gcc 4.5 uses register $12 to pass
62 * the location of the parent's return address.
64 #define MCOUNT_RA_ADDRESS_REG $12
66 #ifdef CONFIG_DYNAMIC_FTRACE
68 NESTED(ftrace_caller, PT_SIZE, ra)
73 lw t1, function_trace_stop
78 #ifdef KBUILD_MCOUNT_RA_ADDRESS
79 PTR_S MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
82 move a0, ra /* arg1: self return address */
85 nop /* a placeholder for the call to a real tracing function */
86 move a1, AT /* arg2: parent's return address */
88 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89 .globl ftrace_graph_call
101 #else /* ! CONFIG_DYNAMIC_FTRACE */
103 NESTED(_mcount, PT_SIZE, ra)
104 lw t1, function_trace_stop
107 PTR_LA t1, ftrace_stub
108 PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */
109 bne t1, t2, static_trace
112 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
113 PTR_L t3, ftrace_graph_return
114 bne t1, t3, ftrace_graph_caller
116 PTR_LA t1, ftrace_graph_entry_stub
117 PTR_L t3, ftrace_graph_entry
118 bne t1, t3, ftrace_graph_caller
131 move a0, ra /* arg1: self return address */
132 jalr t2 /* (1) call *ftrace_trace_function */
133 move a1, AT /* arg2: parent's return address */
144 #endif /* ! CONFIG_DYNAMIC_FTRACE */
146 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
148 NESTED(ftrace_graph_caller, PT_SIZE, ra)
149 #ifndef CONFIG_DYNAMIC_FTRACE
153 /* arg1: Get the location of the parent's return address */
154 #ifdef KBUILD_MCOUNT_RA_ADDRESS
155 #ifdef CONFIG_DYNAMIC_FTRACE
158 move a0, MCOUNT_RA_ADDRESS_REG
160 bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */
163 PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */
166 /* arg2: Get self return address */
167 #ifdef CONFIG_DYNAMIC_FTRACE
173 /* arg3: Get frame pointer of current stack */
174 #ifdef CONFIG_FRAME_POINTER
176 #else /* ! CONFIG_FRAME_POINTER */
178 PTR_LA a2, PT_SIZE(sp)
180 PTR_LA a2, (PT_SIZE+8)(sp)
184 jal prepare_ftrace_return
187 #ifndef CONFIG_DYNAMIC_FTRACE
193 END(ftrace_graph_caller)
196 .globl return_to_handler
201 jal ftrace_return_to_handler
204 /* restore the real parent address: v0 -> ra */
210 PTR_ADDIU sp, PT_SIZE
211 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */