aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel
diff options
context:
space:
mode:
authorWu Zhangjin <wuzhangjin@gmail.com>2011-01-19 14:28:31 -0500
committerRalf Baechle <ralf@linux-mips.org>2011-03-14 16:07:24 -0400
commit7f21a60968221eabad5c53fe760db3d094994011 (patch)
tree0b87d690d60ff0292d0088bfee6f1b3ca7ff3910 /arch/mips/kernel
parent2816e325969396af5bd1d5f70c7360074ae1d63c (diff)
MIPS, Tracing: Clean up ftrace_make_nop()
This moves the comments out of ftrace_make_nop() and cleans it. At the same time, a macro MCOUNT_OFFSET_INSNS is defined for sharing with the next patch. Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com> Cc: Steven Rostedt <srostedt@redhat.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/2008/ Signed-off-by: Ralf Baechle <ralf@duck.linux-mips.net>
Diffstat (limited to 'arch/mips/kernel')
-rw-r--r--arch/mips/kernel/ftrace.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
index 40ef34ccb76b..bc91e4aa08e9 100644
--- a/arch/mips/kernel/ftrace.c
+++ b/arch/mips/kernel/ftrace.c
@@ -24,8 +24,6 @@
24#define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */ 24#define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */
25#define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */ 25#define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */
26 26
27#define INSN_B_1F_4 0x10000004 /* b 1f; offset = 4 */
28#define INSN_B_1F_5 0x10000005 /* b 1f; offset = 5 */
29#define INSN_NOP 0x00000000 /* nop */ 27#define INSN_NOP 0x00000000 /* nop */
30#define INSN_JAL(addr) \ 28#define INSN_JAL(addr) \
31 ((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK))) 29 ((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK)))
@@ -84,6 +82,42 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
84 return 0; 82 return 0;
85} 83}
86 84
85/*
86 * The details about the calling site of mcount on MIPS
87 *
88 * 1. For kernel:
89 *
90 * move at, ra
91 * jal _mcount --> nop
92 *
93 * 2. For modules:
94 *
95 * 2.1 For KBUILD_MCOUNT_RA_ADDRESS and CONFIG_32BIT
96 *
97 * lui v1, hi_16bit_of_mcount --> b 1f (0x10000005)
98 * addiu v1, v1, low_16bit_of_mcount
99 * move at, ra
100 * move $12, ra_address
101 * jalr v1
102 * sub sp, sp, 8
103 * 1: offset = 5 instructions
104 * 2.2 For the Other situations
105 *
106 * lui v1, hi_16bit_of_mcount --> b 1f (0x10000004)
107 * addiu v1, v1, low_16bit_of_mcount
108 * move at, ra
109 * jalr v1
110 * nop | move $12, ra_address | sub sp, sp, 8
111 * 1: offset = 4 instructions
112 */
113
114#if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT)
115#define MCOUNT_OFFSET_INSNS 5
116#else
117#define MCOUNT_OFFSET_INSNS 4
118#endif
119#define INSN_B_1F (0x10000000 | MCOUNT_OFFSET_INSNS)
120
87int ftrace_make_nop(struct module *mod, 121int ftrace_make_nop(struct module *mod,
88 struct dyn_ftrace *rec, unsigned long addr) 122 struct dyn_ftrace *rec, unsigned long addr)
89{ 123{
@@ -94,36 +128,8 @@ int ftrace_make_nop(struct module *mod,
94 * If ip is in kernel space, no long call, otherwise, long call is 128 * If ip is in kernel space, no long call, otherwise, long call is
95 * needed. 129 * needed.
96 */ 130 */
97 if (in_kernel_space(ip)) { 131 new = in_kernel_space(ip) ? INSN_NOP : INSN_B_1F;
98 /* 132
99 * move at, ra
100 * jal _mcount --> nop
101 */
102 new = INSN_NOP;
103 } else {
104#if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT)
105 /*
106 * lui v1, hi_16bit_of_mcount --> b 1f (0x10000005)
107 * addiu v1, v1, low_16bit_of_mcount
108 * move at, ra
109 * move $12, ra_address
110 * jalr v1
111 * sub sp, sp, 8
112 * 1: offset = 5 instructions
113 */
114 new = INSN_B_1F_5;
115#else
116 /*
117 * lui v1, hi_16bit_of_mcount --> b 1f (0x10000004)
118 * addiu v1, v1, low_16bit_of_mcount
119 * move at, ra
120 * jalr v1
121 * nop | move $12, ra_address | sub sp, sp, 8
122 * 1: offset = 4 instructions
123 */
124 new = INSN_B_1F_4;
125#endif
126 }
127 return ftrace_modify_code(ip, new); 133 return ftrace_modify_code(ip, new);
128} 134}
129 135