Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/linkage.h> |
Al Viro | d3867f04 | 2016-01-16 21:39:30 -0500 | [diff] [blame] | 10 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | .text |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 18 | .align 32 |
| 19 | .globl _mcount |
| 20 | .type _mcount,#function |
Al Viro | d3867f04 | 2016-01-16 21:39:30 -0500 | [diff] [blame] | 21 | EXPORT_SYMBOL(_mcount) |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 22 | .globl mcount |
| 23 | .type mcount,#function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | _mcount: |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 25 | mcount: |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 26 | #ifdef CONFIG_FUNCTION_TRACER |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_DYNAMIC_FTRACE |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 28 | /* Do nothing, the retl/nop below is all we need. */ |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 29 | #else |
Steven Rostedt (Red Hat) | 2563b9d | 2014-06-25 12:22:53 -0400 | [diff] [blame] | 30 | sethi %hi(ftrace_trace_function), %g1 |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 31 | 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. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 36 | mov %i7, %g3 |
David S. Miller | 035df35 | 2010-04-13 18:59:02 -0700 | [diff] [blame] | 37 | save %sp, -176, %sp |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 38 | mov %g3, %o1 |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame] | 39 | jmpl %g1, %o7 |
| 40 | mov %i7, %o0 |
| 41 | ret |
| 42 | restore |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 43 | /* not reached */ |
| 44 | 1: |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 45 | #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 |
| 57 | 5: mov %i7, %g2 |
| 58 | mov %fp, %g3 |
David S. Miller | 035df35 | 2010-04-13 18:59:02 -0700 | [diff] [blame] | 59 | save %sp, -176, %sp |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 60 | mov %g2, %l0 |
| 61 | ba,pt %xcc, ftrace_graph_caller |
| 62 | mov %g3, %l1 |
| 63 | #endif |
| 64 | 2: |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 65 | #endif |
| 66 | #endif |
| 67 | retl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | nop |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 69 | .size _mcount,.-_mcount |
| 70 | .size mcount,.-mcount |
| 71 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 72 | #ifdef CONFIG_FUNCTION_TRACER |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 73 | .globl ftrace_stub |
| 74 | .type ftrace_stub,#function |
| 75 | ftrace_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 |
| 82 | ftrace_caller: |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame] | 83 | mov %i7, %g2 |
Steven Rostedt (Red Hat) | 2563b9d | 2014-06-25 12:22:53 -0400 | [diff] [blame] | 84 | mov %fp, %g3 |
David S. Miller | 035df35 | 2010-04-13 18:59:02 -0700 | [diff] [blame] | 85 | save %sp, -176, %sp |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame] | 86 | mov %g2, %o1 |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 87 | mov %g2, %l0 |
| 88 | mov %g3, %l1 |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 89 | .globl ftrace_call |
| 90 | ftrace_call: |
| 91 | call ftrace_stub |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame] | 92 | mov %i7, %o0 |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 93 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 94 | .globl ftrace_graph_call |
| 95 | ftrace_graph_call: |
| 96 | call ftrace_stub |
| 97 | nop |
| 98 | #endif |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame] | 99 | ret |
| 100 | restore |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 101 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 102 | .size ftrace_graph_call,.-ftrace_graph_call |
| 103 | #endif |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 104 | .size ftrace_call,.-ftrace_call |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 105 | .size ftrace_caller,.-ftrace_caller |
| 106 | #endif |
| 107 | #endif |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 108 | |
| 109 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 110 | ENTRY(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 |
| 117 | END(ftrace_graph_caller) |
| 118 | |
| 119 | ENTRY(return_to_handler) |
David S. Miller | 035df35 | 2010-04-13 18:59:02 -0700 | [diff] [blame] | 120 | save %sp, -176, %sp |
David S. Miller | 9960e9e | 2010-04-07 04:41:33 -0700 | [diff] [blame] | 121 | call ftrace_return_to_handler |
| 122 | mov %fp, %o0 |
| 123 | jmpl %o0 + 8, %g0 |
| 124 | restore |
| 125 | END(return_to_handler) |
| 126 | #endif |