2 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com)
4 * This file implements mcount(), which is used to collect profiling data.
5 * This can also be tweaked for kernel stack overflow detection.
8 #include <linux/linkage.h>
10 #include <asm/ptrace.h>
11 #include <asm/thread_info.h>
14 * This is the main variant and is called by C code. GCC's -pg option
15 * automatically instruments every C function with a call to this.
18 #ifdef CONFIG_STACK_DEBUG
20 #define OVSTACKSIZE 4096 /* lets hope this is enough */
25 .asciz "Stack overflow\n"
33 .type _mcount,#function
35 .type mcount,#function
38 #ifdef CONFIG_STACK_DEBUG
40 * Check whether %sp is dangerously low.
42 ldub [%g6 + TI_FPDEPTH], %g1
45 sllx %g3, 8, %g3 ! each fpregs frame is 256b
47 add %g6, %g3, %g3 ! where does task_struct+frame end?
48 sub %g3, STACK_BIAS, %g3
52 lduh [%g6 + TI_CPU], %g1
53 sethi %hi(hardirq_stack), %g3
54 or %g3, %lo(hardirq_stack), %g3
57 sub %g7, STACK_BIAS, %g7
60 sethi %hi(THREAD_SIZE), %g3
64 2: sethi %hi(softirq_stack), %g3
65 or %g3, %lo(softirq_stack), %g3
67 sub %g7, STACK_BIAS, %g7
70 sethi %hi(THREAD_SIZE), %g3
75 /* If we are already on ovstack, don't hop onto it
76 * again, we are already trying to output the stack overflow
79 3: sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
80 or %g7, %lo(ovstack), %g7
81 add %g7, OVSTACKSIZE, %g3
82 sub %g3, STACK_BIAS + 192, %g3
83 sub %g7, STACK_BIAS, %g7
90 sethi %hi(panicstring), %g3
92 or %g3, %lo(panicstring), %o0
97 #ifdef CONFIG_FUNCTION_TRACER
98 #ifdef CONFIG_DYNAMIC_FTRACE
105 sethi %hi(ftrace_trace_function), %g1
106 sethi %hi(ftrace_stub), %g2
107 ldx [%g1 + %lo(ftrace_trace_function)], %g1
108 or %g2, %lo(ftrace_stub), %g2
120 .size _mcount,.-_mcount
121 .size mcount,.-mcount
123 #ifdef CONFIG_FUNCTION_TRACER
125 .type ftrace_stub,#function
129 .size ftrace_stub,.-ftrace_stub
130 #ifdef CONFIG_DYNAMIC_FTRACE
132 .type ftrace_caller,#function
142 .size ftrace_caller,.-ftrace_caller