Skip to content

Commit 5f9f41c

Browse files
author
Markos Chandras
committed
MIPS: kernel: Prepare the JR instruction for emulation on MIPS R6
The MIPS R6 JR instruction is an alias to the JALR one, so it may need emulation for non-R6 userlands. Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
1 parent b5ad2c2 commit 5f9f41c

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎arch/mips/include/asm/branch.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <asm/ptrace.h>
1414
#include <asm/inst.h>
1515

16+
static int mipsr2_emulation = 0;
17+
#define NO_R6EMU (cpu_has_mips_r6 && !mipsr2_emulation)
18+
1619
extern int __isa_exception_epc(struct pt_regs *regs);
1720
extern int __compute_return_epc(struct pt_regs *regs);
1821
extern int __compute_return_epc_for_insn(struct pt_regs *regs,

‎arch/mips/kernel/branch.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
417417
regs->regs[insn.r_format.rd] = epc + 8;
418418
/* Fall through */
419419
case jr_op:
420+
if (NO_R6EMU && insn.r_format.func == jr_op)
421+
goto sigill_r6;
420422
regs->cp0_epc = regs->regs[insn.r_format.rs];
421423
break;
422424
}
@@ -477,7 +479,7 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
477479

478480
case bposge32_op:
479481
if (!cpu_has_dsp)
480-
goto sigill;
482+
goto sigill_dsp;
481483

482484
dspcontrol = rddsp(0x01);
483485

@@ -631,10 +633,15 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
631633

632634
return ret;
633635

634-
sigill:
636+
sigill_dsp:
635637
printk("%s: DSP branch but not DSP ASE - sending SIGBUS.\n", current->comm);
636638
force_sig(SIGBUS, current);
637639
return -EFAULT;
640+
sigill_r6:
641+
pr_info("%s: R2 branch but r2-to-r6 emulator is not preset - sending SIGILL.\n",
642+
current->comm);
643+
force_sig(SIGILL, current);
644+
return -EFAULT;
638645
}
639646
EXPORT_SYMBOL_GPL(__compute_return_epc_for_insn);
640647

‎arch/mips/math-emu/cp1emu.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
448448
dec_insn.next_pc_inc;
449449
/* Fall through */
450450
case jr_op:
451+
/* For R6, JR already emulated in jalr_op */
452+
if (NO_R6EMU && insn.r_format.opcode == jr_op)
453+
break;
451454
*contpc = regs->regs[insn.r_format.rs];
452455
return 1;
453456
}

0 commit comments

Comments
 (0)