Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/linkage.h> |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | .text |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 16 | .align 32 |
| 17 | .globl _mcount |
| 18 | .type _mcount,#function |
| 19 | .globl mcount |
| 20 | .type mcount,#function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | _mcount: |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 22 | mcount: |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 23 | #ifdef CONFIG_FUNCTION_TRACER |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 24 | #ifdef CONFIG_DYNAMIC_FTRACE |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 25 | /* Do nothing, the retl/nop below is all we need. */ |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 26 | #else |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 27 | 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 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 | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame^] | 36 | mov %i7, %g2 |
| 37 | save %sp, -128, %sp |
| 38 | mov %g2, %o1 |
| 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: |
| 45 | #endif |
| 46 | #endif |
| 47 | retl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | nop |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 49 | .size _mcount,.-_mcount |
| 50 | .size mcount,.-mcount |
| 51 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 52 | #ifdef CONFIG_FUNCTION_TRACER |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 53 | .globl ftrace_stub |
| 54 | .type ftrace_stub,#function |
| 55 | ftrace_stub: |
| 56 | retl |
| 57 | nop |
| 58 | .size ftrace_stub,.-ftrace_stub |
| 59 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 60 | .globl ftrace_caller |
| 61 | .type ftrace_caller,#function |
| 62 | ftrace_caller: |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 63 | sethi %hi(function_trace_stop), %g1 |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame^] | 64 | mov %i7, %g2 |
| 65 | lduw [%g1 + %lo(function_trace_stop)], %g3 |
| 66 | brnz,pn %g3, ftrace_stub |
| 67 | nop |
| 68 | save %sp, -128, %sp |
| 69 | mov %g2, %o1 |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 70 | .globl ftrace_call |
| 71 | ftrace_call: |
| 72 | call ftrace_stub |
David S. Miller | a71d1d6 | 2010-04-06 19:59:46 -0700 | [diff] [blame^] | 73 | mov %i7, %o0 |
| 74 | ret |
| 75 | restore |
David S. Miller | 63b7549 | 2010-04-12 22:35:24 -0700 | [diff] [blame] | 76 | .size ftrace_call,.-ftrace_call |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 77 | .size ftrace_caller,.-ftrace_caller |
| 78 | #endif |
| 79 | #endif |