MIPS: math-emu: Fix jalr emulation when rd == $0
authorPaul Burton <paul.burton@imgtec.com>
Thu, 21 Apr 2016 13:04:55 +0000 (14:04 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Fri, 13 May 2016 12:02:24 +0000 (14:02 +0200)
When emulating a jalr instruction with rd == $0, the code in
isBranchInstr was incorrectly writing to GPR $0 which should actually
always remain zeroed. This would lead to any further instructions
emulated which use $0 operating on a bogus value until the task is next
context switched, at which point the value of $0 in the task context
would be restored to the correct zero by a store in SAVE_SOME. Fix this
by not writing to rd if it is $0.

Fixes: 102cedc32a6e ("MIPS: microMIPS: Floating point support.")
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: Maciej W. Rozycki <macro@imgtec.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: stable <stable@vger.kernel.org> # v3.10
Patchwork: https://patchwork.linux-mips.org/patch/13160/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/math-emu/cp1emu.c

index 85dd17497151e063ee919f702e2b702dfe3669b7..d96e912b9d44fa7a077500e9ba884deb8caf3cbd 100644 (file)
@@ -445,9 +445,11 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
        case spec_op:
                switch (insn.r_format.func) {
                case jalr_op:
-                       regs->regs[insn.r_format.rd] =
-                               regs->cp0_epc + dec_insn.pc_inc +
-                               dec_insn.next_pc_inc;
+                       if (insn.r_format.rd != 0) {
+                               regs->regs[insn.r_format.rd] =
+                                       regs->cp0_epc + dec_insn.pc_inc +
+                                       dec_insn.next_pc_inc;
+                       }
                        /* Fall through */
                case jr_op:
                        /* For R6, JR already emulated in jalr_op */
This page took 0.02518 seconds and 5 git commands to generate.