1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 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 9#include <linux/export.h> 10#include <linux/linkage.h> 11 12/* 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 17 .text 18 .align 32 19 .globl _mcount 20 .type _mcount,#function 21 EXPORT_SYMBOL(_mcount) 22 .globl mcount 23 .type mcount,#function 24 EXPORT_SYMBOL(mcount) 25_mcount: 26mcount: 27#ifdef CONFIG_FUNCTION_TRACER 28#ifdef CONFIG_DYNAMIC_FTRACE 29 /* Do nothing, the retl/nop below is all we need. */ 30#else 31 sethi %hi(ftrace_trace_function), %g1 32 sethi %hi(ftrace_stub), %g2 33 ldx [%g1 + %lo(ftrace_trace_function)], %g1 34 or %g2, %lo(ftrace_stub), %g2 35 cmp %g1, %g2 36 be,pn %icc, 1f 37 mov %i7, %g3 38 save %sp, -176, %sp 39 mov %g3, %o1 40 jmpl %g1, %o7 41 mov %i7, %o0 42 ret 43 restore 44 /* not reached */ 451: 46#ifdef CONFIG_FUNCTION_GRAPH_TRACER 47 sethi %hi(ftrace_graph_return), %g1 48 ldx [%g1 + %lo(ftrace_graph_return)], %g3 49 cmp %g2, %g3 50 bne,pn %xcc, 5f 51 sethi %hi(ftrace_graph_entry_stub), %g2 52 sethi %hi(ftrace_graph_entry), %g1 53 or %g2, %lo(ftrace_graph_entry_stub), %g2 54 ldx [%g1 + %lo(ftrace_graph_entry)], %g1 55 cmp %g1, %g2 56 be,pt %xcc, 2f 57 nop 585: mov %i7, %g2 59 mov %fp, %g3 60 save %sp, -176, %sp 61 mov %g2, %l0 62 ba,pt %xcc, ftrace_graph_caller 63 mov %g3, %l1 64#endif 652: 66#endif 67#endif 68 retl 69 nop 70 .size _mcount,.-_mcount 71 .size mcount,.-mcount 72 73#ifdef CONFIG_FUNCTION_TRACER 74 .globl ftrace_stub 75 .type ftrace_stub,#function 76ftrace_stub: 77 retl 78 nop 79 .size ftrace_stub,.-ftrace_stub 80#ifdef CONFIG_DYNAMIC_FTRACE 81 .globl ftrace_caller 82 .type ftrace_caller,#function 83ftrace_caller: 84 mov %i7, %g2 85 mov %fp, %g3 86 save %sp, -176, %sp 87 mov %g2, %o1 88 mov %g2, %l0 89 mov %g3, %l1 90 .globl ftrace_call 91ftrace_call: 92 call ftrace_stub 93 mov %i7, %o0 94#ifdef CONFIG_FUNCTION_GRAPH_TRACER 95 .globl ftrace_graph_call 96ftrace_graph_call: 97 call ftrace_stub 98 nop 99#endif 100 ret 101 restore 102#ifdef CONFIG_FUNCTION_GRAPH_TRACER 103 .size ftrace_graph_call,.-ftrace_graph_call 104#endif 105 .size ftrace_call,.-ftrace_call 106 .size ftrace_caller,.-ftrace_caller 107#endif 108#endif 109 110#ifdef CONFIG_FUNCTION_GRAPH_TRACER 111ENTRY(ftrace_graph_caller) 112 mov %l0, %o0 113 mov %i7, %o1 114 call prepare_ftrace_return 115 mov %l1, %o2 116 ret 117 restore %o0, -8, %i7 118END(ftrace_graph_caller) 119 120ENTRY(return_to_handler) 121 save %sp, -176, %sp 122 call ftrace_return_to_handler 123 mov %fp, %o0 124 jmpl %o0 + 8, %g0 125 restore 126END(return_to_handler) 127#endif 128