Switch gen_exception_internal to gen_helper_raise_excp with restore 0, and drop TCG exception_internal. Keep syndrome helpers. Rename C raise_exception globals to arm_raise_exception*, and keep the short names as static inline wrappers in internals.h. Fold leftover C exits into cpu_loop_exit_excp. Keep arm_raise_exception_ra via restore then arm_raise_exception.
Signed-off-by: Yonggang Luo <[email protected]> --- target/arm/internals.h | 27 ++++++++++++++++------ target/arm/tcg-stubs.c | 4 ++-- target/arm/tcg/helper-defs.h | 1 - target/arm/tcg/m_helper.c | 3 ++- target/arm/tcg/op_helper.c | 43 +++++++++--------------------------- target/arm/tcg/translate.c | 2 +- 6 files changed, 36 insertions(+), 44 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index 1775835ad50..ee8ee766327 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -333,20 +333,33 @@ FIELD(FPMR, LSCALE2, 32, 6) #define M_FAKE_FSR_SFAULT 0xe /* SecureFault INVTRAN, INVEP or AUVIOL */ /** - * raise_exception: Raise the specified exception. + * arm_raise_exception: Raise the specified exception. * Raise a guest exception with the specified value, syndrome register * and target exception level. This should be called from helper functions, * and never returns because we will longjump back up to the CPU main loop. */ -G_NORETURN void raise_exception(CPUARMState *env, uint32_t excp, - uint64_t syndrome, uint32_t target_el); - +G_NORETURN void arm_raise_exception(CPUARMState *env, uint32_t excp, + uint64_t syndrome, uint32_t target_el); /* * Similarly, but also use unwinding to restore cpu state. */ -G_NORETURN void raise_exception_ra(CPUARMState *env, uint32_t excp, - uint64_t syndrome, uint32_t target_el, - uintptr_t ra); +G_NORETURN void arm_raise_exception_ra(CPUARMState *env, uint32_t excp, + uint64_t syndrome, uint32_t target_el, + uintptr_t ra); + +static inline G_NORETURN +void raise_exception(CPUARMState *env, uint32_t excp, + uint64_t syndrome, uint32_t target_el) +{ + arm_raise_exception(env, excp, syndrome, target_el); +} + +static inline G_NORETURN +void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, + uint32_t target_el, uintptr_t ra) +{ + arm_raise_exception_ra(env, excp, syndrome, target_el, ra); +} /* * For AArch64, map a given EL to an index in the banked_spsr array. diff --git a/target/arm/tcg-stubs.c b/target/arm/tcg-stubs.c index aeeede80661..7f9f684ed70 100644 --- a/target/arm/tcg-stubs.c +++ b/target/arm/tcg-stubs.c @@ -16,8 +16,8 @@ void write_v7m_exception(CPUARMState *env, uint32_t new_exc) g_assert_not_reached(); } -void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, - uint32_t target_el, uintptr_t ra) +void arm_raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, + uint32_t target_el, uintptr_t ra) { g_assert_not_reached(); } diff --git a/target/arm/tcg/helper-defs.h b/target/arm/tcg/helper-defs.h index 269ac515065..14ef3120373 100644 --- a/target/arm/tcg/helper-defs.h +++ b/target/arm/tcg/helper-defs.h @@ -45,7 +45,6 @@ DEF_HELPER_FLAGS_2(usad8, TCG_CALL_NO_RWG_SE, i32, i32, i32) DEF_HELPER_FLAGS_3(sel_flags, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) -DEF_HELPER_2(exception_internal, noreturn, env, i32) DEF_HELPER_3(exception_with_syndrome, noreturn, env, i32, i32) DEF_HELPER_4(exception_with_syndrome_el, noreturn, env, i32, i32, i32) DEF_HELPER_2(exception_bkpt_insn, noreturn, env, i32) diff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c index 33c9e7c55bc..161c5460217 100644 --- a/target/arm/tcg/m_helper.c +++ b/target/arm/tcg/m_helper.c @@ -18,6 +18,7 @@ #include "exec/page-protection.h" #ifdef CONFIG_TCG #include "accel/tcg/cpu-ldst-common.h" +#include "accel/tcg/cpu-loop.h" #include "semihosting/common-semi.h" #endif #if !defined(CONFIG_USER_ONLY) @@ -575,7 +576,7 @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest) */ env->regs[15] = dest & ~1; env->thumb = dest & 1; - HELPER(exception_internal)(env, EXCP_EXCEPTION_EXIT); + cpu_loop_exit_excp(env_cpu(env), EXCP_EXCEPTION_EXIT, 0); /* notreached */ } diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index c2b09176cb1..f1d1f52ccee 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -45,8 +45,8 @@ int exception_target_el(CPUARMState *env) return target_el; } -void raise_exception(CPUARMState *env, uint32_t excp, - uint64_t syndrome, uint32_t target_el) +void arm_raise_exception(CPUARMState *env, uint32_t excp, + uint64_t syndrome, uint32_t target_el) { CPUState *cs = env_cpu(env); @@ -64,14 +64,13 @@ void raise_exception(CPUARMState *env, uint32_t excp, } assert(!excp_is_internal(excp)); - cs->exception_index = excp; env->exception.syndrome = syndrome; env->exception.target_el = target_el; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, excp, 0); } -void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, - uint32_t target_el, uintptr_t ra) +void arm_raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, + uint32_t target_el, uintptr_t ra) { CPUState *cs = env_cpu(env); @@ -81,7 +80,7 @@ void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome, * the caller passed us, and cannot use cpu_loop_exit_restore(). */ cpu_restore_state(cs, ra); - raise_exception(env, excp, syndrome, target_el); + arm_raise_exception(env, excp, syndrome, target_el); } uint64_t HELPER(neon_tbl)(CPUARMState *env, uint32_t desc, @@ -399,9 +398,8 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len) } env->halt_reason = HALT_WFI; - cs->exception_index = EXCP_HLT; cs->halted = 1; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, EXCP_HLT, 0); #endif } @@ -461,9 +459,8 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd) timer_mod(cpu->wfxt_timer, nexttick); } env->halt_reason = HALT_WFI; - cs->exception_index = EXCP_HLT; cs->halted = 1; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, EXCP_HLT, 0); #endif } @@ -630,9 +627,8 @@ void HELPER(wfe)(CPUARMState *env, uint32_t insn_len) } env->halt_reason = HALT_WFE; - cs->exception_index = EXCP_HLT; cs->halted = 1; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, EXCP_HLT, 0); #endif } @@ -724,9 +720,8 @@ void HELPER(wfet)(CPUARMState *env, uint32_t rd) } env->halt_reason = HALT_WFE; - cs->exception_index = EXCP_HLT; cs->halted = 1; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, EXCP_HLT, 0); #endif } @@ -738,23 +733,7 @@ void HELPER(yield)(CPUARMState *env) * that the guest is currently busy-looping. Yield control back to the * top level loop so that a more deserving VCPU has a chance to run. */ - cs->exception_index = EXCP_YIELD; - cpu_loop_exit(cs); -} - -/* Raise an internal-to-QEMU exception. This is limited to only - * those EXCP values which are special cases for QEMU to interrupt - * execution and not to be used for exceptions which are passed to - * the guest (those must all have syndrome information and thus should - * use exception_with_syndrome*). - */ -void HELPER(exception_internal)(CPUARMState *env, uint32_t excp) -{ - CPUState *cs = env_cpu(env); - - assert(excp_is_internal(excp)); - cs->exception_index = excp; - cpu_loop_exit(cs); + cpu_loop_exit_excp(cs, EXCP_YIELD, 0); } /* Raise an exception with the specified syndrome register value */ diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index 8c56348a665..bc1dc101ff3 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -379,7 +379,7 @@ static void gen_rebuild_hflags(DisasContext *s, bool new_el) void gen_exception_internal(int excp) { assert(excp_is_internal(excp)); - gen_helper_exception_internal(tcg_env, tcg_constant_i32(excp)); + gen_helper_raise_excp(tcg_env, tcg_constant_i32(excp), tcg_constant_i32(0)); } static void gen_singlestep_exception(DisasContext *s) -- 2.52.0.windows.1
