From mboxrd@z Thu Jan 1 00:00:00 1970 From: will.deacon@arm.com (Will Deacon) Date: Wed, 24 Jul 2013 17:20:37 +0100 Subject: [PATCH 12/14] ARM: traps: use to get correct instruction order In-Reply-To: <1374661682-9349-13-git-send-email-ben.dooks@codethink.co.uk> References: <1374661682-9349-1-git-send-email-ben.dooks@codethink.co.uk> <1374661682-9349-13-git-send-email-ben.dooks@codethink.co.uk> Message-ID: <20130724162036.GS11072@mudshark.cambridge.arm.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Wed, Jul 24, 2013 at 11:28:00AM +0100, Ben Dooks wrote: > The trap handler needs to take into account the endian configuration of > the system when loading instructions. Use to provide the > necessary conversion functions. > > Signed-off-by: Ben Dooks > --- > arch/arm/kernel/traps.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c > index 18b32e8..c300e51 100644 > --- a/arch/arm/kernel/traps.c > +++ b/arch/arm/kernel/traps.c > @@ -34,6 +34,7 @@ > #include > #include > #include > +#include > > #include "signal.h" > > @@ -404,23 +405,24 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs) > if (processor_mode(regs) == SVC_MODE) { > #ifdef CONFIG_THUMB2_KERNEL > if (thumb_mode(regs)) { > - instr = ((u16 *)pc)[0]; > + instr = __mem_to_opcode_thumb16(((u16 *)pc)[0]); > if (is_wide_instruction(instr)) { > instr <<= 16; > - instr |= ((u16 *)pc)[1]; > + instr |= __mem_to_opcode_thumb16(((u16 *)pc)[1]); > } > } else > #endif > - instr = *(u32 *) pc; > + instr = __mem_to_opcode_arm(*(u32 *) pc); > } else if (thumb_mode(regs)) { > if (get_user(instr, (u16 __user *)pc)) > goto die_sig; > + instr = __mem_to_opcode_thumb16(instr); > if (is_wide_instruction(instr)) { > unsigned int instr2; > if (get_user(instr2, (u16 __user *)pc+1)) > goto die_sig; > instr <<= 16; > - instr |= instr2; > + instr |= __mem_to_opcode_thumb16(instr2); > } > } else if (get_user(instr, (u32 __user *)pc)) { > goto die_sig; Maybe it's also worth updating dump_instr, so that we don't confuse people by printing the faulting instruction in the wrong endianness. Will