Commit c8a34581 authored by Markos Chandras's avatar Markos Chandras

MIPS: Emulate the BC1{EQ,NE}Z FPU instructions

MIPS R6 introduced the following two branch instructions for COP1:

BC1EQZ: Branch if Cop1 (FPR) Register Bit 0 is Equal to Zero
BC1NEZ: Branch if Cop1 (FPR) Register Bit 0 is Not Equal to Zero
Signed-off-by: default avatarMarkos Chandras <markos.chandras@imgtec.com>
parent 319824ea
...@@ -115,7 +115,8 @@ enum cop_op { ...@@ -115,7 +115,8 @@ enum cop_op {
mfhc_op = 0x03, mtc_op = 0x04, mfhc_op = 0x03, mtc_op = 0x04,
dmtc_op = 0x05, ctc_op = 0x06, dmtc_op = 0x05, ctc_op = 0x06,
mthc0_op = 0x06, mthc_op = 0x07, mthc0_op = 0x06, mthc_op = 0x07,
bc_op = 0x08, cop_op = 0x10, bc_op = 0x08, bc1eqz_op = 0x09,
bc1nez_op = 0x0d, cop_op = 0x10,
copm_op = 0x18 copm_op = 0x18
}; };
......
...@@ -403,7 +403,7 @@ int __MIPS16e_compute_return_epc(struct pt_regs *regs) ...@@ -403,7 +403,7 @@ int __MIPS16e_compute_return_epc(struct pt_regs *regs)
int __compute_return_epc_for_insn(struct pt_regs *regs, int __compute_return_epc_for_insn(struct pt_regs *regs,
union mips_instruction insn) union mips_instruction insn)
{ {
unsigned int bit, fcr31, dspcontrol; unsigned int bit, fcr31, dspcontrol, reg;
long epc = regs->cp0_epc; long epc = regs->cp0_epc;
int ret = 0; int ret = 0;
...@@ -618,40 +618,83 @@ int __compute_return_epc_for_insn(struct pt_regs *regs, ...@@ -618,40 +618,83 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
* And now the FPA/cp1 branch instructions. * And now the FPA/cp1 branch instructions.
*/ */
case cop1_op: case cop1_op:
preempt_disable(); if (cpu_has_mips_r6 &&
if (is_fpu_owner()) ((insn.i_format.rs == bc1eqz_op) ||
fcr31 = read_32bit_cp1_register(CP1_STATUS); (insn.i_format.rs == bc1nez_op))) {
else if (!used_math()) { /* First time FPU user */
fcr31 = current->thread.fpu.fcr31; ret = init_fpu();
preempt_enable(); if (ret && NO_R6EMU) {
ret = -ret;
bit = (insn.i_format.rt >> 2); break;
bit += (bit != 0); }
bit += 23; ret = 0;
switch (insn.i_format.rt & 3) { set_used_math();
case 0: /* bc1f */ }
case 2: /* bc1fl */ lose_fpu(1); /* Save FPU state for the emulator. */
if (~fcr31 & (1 << bit)) { reg = insn.i_format.rt;
epc = epc + 4 + (insn.i_format.simmediate << 2); bit = 0;
if (insn.i_format.rt == 2) switch (insn.i_format.rs) {
ret = BRANCH_LIKELY_TAKEN; case bc1eqz_op:
} else /* Test bit 0 */
if (get_fpr32(&current->thread.fpu.fpr[reg], 0)
& 0x1)
bit = 1;
break;
case bc1nez_op:
/* Test bit 0 */
if (!(get_fpr32(&current->thread.fpu.fpr[reg], 0)
& 0x1))
bit = 1;
break;
}
own_fpu(1);
if (bit)
epc = epc + 4 +
(insn.i_format.simmediate << 2);
else
epc += 8; epc += 8;
regs->cp0_epc = epc; regs->cp0_epc = epc;
break; break;
} else {
case 1: /* bc1t */ preempt_disable();
case 3: /* bc1tl */ if (is_fpu_owner())
if (fcr31 & (1 << bit)) { fcr31 = read_32bit_cp1_register(CP1_STATUS);
epc = epc + 4 + (insn.i_format.simmediate << 2); else
if (insn.i_format.rt == 3) fcr31 = current->thread.fpu.fcr31;
ret = BRANCH_LIKELY_TAKEN; preempt_enable();
} else
epc += 8; bit = (insn.i_format.rt >> 2);
regs->cp0_epc = epc; bit += (bit != 0);
bit += 23;
switch (insn.i_format.rt & 3) {
case 0: /* bc1f */
case 2: /* bc1fl */
if (~fcr31 & (1 << bit)) {
epc = epc + 4 +
(insn.i_format.simmediate << 2);
if (insn.i_format.rt == 2)
ret = BRANCH_LIKELY_TAKEN;
} else
epc += 8;
regs->cp0_epc = epc;
break;
case 1: /* bc1t */
case 3: /* bc1tl */
if (fcr31 & (1 << bit)) {
epc = epc + 4 +
(insn.i_format.simmediate << 2);
if (insn.i_format.rt == 3)
ret = BRANCH_LIKELY_TAKEN;
} else
epc += 8;
regs->cp0_epc = epc;
break;
}
break; break;
} }
break;
#ifdef CONFIG_CPU_CAVIUM_OCTEON #ifdef CONFIG_CPU_CAVIUM_OCTEON
case lwc2_op: /* This is bbit0 on Octeon */ case lwc2_op: /* This is bbit0 on Octeon */
if ((regs->regs[insn.i_format.rs] & (1ull<<insn.i_format.rt)) if ((regs->regs[insn.i_format.rs] & (1ull<<insn.i_format.rt))
......
...@@ -602,6 +602,33 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn, ...@@ -602,6 +602,33 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
#endif #endif
case cop0_op: case cop0_op:
case cop1_op: case cop1_op:
/* Need to check for R6 bc1nez and bc1eqz branches */
if (cpu_has_mips_r6 &&
((insn.i_format.rs == bc1eqz_op) ||
(insn.i_format.rs == bc1nez_op))) {
bit = 0;
switch (insn.i_format.rs) {
case bc1eqz_op:
if (get_fpr32(&current->thread.fpu.fpr[insn.i_format.rt], 0) & 0x1)
bit = 1;
break;
case bc1nez_op:
if (!(get_fpr32(&current->thread.fpu.fpr[insn.i_format.rt], 0) & 0x1))
bit = 1;
break;
}
if (bit)
*contpc = regs->cp0_epc +
dec_insn.pc_inc +
(insn.i_format.simmediate << 2);
else
*contpc = regs->cp0_epc +
dec_insn.pc_inc +
dec_insn.next_pc_inc;
return 1;
}
/* R2/R6 compatible cop1 instruction. Fall through */
case cop2_op: case cop2_op:
case cop1x_op: case cop1x_op:
if (insn.i_format.rs == bc_op) { if (insn.i_format.rs == bc_op) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment