BBEQZC (MD01247 p.38) and BBNEZC (p.39) encode the bit number in
bits 16:11; bit 17 is 'x' (don't care). The decoder used the 7-bit
immediate (17:11) of the other P.BRI branches, so a set bit 17 gave
a bit number >= 64 and raised Reserved Instruction on cores without
64-bit operations. Decode only 6 bits for these two; BEQIC and the
other P.BRI branches really have a 7-bit u field.

Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 target/mips/tcg/nanomips_translate.c.inc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target/mips/tcg/nanomips_translate.c.inc 
b/target/mips/tcg/nanomips_translate.c.inc
index 3612c68561fd..68e9ca9cdb03 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4403,10 +4403,12 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, 
DisasContext *ctx)
         {
             int32_t s = sextract32(ctx->opcode, 0, 1) << 11 |
                         extract32(ctx->opcode, 1, 10) << 1;
-            uint32_t u = extract32(ctx->opcode, 11, 7);
+            uint32_t opc = extract32(ctx->opcode, 18, 3);
+            uint32_t u = extract32(ctx->opcode, 11,
+                                   (opc == NM_BBEQZC ||
+                                    opc == NM_BBNEZC) ? 6 : 7);
 
-            gen_compute_imm_branch(ctx, extract32(ctx->opcode, 18, 3),
-                                   rt, u, s);
+            gen_compute_imm_branch(ctx, opc, rt, u, s);
         }
         break;
     default:
-- 
2.55.0


Reply via email to