blob: 0b0ed4d34219bc6dfccd1a0ab337727b2417a5b0 [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
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040027 sethi %hi(ftrace_trace_function), %g1
David Millerd05f5f92008-05-13 22:06:59 -070028 sethi %hi(ftrace_stub), %g2
29 ldx [%g1 + %lo(ftrace_trace_function)], %g1
30 or %g2, %lo(ftrace_stub), %g2
31 cmp %g1, %g2
32 be,pn %icc, 1f
David S. Miller9960e9e2010-04-07 04:41:33 -070033 mov %i7, %g3
David S. Miller035df352010-04-13 18:59:02 -070034 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070035 mov %g3, %o1
David S. Millera71d1d62010-04-06 19:59:46 -070036 jmpl %g1, %o7
37 mov %i7, %o0
38 ret
39 restore
David Millerd05f5f92008-05-13 22:06:59 -070040 /* not reached */
411:
David S. Miller9960e9e2010-04-07 04:41:33 -070042#ifdef CONFIG_FUNCTION_GRAPH_TRACER
43 sethi %hi(ftrace_graph_return), %g1
44 ldx [%g1 + %lo(ftrace_graph_return)], %g3
45 cmp %g2, %g3
46 bne,pn %xcc, 5f
47 sethi %hi(ftrace_graph_entry_stub), %g2
48 sethi %hi(ftrace_graph_entry), %g1
49 or %g2, %lo(ftrace_graph_entry_stub), %g2
50 ldx [%g1 + %lo(ftrace_graph_entry)], %g1
51 cmp %g1, %g2
52 be,pt %xcc, 2f
53 nop
545: mov %i7, %g2
55 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070056 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -070057 mov %g2, %l0
58 ba,pt %xcc, ftrace_graph_caller
59 mov %g3, %l1
60#endif
612:
David Millerd05f5f92008-05-13 22:06:59 -070062#endif
63#endif
64 retl
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 nop
David Millerd05f5f92008-05-13 22:06:59 -070066 .size _mcount,.-_mcount
67 .size mcount,.-mcount
68
Steven Rostedt606576c2008-10-06 19:06:12 -040069#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070070 .globl ftrace_stub
71 .type ftrace_stub,#function
72ftrace_stub:
73 retl
74 nop
75 .size ftrace_stub,.-ftrace_stub
76#ifdef CONFIG_DYNAMIC_FTRACE
77 .globl ftrace_caller
78 .type ftrace_caller,#function
79ftrace_caller:
David S. Millera71d1d62010-04-06 19:59:46 -070080 mov %i7, %g2
Steven Rostedt (Red Hat)2563b9d2014-06-25 12:22:53 -040081 mov %fp, %g3
David S. Miller035df352010-04-13 18:59:02 -070082 save %sp, -176, %sp
David S. Millera71d1d62010-04-06 19:59:46 -070083 mov %g2, %o1
David S. Miller9960e9e2010-04-07 04:41:33 -070084 mov %g2, %l0
85 mov %g3, %l1
David Millerd05f5f92008-05-13 22:06:59 -070086 .globl ftrace_call
87ftrace_call:
88 call ftrace_stub
David S. Millera71d1d62010-04-06 19:59:46 -070089 mov %i7, %o0
David S. Miller9960e9e2010-04-07 04:41:33 -070090#ifdef CONFIG_FUNCTION_GRAPH_TRACER
91 .globl ftrace_graph_call
92ftrace_graph_call:
93 call ftrace_stub
94 nop
95#endif
David S. Millera71d1d62010-04-06 19:59:46 -070096 ret
97 restore
David S. Miller9960e9e2010-04-07 04:41:33 -070098#ifdef CONFIG_FUNCTION_GRAPH_TRACER
99 .size ftrace_graph_call,.-ftrace_graph_call
100#endif
David S. Miller63b75492010-04-12 22:35:24 -0700101 .size ftrace_call,.-ftrace_call
David Millerd05f5f92008-05-13 22:06:59 -0700102 .size ftrace_caller,.-ftrace_caller
103#endif
104#endif
David S. Miller9960e9e2010-04-07 04:41:33 -0700105
106#ifdef CONFIG_FUNCTION_GRAPH_TRACER
107ENTRY(ftrace_graph_caller)
108 mov %l0, %o0
109 mov %i7, %o1
110 call prepare_ftrace_return
111 mov %l1, %o2
112 ret
113 restore %o0, -8, %i7
114END(ftrace_graph_caller)
115
116ENTRY(return_to_handler)
David S. Miller035df352010-04-13 18:59:02 -0700117 save %sp, -176, %sp
David S. Miller9960e9e2010-04-07 04:41:33 -0700118 call ftrace_return_to_handler
119 mov %fp, %o0
120 jmpl %o0 + 8, %g0
121 restore
122END(return_to_handler)
123#endif