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 | |
| 10 | #include <asm/ptrace.h> |
| 11 | #include <asm/thread_info.h> |
| 12 | |
| 13 | /* |
| 14 | * This is the main variant and is called by C code. GCC's -pg option |
| 15 | * automatically instruments every C function with a call to this. |
| 16 | */ |
| 17 | |
| 18 | #ifdef CONFIG_STACK_DEBUG |
| 19 | |
| 20 | #define OVSTACKSIZE 4096 /* lets hope this is enough */ |
| 21 | |
| 22 | .data |
| 23 | .align 8 |
| 24 | panicstring: |
| 25 | .asciz "Stack overflow\n" |
| 26 | .align 8 |
| 27 | ovstack: |
| 28 | .skip OVSTACKSIZE |
| 29 | #endif |
| 30 | .text |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 31 | .align 32 |
| 32 | .globl _mcount |
| 33 | .type _mcount,#function |
| 34 | .globl mcount |
| 35 | .type mcount,#function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | _mcount: |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 37 | mcount: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_STACK_DEBUG |
| 39 | /* |
| 40 | * Check whether %sp is dangerously low. |
| 41 | */ |
| 42 | ldub [%g6 + TI_FPDEPTH], %g1 |
| 43 | srl %g1, 1, %g3 |
| 44 | add %g3, 1, %g3 |
| 45 | sllx %g3, 8, %g3 ! each fpregs frame is 256b |
| 46 | add %g3, 192, %g3 |
| 47 | add %g6, %g3, %g3 ! where does task_struct+frame end? |
| 48 | sub %g3, STACK_BIAS, %g3 |
| 49 | cmp %sp, %g3 |
| 50 | bg,pt %xcc, 1f |
David S. Miller | c749808 | 2008-08-12 02:03:49 -0700 | [diff] [blame^] | 51 | nop |
| 52 | /* If we are already on ovstack, don't hop onto it |
| 53 | * again, we are already trying to output the stack overflow |
| 54 | * message. |
| 55 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough |
| 57 | or %g7, %lo(ovstack), %g7 |
David S. Miller | c749808 | 2008-08-12 02:03:49 -0700 | [diff] [blame^] | 58 | add %g7, OVSTACKSIZE, %g3 |
| 59 | sub %g3, STACK_BIAS + 192, %g3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | sub %g7, STACK_BIAS, %g7 |
David S. Miller | c749808 | 2008-08-12 02:03:49 -0700 | [diff] [blame^] | 61 | cmp %sp, %g7 |
| 62 | blu,pn %xcc, 2f |
| 63 | cmp %sp, %g3 |
| 64 | bleu,pn %xcc, 1f |
| 65 | nop |
| 66 | 2: mov %g3, %sp |
| 67 | sethi %hi(panicstring), %g3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | call prom_printf |
| 69 | or %g3, %lo(panicstring), %o0 |
| 70 | call prom_halt |
| 71 | nop |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 72 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #endif |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 74 | #ifdef CONFIG_FTRACE |
| 75 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 76 | mov %o7, %o0 |
| 77 | .globl mcount_call |
| 78 | mcount_call: |
| 79 | call ftrace_stub |
| 80 | mov %o0, %o7 |
| 81 | #else |
| 82 | sethi %hi(ftrace_trace_function), %g1 |
| 83 | sethi %hi(ftrace_stub), %g2 |
| 84 | ldx [%g1 + %lo(ftrace_trace_function)], %g1 |
| 85 | or %g2, %lo(ftrace_stub), %g2 |
| 86 | cmp %g1, %g2 |
| 87 | be,pn %icc, 1f |
| 88 | mov %i7, %o1 |
| 89 | jmpl %g1, %g0 |
| 90 | mov %o7, %o0 |
| 91 | /* not reached */ |
| 92 | 1: |
| 93 | #endif |
| 94 | #endif |
| 95 | retl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | nop |
David Miller | d05f5f9 | 2008-05-13 22:06:59 -0700 | [diff] [blame] | 97 | .size _mcount,.-_mcount |
| 98 | .size mcount,.-mcount |
| 99 | |
| 100 | #ifdef CONFIG_FTRACE |
| 101 | .globl ftrace_stub |
| 102 | .type ftrace_stub,#function |
| 103 | ftrace_stub: |
| 104 | retl |
| 105 | nop |
| 106 | .size ftrace_stub,.-ftrace_stub |
| 107 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 108 | .globl ftrace_caller |
| 109 | .type ftrace_caller,#function |
| 110 | ftrace_caller: |
| 111 | mov %i7, %o1 |
| 112 | mov %o7, %o0 |
| 113 | .globl ftrace_call |
| 114 | ftrace_call: |
| 115 | call ftrace_stub |
| 116 | mov %o0, %o7 |
| 117 | retl |
| 118 | nop |
| 119 | .size ftrace_caller,.-ftrace_caller |
| 120 | #endif |
| 121 | #endif |