blob: 3ad6cbdc21636f51c1853c2ab604d2dc692727db [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/linkage.h>
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010/*
11 * This is the main variant and is called by C code. GCC's -pg option
12 * automatically instruments every C function with a call to this.
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 .text
David Millerd05f5f92008-05-13 22:06:59 -070016 .align 32
17 .globl _mcount
18 .type _mcount,#function
19 .globl mcount
20 .type mcount,#function
Linus Torvalds1da177e2005-04-16 15:20:36 -070021_mcount:
David Millerd05f5f92008-05-13 22:06:59 -070022mcount:
Steven Rostedt606576c2008-10-06 19:06:12 -040023#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070024#ifdef CONFIG_DYNAMIC_FTRACE
David S. Miller63b75492010-04-12 22:35:24 -070025 /* Do nothing, the retl/nop below is all we need. */
David Millerd05f5f92008-05-13 22:06:59 -070026#else
David S. Miller63b75492010-04-12 22:35:24 -070027 sethi %hi(function_trace_stop), %g1
28 lduw [%g1 + %lo(function_trace_stop)], %g2
David S. Miller9960e9e2010-04-07 04:41:33 -070029 brnz,pn %g2, 2f
David S. Miller63b75492010-04-12 22:35:24 -070030 sethi %hi(ftrace_trace_function), %g1
David Millerd05f5f92008-05-13 22:06:59 -070031 sethi %hi(ftrace_stub), %g2
32 ldx [%g1 + %lo(ftrace_trace_function)], %g1
33 or %g2, %lo(ftrace_stub), %g2
34 cmp %g1, %g2
35 be,pn %icc, 1f
David S. Miller9960e9e2010-04-07 04:41:33 -070036 mov %i7, %g3
David S. Miller035df352010-04-13 18:59:02 -070037 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070038 mov %g3, %o1
David S. Millera71d1d62010-04-06 19:59:46 -070039 jmpl %g1, %o7
40 mov %i7, %o0
41 ret
42 restore
David Millerd05f5f92008-05-13 22:06:59 -070043 /* not reached */
441:
David S. Miller9960e9e2010-04-07 04:41:33 -070045#ifdef CONFIG_FUNCTION_GRAPH_TRACER
46 sethi %hi(ftrace_graph_return), %g1
47 ldx [%g1 + %lo(ftrace_graph_return)], %g3
48 cmp %g2, %g3
49 bne,pn %xcc, 5f
50 sethi %hi(ftrace_graph_entry_stub), %g2
51 sethi %hi(ftrace_graph_entry), %g1
52 or %g2, %lo(ftrace_graph_entry_stub), %g2
53 ldx [%g1 + %lo(ftrace_graph_entry)], %g1
54 cmp %g1, %g2
55 be,pt %xcc, 2f
56 nop
575: mov %i7, %g2
58 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070059 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070060 mov %g2, %l0
61 ba,pt %xcc, ftrace_graph_caller
62 mov %g3, %l1
63#endif
642:
David Millerd05f5f92008-05-13 22:06:59 -070065#endif
66#endif
67 retl
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 nop
David Millerd05f5f92008-05-13 22:06:59 -070069 .size _mcount,.-_mcount
70 .size mcount,.-mcount
71
Steven Rostedt606576c2008-10-06 19:06:12 -040072#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070073 .globl ftrace_stub
74 .type ftrace_stub,#function
75ftrace_stub:
76 retl
77 nop
78 .size ftrace_stub,.-ftrace_stub
79#ifdef CONFIG_DYNAMIC_FTRACE
80 .globl ftrace_caller
81 .type ftrace_caller,#function
82ftrace_caller:
David S. Miller63b75492010-04-12 22:35:24 -070083 sethi %hi(function_trace_stop), %g1
David S. Millera71d1d62010-04-06 19:59:46 -070084 mov %i7, %g2
David S. Miller9960e9e2010-04-07 04:41:33 -070085 lduw [%g1 + %lo(function_trace_stop)], %g1
86 brnz,pn %g1, ftrace_stub
87 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070088 save %sp, -176, %sp
David S. Millera71d1d62010-04-06 19:59:46 -070089 mov %g2, %o1
David S. Miller9960e9e2010-04-07 04:41:33 -070090 mov %g2, %l0
91 mov %g3, %l1
David Millerd05f5f92008-05-13 22:06:59 -070092 .globl ftrace_call
93ftrace_call:
94 call ftrace_stub
David S. Millera71d1d62010-04-06 19:59:46 -070095 mov %i7, %o0
David S. Miller9960e9e2010-04-07 04:41:33 -070096#ifdef CONFIG_FUNCTION_GRAPH_TRACER
97 .globl ftrace_graph_call
98ftrace_graph_call:
99 call ftrace_stub
100 nop
101#endif
David S. Millera71d1d62010-04-06 19:59:46 -0700102 ret
103 restore
David S. Miller9960e9e2010-04-07 04:41:33 -0700104#ifdef CONFIG_FUNCTION_GRAPH_TRACER
105 .size ftrace_graph_call,.-ftrace_graph_call
106#endif
David S. Miller63b75492010-04-12 22:35:24 -0700107 .size ftrace_call,.-ftrace_call
David Millerd05f5f92008-05-13 22:06:59 -0700108 .size ftrace_caller,.-ftrace_caller
109#endif
110#endif
David S. Miller9960e9e2010-04-07 04:41:33 -0700111
112#ifdef CONFIG_FUNCTION_GRAPH_TRACER
113ENTRY(ftrace_graph_caller)
114 mov %l0, %o0
115 mov %i7, %o1
116 call prepare_ftrace_return
117 mov %l1, %o2
118 ret
119 restore %o0, -8, %i7
120END(ftrace_graph_caller)
121
122ENTRY(return_to_handler)
David S. Miller035df352010-04-13 18:59:02 -0700123 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -0700124 call ftrace_return_to_handler
125 mov %fp, %o0
126 jmpl %o0 + 8, %g0
127 restore
128END(return_to_handler)
129#endif