blob: 194f383611c02f815431f90dfd662c3718f3b4a8 [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>
Al Virod3867f042016-01-16 21:39:30 -05009#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011/*
12 * This is the main variant and is called by C code. GCC's -pg option
13 * automatically instruments every C function with a call to this.
14 */
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 .text
David Millerd05f5f92008-05-13 22:06:59 -070017 .align 32
18 .globl _mcount
19 .type _mcount,#function
Al Virod3867f042016-01-16 21:39:30 -050020 EXPORT_SYMBOL(_mcount)
David Millerd05f5f92008-05-13 22:06:59 -070021 .globl mcount
22 .type mcount,#function
Linus Torvalds1da177e2005-04-16 15:20:36 -070023_mcount:
David Millerd05f5f92008-05-13 22:06:59 -070024mcount:
Steven Rostedt606576c2008-10-06 19:06:12 -040025#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070026#ifdef CONFIG_DYNAMIC_FTRACE
David S. Miller63b75492010-04-12 22:35:24 -070027 /* Do nothing, the retl/nop below is all we need. */
David Millerd05f5f92008-05-13 22:06:59 -070028#else
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040029 sethi %hi(ftrace_trace_function), %g1
David Millerd05f5f92008-05-13 22:06:59 -070030 sethi %hi(ftrace_stub), %g2
31 ldx [%g1 + %lo(ftrace_trace_function)], %g1
32 or %g2, %lo(ftrace_stub), %g2
33 cmp %g1, %g2
34 be,pn %icc, 1f
David S. Miller9960e9e2010-04-07 04:41:33 -070035 mov %i7, %g3
David S. Miller035df352010-04-13 18:59:02 -070036 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070037 mov %g3, %o1
David S. Millera71d1d62010-04-06 19:59:46 -070038 jmpl %g1, %o7
39 mov %i7, %o0
40 ret
41 restore
David Millerd05f5f92008-05-13 22:06:59 -070042 /* not reached */
431:
David S. Miller9960e9e2010-04-07 04:41:33 -070044#ifdef CONFIG_FUNCTION_GRAPH_TRACER
45 sethi %hi(ftrace_graph_return), %g1
46 ldx [%g1 + %lo(ftrace_graph_return)], %g3
47 cmp %g2, %g3
48 bne,pn %xcc, 5f
49 sethi %hi(ftrace_graph_entry_stub), %g2
50 sethi %hi(ftrace_graph_entry), %g1
51 or %g2, %lo(ftrace_graph_entry_stub), %g2
52 ldx [%g1 + %lo(ftrace_graph_entry)], %g1
53 cmp %g1, %g2
54 be,pt %xcc, 2f
55 nop
565: mov %i7, %g2
57 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070058 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070059 mov %g2, %l0
60 ba,pt %xcc, ftrace_graph_caller
61 mov %g3, %l1
62#endif
632:
David Millerd05f5f92008-05-13 22:06:59 -070064#endif
65#endif
66 retl
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 nop
David Millerd05f5f92008-05-13 22:06:59 -070068 .size _mcount,.-_mcount
69 .size mcount,.-mcount
70
Steven Rostedt606576c2008-10-06 19:06:12 -040071#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070072 .globl ftrace_stub
73 .type ftrace_stub,#function
74ftrace_stub:
75 retl
76 nop
77 .size ftrace_stub,.-ftrace_stub
78#ifdef CONFIG_DYNAMIC_FTRACE
79 .globl ftrace_caller
80 .type ftrace_caller,#function
81ftrace_caller:
David S. Millera71d1d62010-04-06 19:59:46 -070082 mov %i7, %g2
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040083 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070084 save %sp, -176, %sp
David S. Millera71d1d62010-04-06 19:59:46 -070085 mov %g2, %o1
David S. Miller9960e9e2010-04-07 04:41:33 -070086 mov %g2, %l0
87 mov %g3, %l1
David Millerd05f5f92008-05-13 22:06:59 -070088 .globl ftrace_call
89ftrace_call:
90 call ftrace_stub
David S. Millera71d1d62010-04-06 19:59:46 -070091 mov %i7, %o0
David S. Miller9960e9e2010-04-07 04:41:33 -070092#ifdef CONFIG_FUNCTION_GRAPH_TRACER
93 .globl ftrace_graph_call
94ftrace_graph_call:
95 call ftrace_stub
96 nop
97#endif
David S. Millera71d1d62010-04-06 19:59:46 -070098 ret
99 restore
David S. Miller9960e9e2010-04-07 04:41:33 -0700100#ifdef CONFIG_FUNCTION_GRAPH_TRACER
101 .size ftrace_graph_call,.-ftrace_graph_call
102#endif
David S. Miller63b75492010-04-12 22:35:24 -0700103 .size ftrace_call,.-ftrace_call
David Millerd05f5f92008-05-13 22:06:59 -0700104 .size ftrace_caller,.-ftrace_caller
105#endif
106#endif
David S. Miller9960e9e2010-04-07 04:41:33 -0700107
108#ifdef CONFIG_FUNCTION_GRAPH_TRACER
109ENTRY(ftrace_graph_caller)
110 mov %l0, %o0
111 mov %i7, %o1
112 call prepare_ftrace_return
113 mov %l1, %o2
114 ret
115 restore %o0, -8, %i7
116END(ftrace_graph_caller)
117
118ENTRY(return_to_handler)
David S. Miller035df352010-04-13 18:59:02 -0700119 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -0700120 call ftrace_return_to_handler
121 mov %fp, %o0
122 jmpl %o0 + 8, %g0
123 restore
124END(return_to_handler)
125#endif