Merge branch 'core/topology' of git://git.kernel.org/pub/scm/linux/kernel/git/tip...
[pandora-kernel.git] / arch / sparc64 / lib / mcount.S
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
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
24 panicstring:
25         .asciz          "Stack overflow\n"
26         .align          8
27 ovstack:
28         .skip           OVSTACKSIZE
29 #endif
30         .text
31         .align          32
32         .globl          _mcount
33         .type           _mcount,#function
34         .globl          mcount
35         .type           mcount,#function
36 _mcount:
37 mcount:
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
51          sethi          %hi(panicstring), %g3
52         sethi           %hi(ovstack), %g7               ! cant move to panic stack fast enough
53          or             %g7, %lo(ovstack), %g7
54         add             %g7, OVSTACKSIZE, %g7
55         sub             %g7, STACK_BIAS, %g7
56         mov             %g7, %sp
57         call            prom_printf
58          or             %g3, %lo(panicstring), %o0
59         call            prom_halt
60          nop
61 1:
62 #endif
63 #ifdef CONFIG_FTRACE
64 #ifdef CONFIG_DYNAMIC_FTRACE
65         mov             %o7, %o0
66         .globl          mcount_call
67 mcount_call:
68         call            ftrace_stub
69          mov            %o0, %o7
70 #else
71         sethi           %hi(ftrace_trace_function), %g1
72         sethi           %hi(ftrace_stub), %g2
73         ldx             [%g1 + %lo(ftrace_trace_function)], %g1
74         or              %g2, %lo(ftrace_stub), %g2
75         cmp             %g1, %g2
76         be,pn           %icc, 1f
77          mov            %i7, %o1
78         jmpl            %g1, %g0
79          mov            %o7, %o0
80         /* not reached */
81 1:
82 #endif
83 #endif
84         retl
85          nop
86         .size           _mcount,.-_mcount
87         .size           mcount,.-mcount
88
89 #ifdef CONFIG_FTRACE
90         .globl          ftrace_stub
91         .type           ftrace_stub,#function
92 ftrace_stub:
93         retl
94          nop
95         .size           ftrace_stub,.-ftrace_stub
96 #ifdef CONFIG_DYNAMIC_FTRACE
97         .globl          ftrace_caller
98         .type           ftrace_caller,#function
99 ftrace_caller:
100         mov             %i7, %o1
101         mov             %o7, %o0
102         .globl          ftrace_call
103 ftrace_call:
104         call            ftrace_stub
105          mov            %o0, %o7
106         retl
107          nop
108         .size           ftrace_caller,.-ftrace_caller
109 #endif
110 #endif