Wu Zhangjin | d2bb0762 | 2009-11-20 20:34:29 +0800 | [diff] [blame] | 1 | /* |
| 2 | * MIPS specific _mcount support |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive for |
| 6 | * more details. |
| 7 | * |
| 8 | * Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China |
| 9 | * Author: Wu Zhangjin <wuzj@lemote.com> |
| 10 | */ |
| 11 | |
| 12 | #include <asm/regdef.h> |
| 13 | #include <asm/stackframe.h> |
| 14 | #include <asm/ftrace.h> |
| 15 | |
| 16 | .text |
| 17 | .set noreorder |
| 18 | .set noat |
| 19 | |
| 20 | .macro MCOUNT_SAVE_REGS |
| 21 | PTR_SUBU sp, PT_SIZE |
| 22 | PTR_S ra, PT_R31(sp) |
| 23 | PTR_S AT, PT_R1(sp) |
| 24 | PTR_S a0, PT_R4(sp) |
| 25 | PTR_S a1, PT_R5(sp) |
| 26 | PTR_S a2, PT_R6(sp) |
| 27 | PTR_S a3, PT_R7(sp) |
| 28 | #ifdef CONFIG_64BIT |
| 29 | PTR_S a4, PT_R8(sp) |
| 30 | PTR_S a5, PT_R9(sp) |
| 31 | PTR_S a6, PT_R10(sp) |
| 32 | PTR_S a7, PT_R11(sp) |
| 33 | #endif |
| 34 | .endm |
| 35 | |
| 36 | .macro MCOUNT_RESTORE_REGS |
| 37 | PTR_L ra, PT_R31(sp) |
| 38 | PTR_L AT, PT_R1(sp) |
| 39 | PTR_L a0, PT_R4(sp) |
| 40 | PTR_L a1, PT_R5(sp) |
| 41 | PTR_L a2, PT_R6(sp) |
| 42 | PTR_L a3, PT_R7(sp) |
| 43 | #ifdef CONFIG_64BIT |
| 44 | PTR_L a4, PT_R8(sp) |
| 45 | PTR_L a5, PT_R9(sp) |
| 46 | PTR_L a6, PT_R10(sp) |
| 47 | PTR_L a7, PT_R11(sp) |
| 48 | #endif |
| 49 | #ifdef CONFIG_64BIT |
| 50 | PTR_ADDIU sp, PT_SIZE |
| 51 | #else |
| 52 | PTR_ADDIU sp, (PT_SIZE + 8) |
| 53 | #endif |
| 54 | .endm |
| 55 | |
| 56 | .macro RETURN_BACK |
| 57 | jr ra |
| 58 | move ra, AT |
| 59 | .endm |
| 60 | |
Wu Zhangjin | 538f195 | 2009-11-20 20:34:32 +0800 | [diff] [blame] | 61 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 62 | |
| 63 | NESTED(ftrace_caller, PT_SIZE, ra) |
| 64 | .globl _mcount |
| 65 | _mcount: |
| 66 | b ftrace_stub |
| 67 | nop |
| 68 | lw t0, function_trace_stop |
| 69 | bnez t0, ftrace_stub |
| 70 | nop |
| 71 | |
| 72 | MCOUNT_SAVE_REGS |
| 73 | |
| 74 | move a0, ra /* arg1: next ip, selfaddr */ |
| 75 | .globl ftrace_call |
| 76 | ftrace_call: |
| 77 | nop /* a placeholder for the call to a real tracing function */ |
| 78 | move a1, AT /* arg2: the caller's next ip, parent */ |
| 79 | |
Wu Zhangjin | e17ff5f | 2009-11-20 20:34:35 +0800 | [diff] [blame] | 80 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 81 | .globl ftrace_graph_call |
| 82 | ftrace_graph_call: |
| 83 | nop |
| 84 | nop |
| 85 | #endif |
| 86 | |
Wu Zhangjin | 538f195 | 2009-11-20 20:34:32 +0800 | [diff] [blame] | 87 | MCOUNT_RESTORE_REGS |
| 88 | .globl ftrace_stub |
| 89 | ftrace_stub: |
| 90 | RETURN_BACK |
| 91 | END(ftrace_caller) |
| 92 | |
| 93 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
| 94 | |
Wu Zhangjin | d2bb0762 | 2009-11-20 20:34:29 +0800 | [diff] [blame] | 95 | NESTED(_mcount, PT_SIZE, ra) |
Wu Zhangjin | 69a7d1b | 2009-11-20 20:34:30 +0800 | [diff] [blame] | 96 | lw t0, function_trace_stop |
| 97 | bnez t0, ftrace_stub |
| 98 | nop |
Wu Zhangjin | d2bb0762 | 2009-11-20 20:34:29 +0800 | [diff] [blame] | 99 | PTR_LA t0, ftrace_stub |
| 100 | PTR_L t1, ftrace_trace_function /* Prepare t1 for (1) */ |
| 101 | bne t0, t1, static_trace |
| 102 | nop |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 103 | |
| 104 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 105 | PTR_L t2, ftrace_graph_return |
| 106 | bne t0, t2, ftrace_graph_caller |
| 107 | nop |
| 108 | PTR_LA t0, ftrace_graph_entry_stub |
| 109 | PTR_L t2, ftrace_graph_entry |
| 110 | bne t0, t2, ftrace_graph_caller |
| 111 | nop |
| 112 | #endif |
Wu Zhangjin | d2bb0762 | 2009-11-20 20:34:29 +0800 | [diff] [blame] | 113 | b ftrace_stub |
| 114 | nop |
| 115 | |
| 116 | static_trace: |
| 117 | MCOUNT_SAVE_REGS |
| 118 | |
| 119 | move a0, ra /* arg1: next ip, selfaddr */ |
| 120 | jalr t1 /* (1) call *ftrace_trace_function */ |
| 121 | move a1, AT /* arg2: the caller's next ip, parent */ |
| 122 | |
| 123 | MCOUNT_RESTORE_REGS |
| 124 | .globl ftrace_stub |
| 125 | ftrace_stub: |
| 126 | RETURN_BACK |
| 127 | END(_mcount) |
| 128 | |
Wu Zhangjin | 538f195 | 2009-11-20 20:34:32 +0800 | [diff] [blame] | 129 | #endif /* ! CONFIG_DYNAMIC_FTRACE */ |
| 130 | |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 131 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 132 | |
| 133 | NESTED(ftrace_graph_caller, PT_SIZE, ra) |
Wu Zhangjin | e17ff5f | 2009-11-20 20:34:35 +0800 | [diff] [blame] | 134 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 135 | PTR_L a1, PT_R31(sp) /* load the original ra from the stack */ |
| 136 | #else |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 137 | MCOUNT_SAVE_REGS |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 138 | move a1, ra /* arg2: next ip, selfaddr */ |
Wu Zhangjin | e17ff5f | 2009-11-20 20:34:35 +0800 | [diff] [blame] | 139 | #endif |
| 140 | PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */ |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 141 | jal prepare_ftrace_return |
Wu Zhangjin | 046199c | 2009-11-20 20:34:36 +0800 | [diff] [blame^] | 142 | #ifdef CONFIG_FRAME_POINTER |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 143 | move a2, fp /* arg3: frame pointer */ |
Wu Zhangjin | 046199c | 2009-11-20 20:34:36 +0800 | [diff] [blame^] | 144 | #else |
| 145 | #ifdef CONFIG_64BIT |
| 146 | PTR_LA a2, PT_SIZE(sp) |
| 147 | #else |
| 148 | PTR_LA a2, (PT_SIZE+8)(sp) |
| 149 | #endif |
| 150 | #endif |
Wu Zhangjin | 29c5d34 | 2009-11-20 20:34:34 +0800 | [diff] [blame] | 151 | |
| 152 | MCOUNT_RESTORE_REGS |
| 153 | RETURN_BACK |
| 154 | END(ftrace_graph_caller) |
| 155 | |
| 156 | .align 2 |
| 157 | .globl return_to_handler |
| 158 | return_to_handler: |
| 159 | PTR_SUBU sp, PT_SIZE |
| 160 | PTR_S v0, PT_R2(sp) |
| 161 | |
| 162 | jal ftrace_return_to_handler |
| 163 | PTR_S v1, PT_R3(sp) |
| 164 | |
| 165 | /* restore the real parent address: v0 -> ra */ |
| 166 | move ra, v0 |
| 167 | |
| 168 | PTR_L v0, PT_R2(sp) |
| 169 | PTR_L v1, PT_R3(sp) |
| 170 | jr ra |
| 171 | PTR_ADDIU sp, PT_SIZE |
| 172 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 173 | |
Wu Zhangjin | d2bb0762 | 2009-11-20 20:34:29 +0800 | [diff] [blame] | 174 | .set at |
| 175 | .set reorder |