blob: deba6fa0bc78bfd48ffdb7b96219d1072109ca06 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com)
4 *
5 * This file implements mcount(), which is used to collect profiling data.
6 * This can also be tweaked for kernel stack overflow detection.
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/linkage.h>
Al Virod3867f042016-01-16 21:39:30 -050010#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012/*
13 * This is the main variant and is called by C code. GCC's -pg option
14 * automatically instruments every C function with a call to this.
15 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 .text
David Millerd05f5f92008-05-13 22:06:59 -070018 .align 32
19 .globl _mcount
20 .type _mcount,#function
Al Virod3867f042016-01-16 21:39:30 -050021 EXPORT_SYMBOL(_mcount)
David Millerd05f5f92008-05-13 22:06:59 -070022 .globl mcount
23 .type mcount,#function
Linus Torvalds1da177e2005-04-16 15:20:36 -070024_mcount:
David Millerd05f5f92008-05-13 22:06:59 -070025mcount:
Steven Rostedt606576c2008-10-06 19:06:12 -040026#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070027#ifdef CONFIG_DYNAMIC_FTRACE
David S. Miller63b75492010-04-12 22:35:24 -070028 /* Do nothing, the retl/nop below is all we need. */
David Millerd05f5f92008-05-13 22:06:59 -070029#else
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040030 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. Millera71d1d62010-04-06 19:59:46 -070083 mov %i7, %g2
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040084 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070085 save %sp, -176, %sp
David S. Millera71d1d62010-04-06 19:59:46 -070086 mov %g2, %o1
David S. Miller9960e9e2010-04-07 04:41:33 -070087 mov %g2, %l0
88 mov %g3, %l1
David Millerd05f5f92008-05-13 22:06:59 -070089 .globl ftrace_call
90ftrace_call:
91 call ftrace_stub
David S. Millera71d1d62010-04-06 19:59:46 -070092 mov %i7, %o0
David S. Miller9960e9e2010-04-07 04:41:33 -070093#ifdef CONFIG_FUNCTION_GRAPH_TRACER
94 .globl ftrace_graph_call
95ftrace_graph_call:
96 call ftrace_stub
97 nop
98#endif
David S. Millera71d1d62010-04-06 19:59:46 -070099 ret
100 restore
David S. Miller9960e9e2010-04-07 04:41:33 -0700101#ifdef CONFIG_FUNCTION_GRAPH_TRACER
102 .size ftrace_graph_call,.-ftrace_graph_call
103#endif
David S. Miller63b75492010-04-12 22:35:24 -0700104 .size ftrace_call,.-ftrace_call
David Millerd05f5f92008-05-13 22:06:59 -0700105 .size ftrace_caller,.-ftrace_caller
106#endif
107#endif
David S. Miller9960e9e2010-04-07 04:41:33 -0700108
109#ifdef CONFIG_FUNCTION_GRAPH_TRACER
110ENTRY(ftrace_graph_caller)
111 mov %l0, %o0
112 mov %i7, %o1
113 call prepare_ftrace_return
114 mov %l1, %o2
115 ret
116 restore %o0, -8, %i7
117END(ftrace_graph_caller)
118
119ENTRY(return_to_handler)
David S. Miller035df352010-04-13 18:59:02 -0700120 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -0700121 call ftrace_return_to_handler
122 mov %fp, %o0
123 jmpl %o0 + 8, %g0
124 restore
125END(return_to_handler)
126#endif