1 /* SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2008, 2009 Paul Mundt
6 * Copyright (C) 2008, 2009 Matt Fleming
8 #include <asm/ftrace.h>
9 #include <asm/thread_info.h>
10 #include <asm/asm-offsets.h>
12 #define MCOUNT_ENTER() \
22 #define MCOUNT_LEAVE() \
30 #ifdef CONFIG_STACK_DEBUG
32 * Perform diagnostic checks on the state of the kernel stack.
34 * Check for stack overflow. If there is less than 1KB free
35 * then it has overflowed.
37 * Make sure the stack pointer contains a valid address. Valid
38 * addresses for kernel stacks are anywhere after the bss
39 * (after __bss_stop) and anywhere in init_thread_union (init_stack).
41 #define STACK_CHECK() \
42 mov #(THREAD_SIZE >> 10), r0; \
46 /* r1 = sp & (THREAD_SIZE - 1) */ \
52 mov #(STACK_WARN >> 8), r2; \
56 /* Is the stack overflowing? */ \
60 /* If sp > __bss_stop then we're OK. */ \
65 /* If sp < init_stack, we're not OK. */ \
66 mov.l .L_init_thread_union, r1; \
70 /* If sp > init_stack && sp < __bss_stop, not OK. */ \
77 #endif /* CONFIG_STACK_DEBUG */
81 .type _mcount,@function
83 .type mcount,@function
88 #ifndef CONFIG_FUNCTION_TRACER
94 #ifdef CONFIG_DYNAMIC_FTRACE
97 mov.l .Lftrace_stub, r6
99 mov.l .Lftrace_trace_function, r6
100 mov.l ftrace_stub, r7
109 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
110 mov.l .Lftrace_graph_return, r6
111 mov.l .Lftrace_stub, r7
115 mov.l .Lftrace_graph_caller, r0
120 mov.l .Lftrace_graph_entry, r6
121 mov.l .Lftrace_graph_entry_stub, r7
125 mov.l .Lftrace_graph_caller, r0
130 .Lftrace_graph_return:
131 .long ftrace_graph_return
132 .Lftrace_graph_entry:
133 .long ftrace_graph_entry
134 .Lftrace_graph_entry_stub:
135 .long ftrace_graph_entry_stub
136 .Lftrace_graph_caller:
137 .long ftrace_graph_caller
138 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
145 .Lftrace_trace_function:
146 .long ftrace_trace_function
148 #ifdef CONFIG_DYNAMIC_FTRACE
149 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
151 * NOTE: Do not move either ftrace_graph_call or ftrace_caller
152 * as this will affect the calculation of GRAPH_INSN_OFFSET.
154 .globl ftrace_graph_call
156 mov.l .Lskip_trace, r0
163 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
171 mov.l .Lftrace_stub, r6
175 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
176 bra ftrace_graph_call
180 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
181 #endif /* CONFIG_DYNAMIC_FTRACE */
186 * NOTE: From here on the locations of the .Lftrace_stub label and
187 * ftrace_stub itself are fixed. Adding additional data here will skew
188 * the displacement for the memory table and break the block replacement.
189 * Place new labels either after the ftrace_stub body, or before
190 * ftrace_caller. You have been warned.
200 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
201 .globl ftrace_graph_caller
208 * MCOUNT_ENTER() pushed 5 registers onto the stack, so
209 * the stack address containing our return address is
216 mov.l .Lprepare_ftrace_return, r0
224 .Lprepare_ftrace_return:
225 .long prepare_ftrace_return
227 .globl return_to_handler
230 * Save the return values.
237 mov.l .Lftrace_return_to_handler, r0
242 * The return value from ftrace_return_handler has the real
243 * address that we should return to.
252 .Lftrace_return_to_handler:
253 .long ftrace_return_to_handler
254 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
255 #endif /* CONFIG_FUNCTION_TRACER */
257 #ifdef CONFIG_STACK_DEBUG
260 mov.l .Ldump_stack, r0
272 .L_init_thread_union:
273 .long init_thread_union
286 .string "Stack error"
287 #endif /* CONFIG_STACK_DEBUG */