Commit 7f21a609 authored by Wu Zhangjin's avatar Wu Zhangjin Committed by Ralf Baechle

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: default avatarWu 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: default avatarRalf Baechle <ralf@duck.linux-mips.net>
parent 2816e325
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */ #define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */
#define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */ #define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */
#define INSN_B_1F_4 0x10000004 /* b 1f; offset = 4 */
#define INSN_B_1F_5 0x10000005 /* b 1f; offset = 5 */
#define INSN_NOP 0x00000000 /* nop */ #define INSN_NOP 0x00000000 /* nop */
#define INSN_JAL(addr) \ #define INSN_JAL(addr) \
((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK))) ((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK)))
...@@ -84,25 +82,18 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code) ...@@ -84,25 +82,18 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
return 0; return 0;
} }
int ftrace_make_nop(struct module *mod, /*
struct dyn_ftrace *rec, unsigned long addr) * The details about the calling site of mcount on MIPS
{ *
unsigned int new; * 1. For kernel:
unsigned long ip = rec->ip; *
/*
* If ip is in kernel space, no long call, otherwise, long call is
* needed.
*/
if (in_kernel_space(ip)) {
/*
* move at, ra * move at, ra
* jal _mcount --> nop * jal _mcount --> nop
*/ *
new = INSN_NOP; * 2. For modules:
} else { *
#if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT) * 2.1 For KBUILD_MCOUNT_RA_ADDRESS and CONFIG_32BIT
/* *
* lui v1, hi_16bit_of_mcount --> b 1f (0x10000005) * lui v1, hi_16bit_of_mcount --> b 1f (0x10000005)
* addiu v1, v1, low_16bit_of_mcount * addiu v1, v1, low_16bit_of_mcount
* move at, ra * move at, ra
...@@ -110,10 +101,8 @@ int ftrace_make_nop(struct module *mod, ...@@ -110,10 +101,8 @@ int ftrace_make_nop(struct module *mod,
* jalr v1 * jalr v1
* sub sp, sp, 8 * sub sp, sp, 8
* 1: offset = 5 instructions * 1: offset = 5 instructions
*/ * 2.2 For the Other situations
new = INSN_B_1F_5; *
#else
/*
* lui v1, hi_16bit_of_mcount --> b 1f (0x10000004) * lui v1, hi_16bit_of_mcount --> b 1f (0x10000004)
* addiu v1, v1, low_16bit_of_mcount * addiu v1, v1, low_16bit_of_mcount
* move at, ra * move at, ra
...@@ -121,9 +110,26 @@ int ftrace_make_nop(struct module *mod, ...@@ -121,9 +110,26 @@ int ftrace_make_nop(struct module *mod,
* nop | move $12, ra_address | sub sp, sp, 8 * nop | move $12, ra_address | sub sp, sp, 8
* 1: offset = 4 instructions * 1: offset = 4 instructions
*/ */
new = INSN_B_1F_4;
#if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT)
#define MCOUNT_OFFSET_INSNS 5
#else
#define MCOUNT_OFFSET_INSNS 4
#endif #endif
} #define INSN_B_1F (0x10000000 | MCOUNT_OFFSET_INSNS)
int ftrace_make_nop(struct module *mod,
struct dyn_ftrace *rec, unsigned long addr)
{
unsigned int new;
unsigned long ip = rec->ip;
/*
* If ip is in kernel space, no long call, otherwise, long call is
* needed.
*/
new = in_kernel_space(ip) ? INSN_NOP : INSN_B_1F;
return ftrace_modify_code(ip, new); return ftrace_modify_code(ip, new);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment