aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorWu Zhangjin <wuzhangjin@gmail.com>2010-05-14 07:08:31 -0400
committerRalf Baechle <ralf@linux-mips.org>2010-07-05 12:17:29 -0400
commit4d6829f92a02d96e1bec2ffe6ee674ef3b49722b (patch)
treee2fe7f3058f68e1ae1c9b26dedb6cc18f46ce12a /arch
parent3a2af2dc1bcbfe86b1f39e9e5f9c2c5447943f16 (diff)
MIPS: Tracing: Cleanup of instructions used
This patch adds some cleanups of the instructions: o use macros instead of magic numbers o use macros instead of variables to reduce some overhead o add new macro for the jal instruction Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com> Cc: linux-mips <linux-mips@linux-mips.org> Cc: David Daney <david.s.daney@gmail.com> Patchwork: http://patchwork.linux-mips.org/patch/1229/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/kernel/ftrace.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
index 37aa7677e76d..b1b8fec2432f 100644
--- a/arch/mips/kernel/ftrace.c
+++ b/arch/mips/kernel/ftrace.c
@@ -23,7 +23,10 @@
23#define jump_insn_encode(op_code, addr) \ 23#define jump_insn_encode(op_code, addr) \
24 ((unsigned int)((op_code) | (((addr) >> 2) & ADDR_MASK))) 24 ((unsigned int)((op_code) | (((addr) >> 2) & ADDR_MASK)))
25 25
26static unsigned int ftrace_nop = 0x00000000; 26#define INSN_B_1F_4 0x10000004 /* b 1f; offset = 4 */
27#define INSN_B_1F_5 0x10000005 /* b 1f; offset = 5 */
28#define INSN_NOP 0x00000000 /* nop */
29#define INSN_JAL(addr) jump_insn_encode(JAL, addr)
27 30
28static int ftrace_modify_code(unsigned long ip, unsigned int new_code) 31static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
29{ 32{
@@ -71,7 +74,7 @@ int ftrace_make_nop(struct module *mod,
71 * sub sp, sp, 8 74 * sub sp, sp, 8
72 * 1: offset = 5 instructions 75 * 1: offset = 5 instructions
73 */ 76 */
74 new = 0x10000005; 77 new = INSN_B_1F_5;
75#else 78#else
76 /* lui v1, hi_16bit_of_mcount --> b 1f (0x10000004) 79 /* lui v1, hi_16bit_of_mcount --> b 1f (0x10000004)
77 * addiu v1, v1, low_16bit_of_mcount 80 * addiu v1, v1, low_16bit_of_mcount
@@ -80,7 +83,7 @@ int ftrace_make_nop(struct module *mod,
80 * nop | move $12, ra_address | sub sp, sp, 8 83 * nop | move $12, ra_address | sub sp, sp, 8
81 * 1: offset = 4 instructions 84 * 1: offset = 4 instructions
82 */ 85 */
83 new = 0x10000004; 86 new = INSN_B_1F_4;
84#endif 87#endif
85 } else { 88 } else {
86 /* record/calculate it for ftrace_make_call */ 89 /* record/calculate it for ftrace_make_call */
@@ -88,13 +91,13 @@ int ftrace_make_nop(struct module *mod,
88 /* We can record it directly like this: 91 /* We can record it directly like this:
89 * jal_mcount = *(unsigned int *)ip; 92 * jal_mcount = *(unsigned int *)ip;
90 * Herein, jump over the first two nop instructions */ 93 * Herein, jump over the first two nop instructions */
91 jal_mcount = jump_insn_encode(JAL, (MCOUNT_ADDR + 8)); 94 jal_mcount = INSN_JAL(MCOUNT_ADDR + 8);
92 } 95 }
93 96
94 /* move at, ra 97 /* move at, ra
95 * jalr v1 --> nop 98 * jalr v1 --> nop
96 */ 99 */
97 new = ftrace_nop; 100 new = INSN_NOP;
98 } 101 }
99 return ftrace_modify_code(ip, new); 102 return ftrace_modify_code(ip, new);
100} 103}
@@ -109,7 +112,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
109 /* We just need to remove the "b ftrace_stub" at the fist time! */ 112 /* We just need to remove the "b ftrace_stub" at the fist time! */
110 if (modified == 0) { 113 if (modified == 0) {
111 modified = 1; 114 modified = 1;
112 ftrace_modify_code(addr, ftrace_nop); 115 ftrace_modify_code(addr, INSN_NOP);
113 } 116 }
114 /* ip, module: 0xc0000000, kernel: 0x80000000 */ 117 /* ip, module: 0xc0000000, kernel: 0x80000000 */
115 new = (ip & 0x40000000) ? lui_v1 : jal_mcount; 118 new = (ip & 0x40000000) ? lui_v1 : jal_mcount;
@@ -123,7 +126,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
123{ 126{
124 unsigned int new; 127 unsigned int new;
125 128
126 new = jump_insn_encode(JAL, (unsigned long)func); 129 new = INSN_JAL((unsigned long)func);
127 130
128 return ftrace_modify_code(FTRACE_CALL_IP, new); 131 return ftrace_modify_code(FTRACE_CALL_IP, new);
129} 132}
@@ -155,7 +158,7 @@ int ftrace_enable_ftrace_graph_caller(void)
155 158
156int ftrace_disable_ftrace_graph_caller(void) 159int ftrace_disable_ftrace_graph_caller(void)
157{ 160{
158 return ftrace_modify_code(FTRACE_GRAPH_CALL_IP, ftrace_nop); 161 return ftrace_modify_code(FTRACE_GRAPH_CALL_IP, INSN_NOP);
159} 162}
160 163
161#endif /* !CONFIG_DYNAMIC_FTRACE */ 164#endif /* !CONFIG_DYNAMIC_FTRACE */