blob: 73ed0f3aaa0cc4ee5f18c4f7cfbf703f16b44a53 [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
29 brnz,pn %g2, 1f
30 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
36 mov %i7, %o1
37 jmpl %g1, %g0
38 mov %o7, %o0
39 /* not reached */
401:
41#endif
42#endif
43 retl
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 nop
David Millerd05f5f92008-05-13 22:06:59 -070045 .size _mcount,.-_mcount
46 .size mcount,.-mcount
47
Steven Rostedt606576c2008-10-06 19:06:12 -040048#ifdef CONFIG_FUNCTION_TRACER
David Millerd05f5f92008-05-13 22:06:59 -070049 .globl ftrace_stub
50 .type ftrace_stub,#function
51ftrace_stub:
52 retl
53 nop
54 .size ftrace_stub,.-ftrace_stub
55#ifdef CONFIG_DYNAMIC_FTRACE
56 .globl ftrace_caller
57 .type ftrace_caller,#function
58ftrace_caller:
David S. Miller63b75492010-04-12 22:35:24 -070059 sethi %hi(function_trace_stop), %g1
David Millerd05f5f92008-05-13 22:06:59 -070060 mov %i7, %o1
David S. Miller63b75492010-04-12 22:35:24 -070061 lduw [%g1 + %lo(function_trace_stop)], %g2
62 brnz,pn %g2, ftrace_stub
63 mov %o7, %o0
David Millerd05f5f92008-05-13 22:06:59 -070064 .globl ftrace_call
65ftrace_call:
David S. Miller63b75492010-04-12 22:35:24 -070066 /* If the final kernel link ever turns on relaxation, we'll need
67 * to do something about this tail call. Otherwise the linker
68 * will rewrite the call into a branch and nop out the move
69 * instruction.
70 */
David Millerd05f5f92008-05-13 22:06:59 -070071 call ftrace_stub
72 mov %o0, %o7
73 retl
74 nop
David S. Miller63b75492010-04-12 22:35:24 -070075 .size ftrace_call,.-ftrace_call
David Millerd05f5f92008-05-13 22:06:59 -070076 .size ftrace_caller,.-ftrace_caller
77#endif
78#endif