]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/sparc/lib/mcount.S
sparc64: Add HAVE_FUNCTION_TRACE_MCOUNT_TEST and tidy up.
[net-next-2.6.git] / arch / sparc / lib / mcount.S
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com)
3 *
4 * This file implements mcount(), which is used to collect profiling data.
5 * This can also be tweaked for kernel stack overflow detection.
6 */
7
1da177e4
LT
8#include <linux/linkage.h>
9
10#include <asm/ptrace.h>
11#include <asm/thread_info.h>
12
13/*
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.
16 */
17
18#ifdef CONFIG_STACK_DEBUG
19
20#define OVSTACKSIZE 4096 /* lets hope this is enough */
21
22 .data
23 .align 8
24panicstring:
25 .asciz "Stack overflow\n"
26 .align 8
27ovstack:
28 .skip OVSTACKSIZE
29#endif
30 .text
d05f5f99
DM
31 .align 32
32 .globl _mcount
33 .type _mcount,#function
34 .globl mcount
35 .type mcount,#function
1da177e4 36_mcount:
d05f5f99 37mcount:
1da177e4
LT
38#ifdef CONFIG_STACK_DEBUG
39 /*
40 * Check whether %sp is dangerously low.
41 */
42 ldub [%g6 + TI_FPDEPTH], %g1
43 srl %g1, 1, %g3
44 add %g3, 1, %g3
45 sllx %g3, 8, %g3 ! each fpregs frame is 256b
46 add %g3, 192, %g3
47 add %g6, %g3, %g3 ! where does task_struct+frame end?
48 sub %g3, STACK_BIAS, %g3
49 cmp %sp, %g3
50 bg,pt %xcc, 1f
c7498081 51 nop
4f70f7a9
DM
52 lduh [%g6 + TI_CPU], %g1
53 sethi %hi(hardirq_stack), %g3
54 or %g3, %lo(hardirq_stack), %g3
55 sllx %g1, 3, %g1
56 ldx [%g3 + %g1], %g7
57 sub %g7, STACK_BIAS, %g7
58 cmp %sp, %g7
59 bleu,pt %xcc, 2f
60 sethi %hi(THREAD_SIZE), %g3
61 add %g7, %g3, %g7
62 cmp %sp, %g7
63 blu,pn %xcc, 1f
642: sethi %hi(softirq_stack), %g3
65 or %g3, %lo(softirq_stack), %g3
66 ldx [%g3 + %g1], %g7
166e553a 67 sub %g7, STACK_BIAS, %g7
4f70f7a9 68 cmp %sp, %g7
166e553a 69 bleu,pt %xcc, 3f
4f70f7a9
DM
70 sethi %hi(THREAD_SIZE), %g3
71 add %g7, %g3, %g7
72 cmp %sp, %g7
73 blu,pn %xcc, 1f
74 nop
c7498081
DM
75 /* If we are already on ovstack, don't hop onto it
76 * again, we are already trying to output the stack overflow
77 * message.
78 */
166e553a 793: sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
1da177e4 80 or %g7, %lo(ovstack), %g7
c7498081
DM
81 add %g7, OVSTACKSIZE, %g3
82 sub %g3, STACK_BIAS + 192, %g3
1da177e4 83 sub %g7, STACK_BIAS, %g7
c7498081
DM
84 cmp %sp, %g7
85 blu,pn %xcc, 2f
86 cmp %sp, %g3
87 bleu,pn %xcc, 1f
88 nop
892: mov %g3, %sp
90 sethi %hi(panicstring), %g3
1da177e4
LT
91 call prom_printf
92 or %g3, %lo(panicstring), %o0
93 call prom_halt
94 nop
d05f5f99
DM
951:
96#endif
606576ce 97#ifdef CONFIG_FUNCTION_TRACER
d05f5f99 98#ifdef CONFIG_DYNAMIC_FTRACE
63b75495 99 /* Do nothing, the retl/nop below is all we need. */
d05f5f99 100#else
63b75495
DM
101 sethi %hi(function_trace_stop), %g1
102 lduw [%g1 + %lo(function_trace_stop)], %g2
103 brnz,pn %g2, 1f
104 sethi %hi(ftrace_trace_function), %g1
d05f5f99
DM
105 sethi %hi(ftrace_stub), %g2
106 ldx [%g1 + %lo(ftrace_trace_function)], %g1
107 or %g2, %lo(ftrace_stub), %g2
108 cmp %g1, %g2
109 be,pn %icc, 1f
110 mov %i7, %o1
111 jmpl %g1, %g0
112 mov %o7, %o0
113 /* not reached */
1141:
1da177e4 115#endif
d05f5f99
DM
116#endif
117 retl
1da177e4 118 nop
d05f5f99
DM
119 .size _mcount,.-_mcount
120 .size mcount,.-mcount
121
606576ce 122#ifdef CONFIG_FUNCTION_TRACER
d05f5f99
DM
123 .globl ftrace_stub
124 .type ftrace_stub,#function
125ftrace_stub:
126 retl
127 nop
128 .size ftrace_stub,.-ftrace_stub
129#ifdef CONFIG_DYNAMIC_FTRACE
130 .globl ftrace_caller
131 .type ftrace_caller,#function
132ftrace_caller:
63b75495 133 sethi %hi(function_trace_stop), %g1
d05f5f99 134 mov %i7, %o1
63b75495
DM
135 lduw [%g1 + %lo(function_trace_stop)], %g2
136 brnz,pn %g2, ftrace_stub
137 mov %o7, %o0
d05f5f99
DM
138 .globl ftrace_call
139ftrace_call:
63b75495
DM
140 /* If the final kernel link ever turns on relaxation, we'll need
141 * to do something about this tail call. Otherwise the linker
142 * will rewrite the call into a branch and nop out the move
143 * instruction.
144 */
d05f5f99
DM
145 call ftrace_stub
146 mov %o0, %o7
147 retl
148 nop
63b75495 149 .size ftrace_call,.-ftrace_call
d05f5f99
DM
150 .size ftrace_caller,.-ftrace_caller
151#endif
152#endif