2 * mcount and friends -- ftrace stuff
4 * Copyright (C) 2009-2010 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
8 #include <linux/linkage.h>
9 #include <asm/ftrace.h>
13 /* GCC will have called us before setting up the function prologue, so we
14 * can clobber the normal scratch registers, but we need to make sure to
15 * save/restore the registers used for argument passing (R0-R2) in case
16 * the profiled function is using them. With data registers, R3 is the
17 * only one we can blow away. With pointer registers, we have P0-P2.
19 * Upon entry, the RETS will point to the top of the current profiled
20 * function. And since GCC pushed the previous RETS for us, the previous
21 * function will be waiting there. mmmm pie.
24 #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
25 /* optional micro optimization: return if stopped */
26 p1.l = _function_trace_stop;
27 p1.h = _function_trace_stop;
30 if ! cc jump _ftrace_stub (bp);
33 /* save third function arg early so we can do testing below */
36 /* load the function pointer to the tracer */
37 p0.l = _ftrace_trace_function;
38 p0.h = _ftrace_trace_function;
41 /* optional micro optimization: don't call the stub tracer */
45 if ! cc jump .Ldo_trace;
47 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
48 /* if the ftrace_graph_return function pointer is not set to
49 * the ftrace_stub entry, call prepare_ftrace_return().
51 p0.l = _ftrace_graph_return;
52 p0.h = _ftrace_graph_return;
55 if ! cc jump _ftrace_graph_caller;
57 /* similarly, if the ftrace_graph_entry function pointer is not
58 * set to the ftrace_graph_entry_stub entry, ...
60 p0.l = _ftrace_graph_entry;
61 p0.h = _ftrace_graph_entry;
62 r2.l = _ftrace_graph_entry_stub;
63 r2.h = _ftrace_graph_entry_stub;
66 if ! cc jump _ftrace_graph_caller;
74 /* save first/second function arg and the return register */
79 /* setup the tracer function */
82 /* function_trace_call(unsigned long ip, unsigned long parent_ip):
83 * ip: this point was called by ...
84 * parent_ip: ... this function
85 * the ip itself will need adjusting for the mcount call
88 r1 = [sp + 16]; /* skip the 4 local regs on stack */
89 r0 += -MCOUNT_INSN_SIZE;
94 /* restore state and get out of dodge */
106 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
107 /* The prepare_ftrace_return() function is similar to the trace function
108 * except it takes a pointer to the location of the frompc. This is so
109 * the prepare_ftrace_return() can hijack it temporarily for probing
112 ENTRY(_ftrace_graph_caller)
113 /* save first/second function arg and the return register */
118 /* prepare_ftrace_return(parent, self_addr, frame_pointer) */
119 r0 = sp; /* unsigned long *parent */
120 r1 = rets; /* unsigned long self_addr */
121 #ifdef CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST
122 r2 = fp; /* unsigned long frame_pointer */
124 r0 += 16; /* skip the 4 local regs on stack */
125 r1 += -MCOUNT_INSN_SIZE;
126 call _prepare_ftrace_return;
129 ENDPROC(_ftrace_graph_caller)
131 /* Undo the rewrite caused by ftrace_graph_caller(). The common function
132 * ftrace_return_to_handler() will return the original rets so we can
133 * restore it and be on our way.
135 ENTRY(_return_to_handler)
136 /* make sure original return values are saved */
141 /* get original return address */
142 #ifdef CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST
143 r0 = fp; /* Blackfin is sane, so omit this */
145 call _ftrace_return_to_handler;
148 /* anomaly 05000371 - make sure we have at least three instructions
149 * between rets setting and the return
155 ENDPROC(_return_to_handler)