===================================================================
@@ -18466,11 +18466,25 @@ static void decode_opc(CPUMIPSState *env
/* Handle blikely not taken case */
if ((ctx->hflags & MIPS_HFLAG_BMASK_BASE) == MIPS_HFLAG_BL) {
int l1 = gen_new_label();
+ uint32_t saved_hflags;
+ uint32_t bl_hflags;
MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
- tcg_gen_movi_i32(hflags, ctx->hflags & ~MIPS_HFLAG_BMASK);
+
+ /* Save and restore the state we're currently in (inside
+ a branch-likely delay), while clearing that state
+ as we exit the current TB. */
+ saved_hflags = ctx->saved_hflags;
+ bl_hflags = ctx->hflags;
+
+ ctx->hflags = bl_hflags & ~MIPS_HFLAG_BMASK;
+ save_cpu_state(ctx, 0);
gen_goto_tb(ctx, 1, ctx->pc + 4);
+
+ ctx->saved_hflags = saved_hflags;
+ ctx->hflags = bl_hflags;
+
gen_set_label(l1);
}