1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 /* 1 /* 3 * Copyright (C) 2000 Anton Blanchard (anton@l 2 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com) 4 * 3 * 5 * This file implements mcount(), which is use 4 * This file implements mcount(), which is used to collect profiling data. 6 * This can also be tweaked for kernel stack o 5 * This can also be tweaked for kernel stack overflow detection. 7 */ 6 */ 8 7 9 #include <linux/export.h> << 10 #include <linux/linkage.h> 8 #include <linux/linkage.h> >> 9 #include <asm/export.h> 11 10 12 /* 11 /* 13 * This is the main variant and is called by C 12 * This is the main variant and is called by C code. GCC's -pg option 14 * automatically instruments every C function 13 * automatically instruments every C function with a call to this. 15 */ 14 */ 16 15 17 .text 16 .text 18 .align 32 17 .align 32 19 .globl _mcount 18 .globl _mcount 20 .type _mcount,#function 19 .type _mcount,#function 21 EXPORT_SYMBOL(_mcount) 20 EXPORT_SYMBOL(_mcount) 22 .globl mcount 21 .globl mcount 23 .type mcount,#function 22 .type mcount,#function 24 _mcount: 23 _mcount: 25 mcount: 24 mcount: 26 #ifdef CONFIG_FUNCTION_TRACER 25 #ifdef CONFIG_FUNCTION_TRACER 27 #ifdef CONFIG_DYNAMIC_FTRACE 26 #ifdef CONFIG_DYNAMIC_FTRACE 28 /* Do nothing, the retl/nop below is a 27 /* Do nothing, the retl/nop below is all we need. */ 29 #else 28 #else 30 sethi %hi(ftrace_trace_funct 29 sethi %hi(ftrace_trace_function), %g1 31 sethi %hi(ftrace_stub), %g2 30 sethi %hi(ftrace_stub), %g2 32 ldx [%g1 + %lo(ftrace_trac 31 ldx [%g1 + %lo(ftrace_trace_function)], %g1 33 or %g2, %lo(ftrace_stub), 32 or %g2, %lo(ftrace_stub), %g2 34 cmp %g1, %g2 33 cmp %g1, %g2 35 be,pn %icc, 1f 34 be,pn %icc, 1f 36 mov %i7, %g3 35 mov %i7, %g3 37 save %sp, -176, %sp 36 save %sp, -176, %sp 38 mov %g3, %o1 37 mov %g3, %o1 39 jmpl %g1, %o7 38 jmpl %g1, %o7 40 mov %i7, %o0 39 mov %i7, %o0 41 ret 40 ret 42 restore 41 restore 43 /* not reached */ 42 /* not reached */ 44 1: 43 1: 45 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 44 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 46 sethi %hi(ftrace_graph_retur 45 sethi %hi(ftrace_graph_return), %g1 47 ldx [%g1 + %lo(ftrace_grap 46 ldx [%g1 + %lo(ftrace_graph_return)], %g3 48 cmp %g2, %g3 47 cmp %g2, %g3 49 bne,pn %xcc, 5f 48 bne,pn %xcc, 5f 50 sethi %hi(ftrace_graph_entry 49 sethi %hi(ftrace_graph_entry_stub), %g2 51 sethi %hi(ftrace_graph_entry 50 sethi %hi(ftrace_graph_entry), %g1 52 or %g2, %lo(ftrace_graph_ 51 or %g2, %lo(ftrace_graph_entry_stub), %g2 53 ldx [%g1 + %lo(ftrace_grap 52 ldx [%g1 + %lo(ftrace_graph_entry)], %g1 54 cmp %g1, %g2 53 cmp %g1, %g2 55 be,pt %xcc, 2f 54 be,pt %xcc, 2f 56 nop 55 nop 57 5: mov %i7, %g2 56 5: mov %i7, %g2 58 mov %fp, %g3 57 mov %fp, %g3 59 save %sp, -176, %sp 58 save %sp, -176, %sp 60 mov %g2, %l0 59 mov %g2, %l0 61 ba,pt %xcc, ftrace_graph_cal 60 ba,pt %xcc, ftrace_graph_caller 62 mov %g3, %l1 61 mov %g3, %l1 63 #endif 62 #endif 64 2: 63 2: 65 #endif 64 #endif 66 #endif 65 #endif 67 retl 66 retl 68 nop 67 nop 69 .size _mcount,.-_mcount 68 .size _mcount,.-_mcount 70 .size mcount,.-mcount 69 .size mcount,.-mcount 71 70 72 #ifdef CONFIG_FUNCTION_TRACER 71 #ifdef CONFIG_FUNCTION_TRACER 73 .globl ftrace_stub 72 .globl ftrace_stub 74 .type ftrace_stub,#function 73 .type ftrace_stub,#function 75 ftrace_stub: 74 ftrace_stub: 76 retl 75 retl 77 nop 76 nop 78 .size ftrace_stub,.-ftrace_s 77 .size ftrace_stub,.-ftrace_stub 79 #ifdef CONFIG_DYNAMIC_FTRACE 78 #ifdef CONFIG_DYNAMIC_FTRACE 80 .globl ftrace_caller 79 .globl ftrace_caller 81 .type ftrace_caller,#functio 80 .type ftrace_caller,#function 82 ftrace_caller: 81 ftrace_caller: 83 mov %i7, %g2 82 mov %i7, %g2 84 mov %fp, %g3 83 mov %fp, %g3 85 save %sp, -176, %sp 84 save %sp, -176, %sp 86 mov %g2, %o1 85 mov %g2, %o1 87 mov %g2, %l0 86 mov %g2, %l0 88 mov %g3, %l1 87 mov %g3, %l1 89 .globl ftrace_call 88 .globl ftrace_call 90 ftrace_call: 89 ftrace_call: 91 call ftrace_stub 90 call ftrace_stub 92 mov %i7, %o0 91 mov %i7, %o0 93 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 92 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 94 .globl ftrace_graph_call 93 .globl ftrace_graph_call 95 ftrace_graph_call: 94 ftrace_graph_call: 96 call ftrace_stub 95 call ftrace_stub 97 nop 96 nop 98 #endif 97 #endif 99 ret 98 ret 100 restore 99 restore 101 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 100 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 102 .size ftrace_graph_call,.-ft 101 .size ftrace_graph_call,.-ftrace_graph_call 103 #endif 102 #endif 104 .size ftrace_call,.-ftrace_c 103 .size ftrace_call,.-ftrace_call 105 .size ftrace_caller,.-ftrace 104 .size ftrace_caller,.-ftrace_caller 106 #endif 105 #endif 107 #endif 106 #endif 108 107 109 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 108 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 110 ENTRY(ftrace_graph_caller) 109 ENTRY(ftrace_graph_caller) 111 mov %l0, %o0 110 mov %l0, %o0 112 mov %i7, %o1 111 mov %i7, %o1 113 call prepare_ftrace_return 112 call prepare_ftrace_return 114 mov %l1, %o2 113 mov %l1, %o2 115 ret 114 ret 116 restore %o0, -8, %i7 115 restore %o0, -8, %i7 117 END(ftrace_graph_caller) 116 END(ftrace_graph_caller) 118 117 119 ENTRY(return_to_handler) 118 ENTRY(return_to_handler) 120 save %sp, -176, %sp 119 save %sp, -176, %sp 121 call ftrace_return_to_handl 120 call ftrace_return_to_handler 122 mov %fp, %o0 121 mov %fp, %o0 123 jmpl %o0 + 8, %g0 122 jmpl %o0 + 8, %g0 124 restore 123 restore 125 END(return_to_handler) 124 END(return_to_handler) 126 #endif 125 #endif
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.