Skip to content

Commit a79a0cb

Browse files
committed
ARM: traps: use <asm/opcodes.h> to get correct instruction order
The trap handler needs to take into account the endian configuration of the system when loading instructions. Use <asm/opcodes.h> to provide the necessary conversion functions. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
1 parent 8592edf commit a79a0cb

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎arch/arm/kernel/traps.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <asm/unwind.h>
3535
#include <asm/tls.h>
3636
#include <asm/system_misc.h>
37+
#include <asm/opcodes.h>
3738

3839
static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };
3940

@@ -402,25 +403,28 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
402403
if (processor_mode(regs) == SVC_MODE) {
403404
#ifdef CONFIG_THUMB2_KERNEL
404405
if (thumb_mode(regs)) {
405-
instr = ((u16 *)pc)[0];
406+
instr = __mem_to_opcode_thumb16(((u16 *)pc)[0]);
406407
if (is_wide_instruction(instr)) {
407-
instr <<= 16;
408-
instr |= ((u16 *)pc)[1];
408+
u16 inst2;
409+
inst2 = __mem_to_opcode_thumb16(((u16 *)pc)[1]);
410+
instr = __opcode_thumb32_compose(instr, inst2);
409411
}
410412
} else
411413
#endif
412-
instr = *(u32 *) pc;
414+
instr = __mem_to_opcode_arm(*(u32 *) pc);
413415
} else if (thumb_mode(regs)) {
414416
if (get_user(instr, (u16 __user *)pc))
415417
goto die_sig;
418+
instr = __mem_to_opcode_thumb16(instr);
416419
if (is_wide_instruction(instr)) {
417420
unsigned int instr2;
418421
if (get_user(instr2, (u16 __user *)pc+1))
419422
goto die_sig;
420-
instr <<= 16;
421-
instr |= instr2;
423+
instr2 = __mem_to_opcode_thumb16(instr2);
424+
instr = __opcode_thumb32_compose(instr, instr2);
422425
}
423426
} else if (get_user(instr, (u32 __user *)pc)) {
427+
instr = __mem_to_opcode_arm(instr);
424428
goto die_sig;
425429
}
426430

0 commit comments

Comments
 (0)