ARM: 7330/1: ftrace: use canonical Thumb-2 wide instruction format
authorRabin Vincent <rabin@rab.in>
Sat, 18 Feb 2012 16:47:03 +0000 (17:47 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Sat, 24 Mar 2012 09:38:54 +0000 (09:38 +0000)
As commit 592201a9f15 (ARM: Thumb-2: Support Thumb-2 in undefined
instruction handler) says:

    32-bit Thumb instructions are specified in the form:
        ((first_half << 16 ) | second_half)
    which matches the layout used by the ARM ARM.

Convert the ftrace code to use the same format to avoid the usage of
different formats in kernel code.

Acked-by: Dave Martin <dave.martin@linaro.org>
Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/kernel/ftrace.c

index 6fd7c4a1e53263d7ad992a81abcbad62fff1f559..5c9cecfaeb21f529c566b0d085b57987bf0c1807 100644 (file)
 #include <linux/uaccess.h>
 
 #include <asm/cacheflush.h>
+#include <asm/opcodes.h>
 #include <asm/ftrace.h>
 
 #ifdef CONFIG_THUMB2_KERNEL
-#define        NOP             0xeb04f85d      /* pop.w {lr} */
+#define        NOP             0xf85deb04      /* pop.w {lr} */
 #else
 #define        NOP             0xe8bd4000      /* pop {lr} */
 #endif
@@ -88,7 +89,7 @@ static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
        if (link)
                second |= 1 << 14;
 
-       return (second << 16) | first;
+       return __opcode_thumb32_compose(first, second);
 }
 #else
 static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
@@ -125,6 +126,14 @@ static int ftrace_modify_code(unsigned long pc, unsigned long old,
 {
        unsigned long replaced;
 
+       if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
+               old = __opcode_to_mem_thumb32(old);
+               new = __opcode_to_mem_thumb32(new);
+       } else {
+               old = __opcode_to_mem_arm(old);
+               new = __opcode_to_mem_arm(new);
+       }
+
        if (validate) {
                if (probe_kernel_read(&replaced, (void *)pc, MCOUNT_INSN_SIZE))
                        return -EFAULT;