Generate exceptions with gen_helper_raise_excp() and gen_helper_raise_excp_restore(), storing error_code in CPUMIPSState before raising. Route do_raise_exception_err() through cpu_raise_excp_restore() to preserve guest-state restoration.
Signed-off-by: Yonggang Luo <[email protected]> --- target/mips/cpu.h | 2 +- target/mips/helper.h | 4 ---- target/mips/tcg/exception.c | 20 +------------------- target/mips/tcg/translate.c | 9 ++++++--- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index 32549791a18..b6bb9028ecf 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -1141,7 +1141,7 @@ typedef struct CPUArchState { TCState tcs[MIPS_SHADOW_SET_MAX]; CPUMIPSFPUContext fpus[MIPS_FPU_MAX]; /* QEMU */ - int error_code; + int32_t error_code; #define EXCP_TLB_NOMATCH 0x1 #define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */ uint32_t hflags; /* CPU State */ diff --git a/target/mips/helper.h b/target/mips/helper.h index 779b87101db..83a6dd0b3c4 100644 --- a/target/mips/helper.h +++ b/target/mips/helper.h @@ -1,7 +1,3 @@ -DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) -DEF_HELPER_2(raise_exception, noreturn, env, i32) -DEF_HELPER_1(raise_exception_debug, noreturn, env) - #ifdef TARGET_MIPS64 DEF_HELPER_4(sdl, void, env, tl, tl, int) DEF_HELPER_4(sdr, void, env, tl, tl, int) diff --git a/target/mips/tcg/exception.c b/target/mips/tcg/exception.c index 514880ccba8..20705192988 100644 --- a/target/mips/tcg/exception.c +++ b/target/mips/tcg/exception.c @@ -44,22 +44,6 @@ target_ulong exception_resume_pc(CPUMIPSState *env) return bad_pc; } -void helper_raise_exception_err(CPUMIPSState *env, uint32_t exception, - int error_code) -{ - do_raise_exception_err(env, exception, error_code, 0); -} - -void helper_raise_exception(CPUMIPSState *env, uint32_t exception) -{ - do_raise_exception(env, exception, GETPC()); -} - -void helper_raise_exception_debug(CPUMIPSState *env) -{ - do_raise_exception(env, EXCP_DEBUG, 0); -} - void helper_wait(CPUMIPSState *env) { CPUState *cs = env_cpu(env); @@ -140,8 +124,6 @@ void do_raise_exception_err(CPUMIPSState *env, uint32_t exception, qemu_log_mask(CPU_LOG_INT, "%s: %d (%s) %d\n", __func__, exception, mips_exception_name(exception), error_code); - cs->exception_index = exception; env->error_code = error_code; - - cpu_loop_exit_restore(cs, pc); + cpu_raise_excp_restore(cs, exception, pc); } diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 936f8c4eddc..81c4301f625 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -1316,14 +1316,17 @@ static inline void restore_cpu_state(CPUMIPSState *env, DisasContext *ctx) void generate_exception_err(DisasContext *ctx, int excp, int err) { save_cpu_state(ctx, 1); - gen_helper_raise_exception_err(tcg_env, tcg_constant_i32(excp), - tcg_constant_i32(err)); + tcg_gen_st_i32(tcg_constant_i32(err), tcg_env, + offsetof(CPUMIPSState, error_code)); + gen_helper_raise_excp(tcg_env, tcg_constant_i32(excp)); ctx->base.is_jmp = DISAS_NORETURN; } void generate_exception(DisasContext *ctx, int excp) { - gen_helper_raise_exception(tcg_env, tcg_constant_i32(excp)); + tcg_gen_st_i32(tcg_constant_i32(0), tcg_env, + offsetof(CPUMIPSState, error_code)); + gen_helper_raise_excp_restore(tcg_env, tcg_constant_i32(excp)); } void generate_exception_end(DisasContext *ctx, int excp) -- 2.52.0.windows.1
