accel/tcg: share raise_excp across TCG targets
Subsystems (2)
v3 cover accel/tcg: share raise_excp across TCG targets
Many TCG targets copy the same two-line raise: set cs->exception_index and call cpu_loop_exit_restore. They also copy DEF_HELPER_2(raise_exception, ...). helper_raise_exception is a global C symbol, so a unified binary cannot keep that name on more than one target.
This series adds two shared C exits and two shared TCG helpers, then converts one target per commit. Joiners call gen_helper_raise_excp or gen_helper_raise_excp_restore and drop the copied DEF. The shared helpers only touch CPUState. Translate may store arch state (error_code, PC) first. A callback that may pass a zero retaddr keeps the explicit cpu_loop_exit_restore form. Guest trap numbers stay below 0x10000. TCG loop codes such as EXCP_INTERRUPT start at 0x10000.
- Move helper_exit_atomic into cpu-exec-common.c with its DEF_HELPER, so the new helpers can sit beside it.
- Add cpu_raise_excp and cpu_raise_excp_restore next to cpu_loop_exit_restore. The first sets exception_index and exits without restoring guest state. The second restores from a nonzero retaddr, and skips restore when retaddr is 0.
- Add TCG raise_excp and raise_excp_restore beside those exits. raise_excp calls cpu_raise_excp. raise_excp_restore calls cpu_raise_excp_restore with GETPC(). Each helper does one thing.
- Unify RX BRK and INT, then define RX and SH4 exception vectors and use them at the raise sites. Log the previously unnamed SH4 vectors. Join privilege and illegal on RX through raise_excp_restore, and BRK and INT through raise_excp. Join illegal, slot-illegal, and FPU-disable on SH4. Keep RX wait and SH4 sleep, trapa, and exclusive.
- Drop HPPA helper_excp, then drop hppa_dynamic_excp. Convert the remaining joiners one arch per commit: m68k, or1k, microblaze, sparc, loongarch, s390x, xtensa, avr, arm exception_internal, mips, and ppc. Store error_code or PC in translate where needed, then call the shared helper. loongarch and the mips 2-arg path use raise_excp_restore. C wrappers that only forward stay static inline.
- Reset Xtensa yield_needed in gen_yield before that conversion. Reuse the ppc error-aware NIP path before the ppc conversion. Call MIPS do_raise_exception directly from the FPU helpers before the MIPS conversion.
- Keep riscv and hexagon TCG raise_exception. riscv still decrements instret, and hexagon still logs, stores PC, and asserts. Their C exits call cpu_raise_excp_restore. Tricore raise_exception_sync, alpha excp, and i386 raise_exception do not join.
v1: https://patchew.org/QEMU/[email protected]/
v2: https://patchew.org/QEMU/[email protected]/
Changes v2 -> v3:
- Replace cpu_loop_exit_excp with cpu_raise_excp and cpu_raise_excp_restore. The no-restore path has no retaddr argument. The restore path restores only when retaddr is nonzero.
- Split the HPPA conversion. Drop helper_excp, then drop hppa_dynamic_excp.
- Define RX and SH4 vectors in the commits that use them. Take Philippe's RX BRK and INT unification. Log the unnamed SH4 vectors in its own commit.
- Do not prefix riscv or hexagon TCG raise_exception. Keep their extra work in those helpers, and route the C exits through cpu_raise_excp_restore.
- Omit the alpha conversion. On microblaze, keep the MMU callback on cpu_loop_exit_restore when retaddr may be zero.
Changes v1 -> v2:
- Move helper_exit_atomic into cpu-exec-common.c. Split the restore flag into raise_excp and raise_excp_restore, and define both there.
- Drop the helper-gen nested-extern change.
- Shorten the cpu_loop_exit_excp comment. Drop the generic EXCP_INTERRUPT note on the RX and SH4 trap enums, and put those enums in their own commits.
- Split xtensa gen_yield and the ppc gen_exception_nip fold out of the conversion commits.
- Omit the i386 conversion, the rx, mips, and hexagon helper_wait renames, and the arm raise_exception rename.
Philippe Mathieu-Daudé (1):
target/rx: Unify BRK and INT trap handling
Yonggang Luo (26):
accel/tcg: move helper_exit_atomic next to cpu_loop_exit_atomic accel/tcg: add cpu_raise_excp and cpu_raise_excp_restore helpers accel/tcg: add raise_excp and raise_excp_restore generator helpers target/rx: Define exception vector constants target/sh4: Define exception vector constants target/hppa: remove helper_excp
target/hppa: remove hppa_dynamic_excp
target/rx: convert raises to raise_excp
target/sh4: log all exception vector names
target/sh4: convert raises to raise_excp
target/s390x: convert exception to raise_excp target/m68k: convert raises to raise_excp
target/or1k: convert exception to raise_excp target/microblaze: convert raise_exception to raise_excp target/sparc: convert raise_exception to raise_excp target/loongarch: convert raise_exception to raise_excp target/hexagon: reuse cpu_raise_excp_restore target/xtensa: reset yield state in the icount path target/xtensa: convert exception to raise_excp target/avr: convert debug/break/sleep to raise_excp target/arm: convert exception_internal to raise_excp target/riscv: use cpu_raise_excp_restore for exception exits target/mips: call do_raise_exception directly target/mips: use shared TCG exception helpers target/ppc: reuse the error-aware NIP exception path target/ppc: use shared helpers for translated exceptions
accel/tcg/cpu-exec-common.c | 35 +++++++++++++++ accel/tcg/cpu-exec-common.h | 4 ++ accel/tcg/tcg-runtime.c | 8 ---- accel/tcg/tcg-runtime.h | 2 - include/accel/tcg/cpu-loop.h | 22 +++++++++ include/exec/helper-gen-common.h | 4 ++ include/exec/helper-proto-common.h | 4 ++ target/arm/tcg/helper-defs.h | 1 - target/arm/tcg/m_helper.c | 3 +- target/arm/tcg/op_helper.c | 33 +++----------- target/arm/tcg/translate.c | 2 +- target/avr/helper.c | 24 ---------- target/avr/helper.h | 3 -- target/avr/translate.c | 4 +- target/hexagon/internal.h | 10 ++++- target/hexagon/op_helper.c | 5 +-- target/hppa/cpu.h | 1 - target/hppa/fpu_helper.c | 3 +- target/hppa/helper.h | 2 - target/hppa/op_helper.c | 18 +------- target/hppa/sys_helper.c | 5 ++- target/hppa/translate.c | 2 +- target/loongarch/internals.h | 12 +++-- target/loongarch/tcg/helper.h | 2 - target/loongarch/tcg/op_helper.c | 6 --- target/loongarch/tcg/tcg_cpu.c | 10 ++--- target/loongarch/tcg/translate.c | 2 +- target/m68k/helper.c | 12 +---- target/m68k/helper.h | 1 - target/m68k/op_helper.c | 19 -------- target/m68k/translate.c | 2 +- target/microblaze/helper.h | 2 - target/microblaze/op_helper.c | 19 ++------ target/microblaze/translate.c | 2 +- target/mips/cpu.h | 2 +- target/mips/helper.h | 4 -- target/mips/tcg/exception.c | 27 +---------- target/mips/tcg/fpu_helper.c | 6 +-- target/mips/tcg/translate.c | 9 ++-- target/or1k/exception.c | 31 ------------- target/or1k/exception.h | 7 ++- target/or1k/exception_helper.c | 13 +----- target/or1k/helper.h | 1 - target/or1k/meson.build | 1 - target/or1k/translate.c | 2 +- target/ppc/cpu.h | 5 +-- target/ppc/helper.h | 2 - target/ppc/internal.h | 9 ++++ target/ppc/misc_helper.c | 1 + target/ppc/tcg-excp_helper.c | 21 --------- target/ppc/timebase_helper.c | 1 + target/ppc/translate.c | 20 +++------ target/riscv/tcg/op_helper.c | 3 +- target/rx/cpu.h | 13 ++++++ target/rx/helper.c | 21 ++++----- target/rx/helper.h | 5 --- target/rx/op_helper.c | 44 +----------------- target/rx/translate.c | 28 ++++++------ target/s390x/helper.h | 1 - target/s390x/tcg/mem_helper.c | 2 +- target/s390x/tcg/misc_helper.c | 10 ----- target/s390x/tcg/translate.c | 2 +- target/sh4/cpu.h | 21 +++++++++ target/sh4/helper.c | 72 +++++++++++++++++------------- target/sh4/helper.h | 4 -- target/sh4/op_helper.c | 40 +++-------------- target/sh4/translate.c | 12 +++-- target/sparc/helper.c | 21 ++------- target/sparc/helper.h | 2 - target/sparc/translate.c | 6 +-- target/xtensa/cpu.h | 2 +- target/xtensa/exc_helper.c | 17 ++----- target/xtensa/helper.h | 1 - target/xtensa/translate.c | 8 ++-- target/xtensa/win_helper.c | 13 +++--- 75 files changed, 300 insertions(+), 494 deletions(-) create mode 100644 accel/tcg/cpu-exec-common.h delete mode 100644 target/or1k/exception.c
Signature · 1 line
2.52.0.windows.1
PATCH v3 1/27 accel/tcg: move helper_exit_atomic next to cpu_loop_exit_atomic
helper_exit_atomic only forwards to cpu_loop_exit_atomic. Define it in cpu-exec-common.c with that function, and move its DEF_HELPER line to cpu-exec-common.h. That file emits helper_info_exit_atomic. tcg-runtime.c keeps the integer helpers.
--- accel/tcg/cpu-exec-common.c | 10 ++++++++++ accel/tcg/cpu-exec-common.h | 2 ++ accel/tcg/tcg-runtime.c | 8 -------- accel/tcg/tcg-runtime.h | 2 -- include/exec/helper-gen-common.h | 4 ++++ include/exec/helper-proto-common.h | 4 ++++ 6 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 accel/tcg/cpu-exec-common.h
accel/tcg/cpu-exec-common.c +10 -0
@@ -23,8 +23,13 @@#include "qemu/plugin.h" #include "qemu/main-loop.h" #include "accel/tcg/cpu-loop.h" +#include "exec/helper-proto-common.h" #include "internal-common.h" +#define HELPER_H "accel/tcg/cpu-exec-common.h" +#include "exec/helper-info.c.inc" +#undef HELPER_H +bool tcg_allowed;/*
@@ -120,3 +125,8 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) cpu->exception_index =EXCP_ATOMIC ;cpu_loop_exit_restore (cpu, pc); } + +void HELPER (exit_atomic )(CPUArchState *env) +{ +cpu_loop_exit_atomic (env_cpu (env),GETPC ()); +}
accel/tcg/cpu-exec-common.h new file +2 -0
@@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +DEF_HELPER_FLAGS_1 (exit_atomic,TCG_CALL_NO_WG , noreturn, env)
accel/tcg/tcg-runtime.c +0 -8
@@ -23,10 +23,7 @@*/ #include "qemu/osdep.h" #include "qemu/host-utils.h" -#include "exec/cpu-common.h" #include "exec/helper-proto-common.h" -#include "accel/tcg/cpu-loop.h" -#include "accel/tcg/getpc.h" #define HELPER_H "accel/tcg/tcg-runtime.h"#include "exec/helper-info.c.inc"
@@ -129,8 +126,3 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg) {return ctpop64 (arg); } - -void HELPER (exit_atomic )(CPUArchState *env) -{ -cpu_loop_exit_atomic (env_cpu (env),GETPC ()); -}
accel/tcg/tcg-runtime.h +0 -2
@@ -22,8 +22,6 @@ DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, cptr, env) -DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env) -#ifndef IN_HELPER_PROTO /* * Pass calls to memset directly to libc, without a thunk in qemu.
include/exec/helper-gen-common.h +4 -0
@@ -7,6 +7,10 @@#ifndef HELPER_GEN_COMMON_H #define HELPER_GEN_COMMON_H +#define HELPER_H "accel/tcg/cpu-exec-common.h" +#include "exec/helper-gen.h.inc" +#undef HELPER_H +#define HELPER_H "accel/tcg/tcg-runtime.h"#include "exec/helper-gen.h.inc" #undef HELPER_H
include/exec/helper-proto-common.h +4 -0
@@ -9,6 +9,10 @@#include "qemu/atomic128.h" /* for HAVE_CMPXCHG128 */ +#define HELPER_H "accel/tcg/cpu-exec-common.h" +#include "exec/helper-proto.h.inc" +#undef HELPER_H +#define HELPER_H "accel/tcg/tcg-runtime.h"#include "exec/helper-proto.h.inc" #undef HELPER_H
Signature · 1 line
2.52.0.windows.1
PATCH v3 2/27 accel/tcg: add cpu_raise_excp and cpu_raise_excp_restore helpers
In reply to Yonggang LuoAdd cpu_raise_excp without host state restoration and cpu_raise_excp_restore with explicit state restoration.
--- accel/tcg/cpu-exec-common.c | 13 +++++++++++++ include/accel/tcg/cpu-loop.h | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+)
accel/tcg/cpu-exec-common.c +13 -0
@@ -118,6 +118,19 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)cpu_loop_exit (cpu); } +void cpu_raise_excp (CPUState *cpu,int exception_index) +{ + cpu->exception_index = exception_index; +cpu_loop_exit (cpu); +} + +void cpu_raise_excp_restore (CPUState *cpu,int exception_index, +uintptr_t retaddr) +{ + cpu->exception_index = exception_index; +cpu_loop_exit_restore (cpu, retaddr); +} +void cpu_loop_exit_atomic (CPUState *cpu,uintptr_t pc) {/* Prevent looping if already executing in a serial context. */
include/accel/tcg/cpu-loop.h +22 -0
@@ -65,6 +65,28 @@ G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu); G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t host_pc); G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t host_pc); +/** +* cpu_raise_excp: +* @cpu: the cpu context +* @exception_index: EXCP_* or target trap number +* +* Raise @exception_index and exit the current TB without restoring guest +* state. +*/ +G_NORETURN void cpu_raise_excp(CPUState *cpu, int exception_index); + +/** +* cpu_raise_excp_restore: +* @cpu: the cpu context +* @exception_index: EXCP_* or target trap number +* @retaddr: the host pc within the translation +* +* Raise @exception_index and exit the current TB. Restore guest state from +* @retaddr when nonzero; otherwise, behave like cpu_raise_excp(). +*/ +G_NORETURN void cpu_raise_excp_restore(CPUState *cpu, int exception_index, +uintptr_t retaddr); +/** * cpu_loop_exit: * @cpu: the cpu context
Signature · 1 line
2.52.0.windows.1
PATCH v3 3/27 accel/tcg: add raise_excp and raise_excp_restore generator helpers
In reply to Yonggang Luo--- accel/tcg/cpu-exec-common.c | 12 ++++++++++++ accel/tcg/cpu-exec-common.h | 2 ++ 2 files changed, 14 insertions(+)
accel/tcg/cpu-exec-common.c +12 -0
@@ -131,6 +131,18 @@ void cpu_raise_excp_restore(CPUState *cpu, int exception_index,cpu_loop_exit_restore (cpu, retaddr); } +/* Raise exception and exit the TB without restoring guest state. */ +void HELPER (raise_excp )(CPUArchState *env,uint32_t exception) +{ +cpu_raise_excp (env_cpu (env), exception); +} + +/* Raise exception and exit the TB, restoring state from GETPC(). */ +void HELPER (raise_excp_restore )(CPUArchState *env,uint32_t exception) +{ +cpu_raise_excp_restore (env_cpu (env), exception,GETPC ()); +} +void cpu_loop_exit_atomic (CPUState *cpu,uintptr_t pc) {/* Prevent looping if already executing in a serial context. */
accel/tcg/cpu-exec-common.h +2 -0
@@ -1,2 +1,4 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env) +DEF_HELPER_FLAGS_2(raise_excp, TCG_CALL_NO_WG, noreturn, env, i32) +DEF_HELPER_FLAGS_2 (raise_excp_restore,TCG_CALL_NO_WG , noreturn, env, i32)
Signature · 1 line
2.52.0.windows.1
PATCH v3 4/27 target/rx: Unify BRK and INT trap handling
In reply to Yonggang LuoFrom: Philippe Mathieu-Daudé <[email protected]>
BRK is equivalent to INT #0, so route both instructions through the same trap helper.
--- target/rx/helper.h | 3 +-- target/rx/op_helper.c | 7 +------ target/rx/translate.c | 19 +++++++++---------- 3 files changed, 11 insertions(+), 18 deletions(-)
target/rx/helper.h +1 -2
@@ -2,8 +2,7 @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) DEF_HELPER_1(raise_access_fault, noreturn, env) DEF_HELPER_1(raise_privilege_violation, noreturn, env) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) +DEF_HELPER_2(trap, noreturn, env, i32) DEF_HELPER_3(fadd, f32, env, f32, f32) DEF_HELPER_3(fsub, f32, env, f32, f32)DEF_HELPER_3 (fmul, f32, env, f32, f32)
target/rx/op_helper.c +1 -6
@@ -455,12 +455,7 @@ G_NORETURN void helper_wait(CPURXState *env)raise_exception (env,EXCP_HLT ,0 ); } -G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) +G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) {raise_exception (env,0x100 + vec,0 ); } - -G_NORETURN void helper_rxbrk(CPURXState *env) -{ -raise_exception (env,0x100 ,0 ); -}
target/rx/translate.c +9 -10
@@ -2170,26 +2170,25 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)return true; } -/* brk */ -static bool trans_BRK (DisasContext *ctx,arg_BRK *a) +static bool do_trap (DisasContext *ctx,uint8_t vec) {tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxbrk (tcg_env); +gen_helper_trap (tcg_env,tcg_constant_i32 (vec)); ctx->base.is_jmp =DISAS_NORETURN ;return true; } +/* brk */ +static bool trans_BRK (DisasContext *ctx,arg_BRK *a) +{ +return do_trap (ctx,0 ); +} +/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -TCGv_i32 vec; -tcg_debug_assert (a->imm <0x100 ); - vec =tcg_constant_i32 (a->imm); -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxint (tcg_env, vec); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx, a->imm); }/* wait */
Signature · 1 line
2.52.0.windows.1
PATCH v3 5/27 target/rx: Define exception vector constants
In reply to Yonggang LuoName RX exception vectors and trap ranges, and use the definitions throughout exception handling and exception raising.
Assert that exception indexes remain within the defined range before accessing their vector tables.
--- target/rx/cpu.h | 13 +++++++++++++ target/rx/helper.c | 21 +++++++++++---------- target/rx/op_helper.c | 10 +++++----- target/rx/translate.c | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-)
target/rx/cpu.h +13 -0
@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +#define RX_EXCP_TRAP_COUNT 0x100 + +enum { +RX_EXCP_PRIVILEGE_VIOLATION =20 , +RX_EXCP_ACCESS =21 , +RX_EXCP_ILLEGAL_INSTRUCTION =23 , +RX_EXCP_FPU =25 , +RX_EXCP_NMI =30 , +RX_EXCP_TRAP_BASE =0x100 ,/* Up to RX_EXCP_TRAP_COUNT */ +}; + +#define RX_EXCP_COUNT (RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT) + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */
target/rx/helper.c +11 -10
@@ -86,13 +86,14 @@ void rx_cpu_do_interrupt(CPUState *cs) env->isp -=4 ;cpu_stl_le_data (env, env->isp, env->pc); -if (vec <0x100 ) { - env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); - }else { +assert (vec <RX_EXCP_COUNT ); +if (vec >=RX_EXCP_TRAP_BASE ) { env->pc =cpu_ldl_le_data (env, env->intb + (vec &0xff ) *4 ); + }else { + env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); } -if (vec ==30 ) { +if (vec ==RX_EXCP_NMI ) {/* Non-maskable interrupt */ qemu_plugin_vcpu_interrupt_cb (cs, last_pc); }else {
@@ -100,22 +101,22 @@ void rx_cpu_do_interrupt(CPUState *cs) }switch (vec) { -case 20 : +case RX_EXCP_PRIVILEGE_VIOLATION : expname ="privilege violation" ;break ; -case 21 : +case RX_EXCP_ACCESS : expname ="access exception" ;break ; -case 23 : +case RX_EXCP_ILLEGAL_INSTRUCTION : expname ="illegal instruction" ;break ; -case 25 : +case RX_EXCP_FPU : expname ="fpu exception" ;break ; -case 30 : +case RX_EXCP_NMI : expname ="non-maskable interrupt" ;break ; - case 0x100 ... 0x1ff: + case RX_EXCP_TRAP_BASE ... RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT - 1: expname ="unconditional trap" ; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n",
target/rx/op_helper.c +5 -5
@@ -115,7 +115,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable =FIELD_EX32 (env->fpsw,FPSW ,ENABLE ); enable |=1 <<5 ;/* CE always enabled */ if (cause & enable) { -raise_exception (env,21 , retaddr); +raise_exception (env,RX_EXCP_ACCESS , retaddr); } } }
@@ -432,17 +432,17 @@ void raise_exception(CPURXState *env, int index, G_NORETURN void helper_raise_privilege_violation(CPURXState *env) { -raise_exception (env,20 ,GETPC ()); +raise_exception (env,RX_EXCP_PRIVILEGE_VIOLATION ,GETPC ()); } G_NORETURN void helper_raise_access_fault(CPURXState *env) { -raise_exception (env,21 ,GETPC ()); +raise_exception (env,RX_EXCP_ACCESS ,GETPC ()); } G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) { -raise_exception (env,23 ,GETPC ()); +raise_exception (env,RX_EXCP_ILLEGAL_INSTRUCTION ,GETPC ()); } G_NORETURN void helper_wait(CPURXState *env)
@@ -457,5 +457,5 @@ G_NORETURN void helper_wait(CPURXState *env) G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) { -raise_exception (env,0x100 + vec,0 ); +raise_exception (env,RX_EXCP_TRAP_BASE + vec,0 ); }
target/rx/translate.c +1 -1
@@ -2187,7 +2187,7 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a)/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -tcg_debug_assert (a->imm <0x100 ); +tcg_debug_assert (a->imm <RX_EXCP_TRAP_COUNT );return do_trap (ctx, a->imm); }
Signature · 1 line
2.52.0.windows.1
PATCH v3 6/27 target/sh4: Define exception vector constants
In reply to Yonggang LuoName SH4 exception vectors and use the definitions throughout exception handling and exception raising.
--- target/sh4/cpu.h | 21 +++++++++++++++ target/sh4/helper.c | 60 +++++++++++++++++++++--------------------- target/sh4/op_helper.c | 16 +++++------ 3 files changed, 59 insertions(+), 38 deletions(-)
target/sh4/cpu.h +21 -0
@@ -135,6 +135,27 @@ typedef struct memory_content {struct memory_content *next; } memory_content; +/* Guest trap numbers. */ +enum { +SH4_EXCP_RESET =0x000 , +SH4_EXCP_MANUAL_RESET =0x020 , +SH4_EXCP_TLB_MISS =0x040 , +SH4_EXCP_DTLB_MISS_WRITE =0x060 , +SH4_EXCP_INITIAL_PAGE_WRITE =0x080 , +SH4_EXCP_TLB_VIOLATION =0x0a0 , +SH4_EXCP_DTLB_VIOLATION_WRITE =0x0c0 , +SH4_EXCP_ADDR_ERROR =0x0e0 , +SH4_EXCP_DATA_WRITE =0x100 , +SH4_EXCP_FPU =0x120 , +SH4_EXCP_TLB_MULTIPLE =0x140 , +SH4_EXCP_TRAPA =0x160 , +SH4_EXCP_ILLEGAL_INSTRUCTION =0x180 , +SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION =0x1a0 , +SH4_EXCP_USER_BREAK =0x1e0 , +SH4_EXCP_FPU_DISABLE =0x800 , +SH4_EXCP_SLOT_FPU_DISABLE =0x820 , +}; + typedef struct CPUArchState { uint32_t flags; /* general execution flags */ uint32_t gregs[24]; /* general registers */
target/sh4/helper.c +30 -30
138 lines not on this page · raw message
target/sh4/op_helper.c +8 -8
@@ -33,10 +33,10 @@ void superh_cpu_do_unaligned_access(CPUState *cs, vaddr addr,switch (access_type) {case MMU_INST_FETCH :case MMU_DATA_LOAD : - cs->exception_index =0x0e0 ; + cs->exception_index =SH4_EXCP_ADDR_ERROR ;break ;case MMU_DATA_STORE : - cs->exception_index =0x100 ; + cs->exception_index =SH4_EXCP_DATA_WRITE ;break ;default :g_assert_not_reached ();
@@ -67,22 +67,22 @@ void raise_exception(CPUSH4State *env, int index,void helper_raise_illegal_instruction (CPUSH4State *env) { -raise_exception (env,0x180 ,0 ); +raise_exception (env,SH4_EXCP_ILLEGAL_INSTRUCTION ,0 ); }void helper_raise_slot_illegal_instruction (CPUSH4State *env) { -raise_exception (env,0x1a0 ,0 ); +raise_exception (env,SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION ,0 ); }void helper_raise_fpu_disable (CPUSH4State *env) { -raise_exception (env,0x800 ,0 ); +raise_exception (env,SH4_EXCP_FPU_DISABLE ,0 ); }void helper_raise_slot_fpu_disable (CPUSH4State *env) { -raise_exception (env,0x820 ,0 ); +raise_exception (env,SH4_EXCP_SLOT_FPU_DISABLE ,0 ); }void helper_sleep (CPUSH4State *env)
@@ -97,7 +97,7 @@ void helper_sleep(CPUSH4State *env)void helper_trapa (CPUSH4State *env,uint32_t tra) { env->tra = tra <<2 ; -raise_exception (env,0x160 ,0 ); +raise_exception (env,SH4_EXCP_TRAPA ,0 ); }void helper_exclusive (CPUSH4State *env)
@@ -255,7 +255,7 @@ static void update_fpscr(CPUSH4State *env, uintptr_t retaddr) cause = (env->fpscr &FPSCR_CAUSE_MASK ) >>FPSCR_CAUSE_SHIFT ; enable = (env->fpscr &FPSCR_ENABLE_MASK ) >>FPSCR_ENABLE_SHIFT ;if (cause & enable) { -raise_exception (env,0x120 , retaddr); +raise_exception (env,SH4_EXCP_FPU , retaddr); } } }
Signature · 1 line
2.52.0.windows.1
Re: [PATCH v3 06/27] target/sh4: Define exception vector constants
Quoted 9 lines · Yonggang Luo
Name SH4 exception vectors and use the definitions throughout exception handling and exception raising.
Signed-off-by Yonggang Luo <[email protected]>--- target/sh4/cpu.h | 21 +++++++++++++++ target/sh4/helper.c | 60 +++++++++++++++++++++--------------------- target/sh4/op_helper.c | 16 +++++------ 3 files changed, 59 insertions(+), 38 deletions(-)
PATCH v3 7/27 target/hppa: remove helper_excp
In reply to Yonggang LuoUse the common raise_excp helper for translated exceptions and route the remaining C callers through cpu_raise_excp().
--- target/hppa/helper.h | 2 -- target/hppa/op_helper.c | 10 +--------- target/hppa/sys_helper.c | 5 +++-- target/hppa/translate.c | 2 +- 4 files changed, 5 insertions(+), 14 deletions(-)
target/hppa/helper.h +0 -2
@@ -1,5 +1,3 @@ -DEF_HELPER_2(excp, noreturn, env, int) - DEF_HELPER_FLAGS_3(stby_b, TCG_CALL_NO_WG, void, env, tl, tl) DEF_HELPER_FLAGS_3(stby_b_parallel, TCG_CALL_NO_WG, void, env, tl, tl)DEF_HELPER_FLAGS_3 (stby_e,TCG_CALL_NO_WG , void, env, tl, tl)
target/hppa/op_helper.c +1 -9
@@ -30,14 +30,6 @@#include "user/page-protection.h" #endif -G_NORETURN void HELPER(excp)(CPUHPPAState *env, int excp) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = excp; -cpu_loop_exit (cs); -} - G_NORETURN void hppa_dynamic_excp(CPUHPPAState *env, int excp, uintptr_t ra) {CPUState *cs =env_cpu (env);
@@ -341,7 +333,7 @@ target_ulong HELPER(probe)(CPUHPPAState *env, target_ulong addr,if (excp ==EXCP_DTLB_MISS ) { excp =EXCP_NA_DTLB_MISS ; } - helper_excp(env, excp); + cpu_raise_excp(env_cpu(env), excp); }return (want & prot) !=0 ;#endif
target/hppa/sys_helper.c +3 -2
@@ -21,6 +21,7 @@#include "qemu/log.h" #include "cpu.h" #include "exec/helper-proto.h" +#include "accel/tcg/cpu-loop.h" #include "qemu/timer.h" #include "system/runstate.h" #include "system/system.h"
@@ -51,13 +52,13 @@ void HELPER(write_interval_timer)(CPUHPPAState *env, target_ulong val)void HELPER (halt )(CPUHPPAState *env) {qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_SHUTDOWN ); -helper_excp (env,EXCP_HLT ); +cpu_raise_excp (env_cpu (env),EXCP_HLT ); }void HELPER (reset )(CPUHPPAState *env) {qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); -helper_excp (env,EXCP_HLT ); +cpu_raise_excp (env_cpu (env),EXCP_HLT ); }target_ulong HELPER (swap_system_mask )(CPUHPPAState *env,target_ulong nsm)
target/hppa/translate.c +1 -1
@@ -726,7 +726,7 @@ static void install_link(DisasContext *ctx, unsigned link, bool with_sr0)static void gen_excp_1 (int exception) { -gen_helper_excp (tcg_env,tcg_constant_i32 (exception)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (exception)); }static void gen_excp (DisasContext *ctx,int exception)
Signature · 1 line
2.52.0.windows.1
PATCH v3 8/27 target/hppa: remove hppa_dynamic_excp
In reply to Yonggang LuoUse cpu_raise_excp_restore() for FPU exceptions and remove the redundant HPPA wrapper.
--- target/hppa/cpu.h | 1 - target/hppa/fpu_helper.c | 3 ++- target/hppa/op_helper.c | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-)
target/hppa/cpu.h +0 -1
@@ -407,6 +407,5 @@ extern const MemoryRegionOps hppa_io_eir_ops;extern const VMStateDescription vmstate_hppa_cpu;void hppa_cpu_alarm_timer (void *);#endif -G_NORETURN void hppa_dynamic_excp(CPUHPPAState *env, int excp, uintptr_t ra);#endif /* HPPA_CPU_H */
target/hppa/fpu_helper.c +2 -1
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "exec/helper-proto.h" +#include "accel/tcg/cpu-loop.h" #include "fpu/softfloat.h" void HELPER (loaded_fr0 )(CPUHPPAState *env)
@@ -131,7 +132,7 @@ static void update_fr0_op(CPUHPPAState *env, uintptr_t ra) env->fr[0 ] = (uint64_t )shadow <<32 | fr1;if (hard_exp & shadow) { -hppa_dynamic_excp (env,EXCP_ASSIST , ra); +cpu_raise_excp_restore (env_cpu (env),EXCP_ASSIST , ra); } }
target/hppa/op_helper.c +0 -8
@@ -30,14 +30,6 @@#include "user/page-protection.h" #endif -G_NORETURN void hppa_dynamic_excp(CPUHPPAState *env, int excp, uintptr_t ra) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = excp; -cpu_loop_exit_restore (cs, ra); -} -static void atomic_store_mask32 (CPUHPPAState *env,target_ulong addr,uint32_t val,uint32_t mask,uintptr_t ra) {
Signature · 1 line
2.52.0.windows.1
PATCH v3 9/27 target/rx: convert raises to raise_excp
In reply to Yonggang LuoTranslate privilege and illegal instructions through the shared exception helpers, and use them for BRK, INT, FPSW, and WAIT paths where applicable. Remove the redundant RX exception helpers.
--- target/rx/helper.h | 4 ---- target/rx/op_helper.c | 39 ++------------------------------------- target/rx/translate.c | 9 ++++++--- 3 files changed, 8 insertions(+), 44 deletions(-)
target/rx/helper.h +0 -4
@@ -1,8 +1,4 @@ -DEF_HELPER_1(raise_illegal_instruction, noreturn, env) -DEF_HELPER_1(raise_access_fault, noreturn, env) -DEF_HELPER_1(raise_privilege_violation, noreturn, env) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(trap, noreturn, env, i32) DEF_HELPER_3(fadd, f32, env, f32, f32) DEF_HELPER_3(fsub, f32, env, f32, f32)DEF_HELPER_3 (fmul, f32, env, f32, f32)
target/rx/op_helper.c +2 -37
@@ -25,10 +25,6 @@#include "fpu/softfloat.h" #include "tcg/debug-assert.h" -static inline G_NORETURN -void raise_exception(CPURXState *env, int index, -uintptr_t retaddr); -static void _set_psw (CPURXState *env,uint32_t psw,uint32_t rte) {uint32_t prev_u;
@@ -115,7 +111,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable =FIELD_EX32 (env->fpsw,FPSW ,ENABLE ); enable |=1 <<5 ;/* CE always enabled */ if (cause & enable) { -raise_exception (env,RX_EXCP_ACCESS , retaddr); +cpu_raise_excp_restore (env_cpu (env),RX_EXCP_ACCESS , retaddr); } } }
@@ -419,32 +415,6 @@ uint32_t helper_divu(CPURXState *env, uint32_t num, uint32_t den)return ret; } -/* exception */ -static inline G_NORETURN -void raise_exception(CPURXState *env, int index, -uintptr_t retaddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = index; -cpu_loop_exit_restore (cs, retaddr); -} - -G_NORETURN void helper_raise_privilege_violation(CPURXState *env) -{ -raise_exception (env,RX_EXCP_PRIVILEGE_VIOLATION ,GETPC ()); -} - -G_NORETURN void helper_raise_access_fault(CPURXState *env) -{ -raise_exception (env,RX_EXCP_ACCESS ,GETPC ()); -} - -G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) -{ -raise_exception (env,RX_EXCP_ILLEGAL_INSTRUCTION ,GETPC ()); -} - G_NORETURN void helper_wait(CPURXState *env) {CPUState *cs =env_cpu (env);
@@ -452,10 +422,5 @@ G_NORETURN void helper_wait(CPURXState *env) cs->halted =1 ; env->in_sleep =1 ; env->psw_i =1 ; -raise_exception (env,EXCP_HLT ,0 ); -} - -G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) -{ -raise_exception (env,RX_EXCP_TRAP_BASE + vec,0 ); +cpu_raise_excp (env_cpu (env),EXCP_HLT ); }
target/rx/translate.c +6 -3
@@ -245,7 +245,8 @@ static int is_privileged(DisasContext *ctx, int is_exception) {if (FIELD_EX32 (ctx->tb_flags,PSW ,PM )) {if (is_exception) { -gen_helper_raise_privilege_violation (tcg_env); +gen_helper_raise_excp_restore ( + tcg_env,tcg_constant_i32 (RX_EXCP_PRIVILEGE_VIOLATION )); }return 0 ; }else {
@@ -2173,7 +2174,8 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)static bool do_trap (DisasContext *ctx,uint8_t vec) {tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_trap (tcg_env,tcg_constant_i32 (vec)); +gen_helper_raise_excp ( + tcg_env,tcg_constant_i32 (RX_EXCP_TRAP_BASE + vec)); ctx->base.is_jmp =DISAS_NORETURN ;return true; }
@@ -2227,7 +2229,8 @@ static void rx_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) ctx->pc = ctx->base.pc_next; insn =decode_load (ctx);if (!decode (ctx, insn)) { -gen_helper_raise_illegal_instruction (tcg_env); +gen_helper_raise_excp_restore ( + tcg_env,tcg_constant_i32 (RX_EXCP_ILLEGAL_INSTRUCTION )); } }
Signature · 1 line
2.52.0.windows.1
PATCH v3 10/27 target/sh4: log all exception vector names
In reply to Yonggang LuoAdd names for reset, manual reset, TLB multiple, and user break exceptions in the SH4 interrupt log.
--- target/sh4/helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target/sh4/helper.c +12 -0
@@ -97,12 +97,21 @@ void superh_cpu_do_interrupt(CPUState *cs)if (qemu_loglevel_mask (CPU_LOG_INT )) {const char *expname;switch (cs->exception_index) { +case SH4_EXCP_RESET : + expname ="reset" ; +break ; +case SH4_EXCP_MANUAL_RESET : + expname ="manual_reset" ; +break ;case SH4_EXCP_ADDR_ERROR : expname ="addr_error" ;break ;case SH4_EXCP_TLB_MISS : expname ="tlb_miss" ;break ; +case SH4_EXCP_TLB_MULTIPLE : + expname ="tlb_multiple" ; +break ;case SH4_EXCP_TLB_VIOLATION : expname ="tlb_violation" ;break ;
@@ -136,6 +145,9 @@ void superh_cpu_do_interrupt(CPUState *cs)case SH4_EXCP_TRAPA : expname ="trapa" ;break ; +case SH4_EXCP_USER_BREAK : + expname ="user_break" ; +break ;default : expname = do_irq ?"interrupt" :"???" ;break ;
Signature · 1 line
2.52.0.windows.1
PATCH v3 11/27 target/sh4: convert raises to raise_excp
In reply to Yonggang LuoTranslate illegal and FPU-disable exceptions through raise_excp and route the remaining C exception paths through cpu_raise_excp helpers. Remove the redundant SH4 exception helpers.
--- target/sh4/helper.h | 4 ---- target/sh4/op_helper.c | 36 +++--------------------------------- target/sh4/translate.c | 12 ++++++++---- 3 files changed, 11 insertions(+), 41 deletions(-)
target/sh4/helper.h +0 -4
@@ -1,8 +1,4 @@ DEF_HELPER_1(ldtlb, void, env) -DEF_HELPER_1(raise_illegal_instruction, noreturn, env) -DEF_HELPER_1(raise_slot_illegal_instruction, noreturn, env) -DEF_HELPER_1(raise_fpu_disable, noreturn, env) -DEF_HELPER_1(raise_slot_fpu_disable, noreturn, env) DEF_HELPER_1(sleep, noreturn, env) DEF_HELPER_2(trapa, noreturn, env, i32)DEF_HELPER_1 (exclusive, noreturn, env)
target/sh4/op_helper.c +3 -33
@@ -55,49 +55,19 @@ void helper_ldtlb(CPUSH4State *env)#endif } -static inline G_NORETURN -void raise_exception(CPUSH4State *env, int index, -uintptr_t retaddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = index; -cpu_loop_exit_restore (cs, retaddr); -} - -void helper_raise_illegal_instruction (CPUSH4State *env) -{ -raise_exception (env,SH4_EXCP_ILLEGAL_INSTRUCTION ,0 ); -} - -void helper_raise_slot_illegal_instruction (CPUSH4State *env) -{ -raise_exception (env,SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION ,0 ); -} - -void helper_raise_fpu_disable (CPUSH4State *env) -{ -raise_exception (env,SH4_EXCP_FPU_DISABLE ,0 ); -} - -void helper_raise_slot_fpu_disable (CPUSH4State *env) -{ -raise_exception (env,SH4_EXCP_SLOT_FPU_DISABLE ,0 ); -} -void helper_sleep (CPUSH4State *env) {CPUState *cs =env_cpu (env); cs->halted =1 ; env->in_sleep =1 ; -raise_exception (env,EXCP_HLT ,0 ); +cpu_raise_excp (cs,EXCP_HLT ); }void helper_trapa (CPUSH4State *env,uint32_t tra) { env->tra = tra <<2 ; -raise_exception (env,SH4_EXCP_TRAPA ,0 ); +cpu_raise_excp (env_cpu (env),SH4_EXCP_TRAPA ); }void helper_exclusive (CPUSH4State *env)
@@ -255,7 +225,7 @@ static void update_fpscr(CPUSH4State *env, uintptr_t retaddr) cause = (env->fpscr &FPSCR_CAUSE_MASK ) >>FPSCR_CAUSE_SHIFT ; enable = (env->fpscr &FPSCR_ENABLE_MASK ) >>FPSCR_ENABLE_SHIFT ;if (cause & enable) { -raise_exception (env,SH4_EXCP_FPU , retaddr); +cpu_raise_excp_restore (env_cpu (env),SH4_EXCP_FPU , retaddr); } } }
target/sh4/translate.c +8 -4
@@ -1756,10 +1756,13 @@ static void _decode_opc(DisasContext * ctx)if (ctx->envflags &TB_FLAG_DELAY_SLOT_MASK ) { do_illegal_slot:gen_save_cpu_state (ctx, true); -gen_helper_raise_slot_illegal_instruction (tcg_env); +gen_helper_raise_excp (tcg_env, +tcg_constant_i32 ( +SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION )); }else {gen_save_cpu_state (ctx, true); -gen_helper_raise_illegal_instruction (tcg_env); +gen_helper_raise_excp (tcg_env, +tcg_constant_i32 (SH4_EXCP_ILLEGAL_INSTRUCTION )); } ctx->base.is_jmp =DISAS_NORETURN ;return ;
@@ -1767,9 +1770,10 @@ static void _decode_opc(DisasContext * ctx) do_fpu_disabled:gen_save_cpu_state (ctx, true);if (ctx->envflags &TB_FLAG_DELAY_SLOT_MASK ) { -gen_helper_raise_slot_fpu_disable (tcg_env); +gen_helper_raise_excp (tcg_env, +tcg_constant_i32 (SH4_EXCP_SLOT_FPU_DISABLE )); }else { -gen_helper_raise_fpu_disable (tcg_env); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (SH4_EXCP_FPU_DISABLE )); } ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH v3 12/27 target/s390x: convert exception to raise_excp
In reply to Yonggang LuoDrop the redundant S390x exception helper and use the current cpu_raise_excp() API for SVC execution. Translate exceptions through the shared raise_excp helper.
--- target/s390x/helper.h | 1 - target/s390x/tcg/mem_helper.c | 2 +- target/s390x/tcg/misc_helper.c | 10 ---------- target/s390x/tcg/translate.c | 2 +- 4 files changed, 2 insertions(+), 13 deletions(-)
target/s390x/helper.h +0 -1
@@ -1,4 +1,3 @@ -DEF_HELPER_2(exception, noreturn, env, i32) DEF_HELPER_2(data_exception, noreturn, env, i32) DEF_HELPER_FLAGS_4(nc, TCG_CALL_NO_WG, i32, env, i32, i64, i64)DEF_HELPER_FLAGS_4 (oc,TCG_CALL_NO_WG , i32, env, i32, i64, i64)
target/s390x/tcg/mem_helper.c +1 -1
@@ -2488,7 +2488,7 @@ void HELPER(ex)(CPUS390XState *env, uint32_t ilen, uint64_t r1, uint64_t addr) }else if (opc ==0x0a ) { env->int_svc_code =extract64 (insn,48 ,8 ); env->int_svc_ilen = ilen; -helper_exception (env,EXCP_SVC ); +cpu_raise_excp (env_cpu (env),EXCP_SVC );g_assert_not_reached (); }
target/s390x/tcg/misc_helper.c +0 -10
@@ -56,16 +56,6 @@ #define HELPER_LOG(x...)#endif -/* Raise an exception statically from a TB. */ -void HELPER (exception )(CPUS390XState *env,uint32_t excp) -{ -CPUState *cs =env_cpu (env); - -HELPER_LOG ("%s: exception %d\n" , __func__, excp); - cs->exception_index = excp; -cpu_loop_exit (cs); -} -/* Store CPU Timer (also used for EXTRACT CPU TIME) */ uint64_t HELPER (stpt )(CPUS390XState *env) {
target/s390x/tcg/translate.c +1 -1
@@ -400,7 +400,7 @@ static int get_mem_index(DisasContext *s)static void gen_exception (int excp) { -gen_helper_exception (tcg_env,tcg_constant_i32 (excp)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (excp)); }static void gen_program_exception (DisasContext *s,int code)
Signature · 1 line
2.52.0.windows.1
PATCH v3 13/27 target/m68k: convert raises to raise_excp
In reply to Yonggang LuoTranslate pure exceptions through the shared raise_excp helper and use cpu_raise_excp() for no-restore C paths. Keep the format2 exception helper because it performs additional guest-state work.
--- target/m68k/helper.c | 12 ++---------- target/m68k/helper.h | 1 - target/m68k/op_helper.c | 19 ------------------- target/m68k/translate.c | 2 +- 4 files changed, 3 insertions(+), 31 deletions(-)
target/m68k/helper.c +2 -10
@@ -162,14 +162,6 @@ void HELPER(cf_movec_to)(CPUM68KState *env, uint32_t reg, uint32_t val) } } -static void raise_exception_ra (CPUM68KState *env,int tt,uintptr_t raddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = tt; -cpu_loop_exit_restore (cs, raddr); -} -void HELPER (m68k_movec_to )(CPUM68KState *env,uint32_t reg,uint32_t val) {switch (reg) {
@@ -291,7 +283,7 @@ void HELPER(m68k_movec_to)(CPUM68KState *env, uint32_t reg, uint32_t val) }/* Invalid control registers will generate an exception. */ -raise_exception_ra (env,EXCP_ILLEGAL ,0 ); +cpu_raise_excp (env_cpu (env),EXCP_ILLEGAL ); }uint32_t HELPER (m68k_movec_from )(CPUM68KState *env,uint32_t reg)
@@ -394,7 +386,7 @@ uint32_t HELPER(m68k_movec_from)(CPUM68KState *env, uint32_t reg) }/* Invalid control registers will generate an exception. */ -raise_exception_ra (env,EXCP_ILLEGAL ,0 ); +cpu_raise_excp (env_cpu (env),EXCP_ILLEGAL );return 0 ; }
target/m68k/helper.h +0 -1
@@ -111,7 +111,6 @@ DEF_HELPER_3(set_mac_extu, void, env, i32, i32) DEF_HELPER_2(flush_flags, void, env, i32) DEF_HELPER_2(set_ccr, void, env, i32) DEF_HELPER_FLAGS_1(get_ccr, TCG_CALL_NO_WG_SE, i32, env) -DEF_HELPER_2(raise_exception, noreturn, env, i32)DEF_HELPER_FLAGS_3 (bfffo_reg,TCG_CALL_NO_RWG_SE , i32, i32, i32, i32)
target/m68k/op_helper.c +0 -19
@@ -539,25 +539,6 @@ bool m68k_cpu_exec_interrupt(CPUState *cs, int interrupt_request)#endif /* !CONFIG_USER_ONLY */ -G_NORETURN static void -raise_exception_ra (CPUM68KState *env,int tt,uintptr_t raddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = tt; -cpu_loop_exit_restore (cs, raddr); -} - -G_NORETURN static void raise_exception(CPUM68KState *env, int tt) -{ -raise_exception_ra (env, tt,0 ); -} - -void HELPER (raise_exception )(CPUM68KState *env,uint32_t tt) -{ -raise_exception (env, tt); -} - G_NORETURN static voidraise_exception_format2 (CPUM68KState *env,int tt,int ilen,uintptr_t raddr) {
target/m68k/translate.c +1 -1
@@ -252,7 +252,7 @@ static void gen_jmp(DisasContext *s, TCGv dest)static void gen_raise_exception (int nr) { -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (nr)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (nr)); } static void gen_raise_exception_format2(DisasContext *s, int nr,
Signature · 1 line
2.52.0.windows.1
PATCH v3 14/27 target/or1k: convert exception to raise_excp
In reply to Yonggang LuoUse the shared raise_excp helper for translated exceptions. Use cpu_raise_excp_restore() for overflow helpers with GETPC() and cpu_raise_excp() for the zero-PC C wrapper.
--- target/or1k/exception.c | 31 ------------------------------- target/or1k/exception.h | 7 ++++++- target/or1k/exception_helper.c | 13 +------------ target/or1k/helper.h | 1 - target/or1k/meson.build | 1 - target/or1k/translate.c | 2 +- 6 files changed, 8 insertions(+), 47 deletions(-) delete mode 100644 target/or1k/exception.c
target/or1k/exception.c deleted +0 -31
@@ -1,31 +0,0 @@ -/* -* OpenRISC exception. -* -* Copyright (c) 2011-2012 Jia Liu <[email protected]> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include "qemu/osdep.h" -#include "accel/tcg/cpu-loop.h" -#include "cpu.h" -#include "exception.h" - -G_NORETURN void raise_exception(OpenRISCCPU *cpu, uint32_t excp) -{ -CPUState *cs =CPU (cpu); - - cs->exception_index = excp; -cpu_loop_exit (cs); -}
target/or1k/exception.h +6 -1
@@ -21,7 +21,12 @@#define TARGET_OPENRISC_EXCEPTION_H #include "cpu.h" +#include "accel/tcg/cpu-loop.h" -G_NORETURN void raise_exception(OpenRISCCPU *cpu, uint32_t excp); +static inline G_NORETURN +void raise_exception(OpenRISCCPU *cpu, uint32_t excp) +{ +cpu_raise_excp (CPU (cpu), excp); +}#endif /* TARGET_OPENRISC_EXCEPTION_H */
target/or1k/exception_helper.c +1 -12
@@ -21,22 +21,11 @@#include "cpu.h" #include "accel/tcg/cpu-loop.h" #include "exec/helper-proto.h" -#include "exception.h" - -void HELPER (exception )(CPUOpenRISCState *env,uint32_t excp) -{ -OpenRISCCPU *cpu =env_archcpu (env); - -raise_exception (cpu, excp); -}static G_NORETURN void do_range(CPUOpenRISCState *env, uintptr_t pc) { -CPUState *cs =env_cpu (env); - - cs->exception_index =EXCP_RANGE ; -cpu_loop_exit_restore (cs, pc); +cpu_raise_excp_restore (env_cpu (env),EXCP_RANGE , pc); }void HELPER (ove_cy )(CPUOpenRISCState *env)
target/or1k/helper.h +0 -1
@@ -18,7 +18,6 @@*/ /* exception */ -DEF_HELPER_FLAGS_2(exception, TCG_CALL_NO_WG, void, env, i32) DEF_HELPER_FLAGS_1(ove_cy, TCG_CALL_NO_WG, void, env) DEF_HELPER_FLAGS_1(ove_ov, TCG_CALL_NO_WG, void, env)DEF_HELPER_FLAGS_1 (ove_cyov,TCG_CALL_NO_WG , void, env)
target/or1k/meson.build +0 -1
@@ -5,7 +5,6 @@ or1k_ss.add(gen) or1k_ss.add(files( 'cpu.c', 'disas.c', - 'exception.c', 'exception_helper.c', 'fpu_helper.c', 'interrupt_helper.c',
target/or1k/translate.c +1 -1
@@ -140,7 +140,7 @@ void openrisc_translate_init(void)static void gen_exception (DisasContext *dc,unsigned int excp) { -gen_helper_exception (tcg_env,tcg_constant_i32 (excp)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (excp)); }static void gen_illegal_exception (DisasContext *dc)
Signature · 1 line
2.52.0.windows.1
PATCH v3 15/27 target/microblaze: convert raise_exception to raise_excp
In reply to Yonggang LuoUse the shared raise_excp helper for translated exceptions. Use cpu_raise_excp_restore() for GETPC() paths and preserve explicit cpu_loop_exit_restore() for MMU callbacks with possibly-zero retaddr.
--- target/microblaze/helper.h | 2 -- target/microblaze/op_helper.c | 19 +++---------------- target/microblaze/translate.c | 2 +- 3 files changed, 4 insertions(+), 19 deletions(-)
target/microblaze/helper.h +0 -2
@@ -1,5 +1,3 @@ -DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32) - DEF_HELPER_FLAGS_3(divs, TCG_CALL_NO_WG, i32, env, i32, i32)DEF_HELPER_FLAGS_3 (divu,TCG_CALL_NO_WG , i32, env, i32, i32)
target/microblaze/op_helper.c +3 -16
@@ -62,25 +62,14 @@ uint32_t helper_get(uint32_t id, uint32_t ctrl)return 0xdead0000 | id; } -void helper_raise_exception (CPUMBState *env,uint32_t index) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = index; -cpu_loop_exit (cs); -} -/* Raises ESR_EC_DIVZERO if exceptions are enabled. */ static void raise_divzero (CPUMBState *env,uint32_t esr,uintptr_t unwind_pc) { env->msr |=MSR_DZ ;if ((env->msr &MSR_EE ) &&env_archcpu (env)->cfg.div_zero_exception) { -CPUState *cs =env_cpu (env); - env->esr = esr; - cs->exception_index =EXCP_HW_EXCP ; -cpu_loop_exit_restore (cs, unwind_pc); +cpu_raise_excp_restore (env_cpu (env),EXCP_HW_EXCP , unwind_pc); } }
@@ -123,8 +112,7 @@ static void raise_fpu_exception(CPUMBState *env, uintptr_t ra)CPUState *cs =env_cpu (env); env->esr =ESR_EC_FPU ; - cs->exception_index =EXCP_HW_EXCP ; -cpu_loop_exit_restore (cs, ra); +cpu_raise_excp_restore (cs,EXCP_HW_EXCP , ra); }static void update_fpu_flags (CPUMBState *env,int flags,uintptr_t ra)
@@ -390,8 +378,7 @@ void helper_stackprot(CPUMBState *env, uint32_t addr) env->ear = addr; env->esr =ESR_EC_STACKPROT ; - cs->exception_index =EXCP_HW_EXCP ; -cpu_loop_exit_restore (cs,GETPC ()); +cpu_raise_excp_restore (cs,EXCP_HW_EXCP ,GETPC ()); } }
target/microblaze/translate.c +1 -1
@@ -100,7 +100,7 @@ static void t_sync_flags(DisasContext *dc)static void gen_raise_exception (DisasContext *dc,uint32_t index) { -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (index)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (index)); dc->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH v3 16/27 target/sparc: convert raise_exception to raise_excp
In reply to Yonggang LuoUse the shared raise_excp helper for translated exceptions and adapt SPARC C exits to cpu_raise_excp() or cpu_raise_excp_restore() according to the return-address contract. Keep cpu_raise_exception_ra().
--- target/sparc/helper.c | 21 +++------------------ target/sparc/helper.h | 2 -- target/sparc/translate.c | 6 +++--- 3 files changed, 6 insertions(+), 23 deletions(-)
target/sparc/helper.c +3 -18
@@ -27,26 +27,12 @@void cpu_raise_exception_ra (CPUSPARCState *env,int tt,uintptr_t ra) { -CPUState *cs =env_cpu (env); - - cs->exception_index = tt; -cpu_loop_exit_restore (cs, ra); -} - -void helper_raise_exception (CPUSPARCState *env,int tt) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = tt; -cpu_loop_exit (cs); +cpu_raise_excp_restore (env_cpu (env), tt, ra); }void helper_debug (CPUSPARCState *env) { -CPUState *cs =env_cpu (env); - - cs->exception_index =EXCP_DEBUG ; -cpu_loop_exit (cs); +cpu_raise_excp (env_cpu (env),EXCP_DEBUG ); }#ifdef TARGET_SPARC64
@@ -208,10 +194,9 @@ void helper_power_down(CPUSPARCState *env)CPUState *cs =env_cpu (env); cs->halted =1 ; - cs->exception_index =EXCP_HLT ; env->pc = env->npc; env->npc = env->pc +4 ; -cpu_loop_exit (cs); +cpu_raise_excp (cs,EXCP_HLT ); }target_ulong helper_rdasr17 (CPUSPARCState *env)
target/sparc/helper.h +0 -2
@@ -53,8 +53,6 @@ DEF_HELPER_FLAGS_3(fcmpq, TCG_CALL_NO_WG, i32, env, i128, i128) DEF_HELPER_FLAGS_3(fcmpeq, TCG_CALL_NO_WG, i32, env, i128, i128) DEF_HELPER_FLAGS_3(flcmps, TCG_CALL_NO_RWG_SE, i32, env, f32, f32) DEF_HELPER_FLAGS_3(flcmpd, TCG_CALL_NO_RWG_SE, i32, env, f64, f64) -DEF_HELPER_2(raise_exception, noreturn, env, int) - DEF_HELPER_FLAGS_3(faddd, TCG_CALL_NO_WG, f64, env, f64, f64) DEF_HELPER_FLAGS_3(fsubd, TCG_CALL_NO_WG, f64, env, f64, f64)DEF_HELPER_FLAGS_3 (fmuld,TCG_CALL_NO_WG , f64, env, f64, f64)
target/sparc/translate.c +3 -3
@@ -1048,7 +1048,7 @@ static void gen_exception(DisasContext *dc, int which) {finishing_insn (dc);save_state (dc); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (which)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (which)); dc->base.is_jmp =DISAS_NORETURN ; }
@@ -2811,7 +2811,7 @@ static bool do_tcc(DisasContext *dc, int cond, int cc,/* Trap always. */ if (cond ==8 ) {save_state (dc); -gen_helper_raise_exception (tcg_env, trap); +gen_helper_raise_excp (tcg_env, trap); dc->base.is_jmp =DISAS_NORETURN ;return true; }
@@ -5833,7 +5833,7 @@ static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)if (e->npc %4 ==0 ) {tcg_gen_movi_tl (cpu_npc, e->npc); } -gen_helper_raise_exception (tcg_env, e->excp); +gen_helper_raise_excp (tcg_env, e->excp); e_next = e->next;g_free (e);
Signature · 1 line
2.52.0.windows.1
PATCH v3 17/27 target/loongarch: convert raise_exception to raise_excp
In reply to Yonggang LuoInline do_raise_exception as it's used by other arch.
Use the shared raise_excp_restore helper for translated exceptions and adapt the logging C exception path to cpu_raise_excp() or cpu_raise_excp_restore() according to the return-address contract.
--- target/loongarch/internals.h | 12 +++++++++--- target/loongarch/tcg/helper.h | 2 -- target/loongarch/tcg/op_helper.c | 6 ------ target/loongarch/tcg/tcg_cpu.c | 10 ++++------ target/loongarch/tcg/translate.c | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-)
target/loongarch/internals.h +9 -3
@@ -19,9 +19,15 @@ void loongarch_translate_init(void);void loongarch_translate_code (CPUState *cs,TranslationBlock *tb,int *max_insns,vaddr pc,void *host_pc); -void G_NORETURN do_raise_exception(CPULoongArchState *env, -uint32_t exception, -uintptr_t pc); +void G_NORETURN loongarch_do_raise_exception(CPULoongArchState *env, +uint32_t exception, +uintptr_t pc); +static inline void G_NORETURN do_raise_exception(CPULoongArchState *env, +uint32_t exception, +uintptr_t pc) +{ +loongarch_do_raise_exception (env, exception, pc); +}#ifdef CONFIG_TCG int ieee_ex_to_loongarch (int xcpt);
target/loongarch/tcg/helper.h +0 -2
@@ -3,8 +3,6 @@* Copyright (c) 2021 Loongson Technology Corporation Limited */ -DEF_HELPER_2(raise_exception, noreturn, env, i32) - DEF_HELPER_FLAGS_3(asrtle_d, TCG_CALL_NO_WG, void, env, tl, tl)DEF_HELPER_FLAGS_3 (asrtgt_d,TCG_CALL_NO_WG , void, env, tl, tl)
target/loongarch/tcg/op_helper.c +0 -6
@@ -16,12 +16,6 @@#include <zlib.h> /* for crc32 */ #include "cpu-csr.h" -/* Exceptions helpers */ -void helper_raise_exception (CPULoongArchState *env,uint32_t exception) -{ -do_raise_exception (env, exception,GETPC ()); -} -/* loongarch assert op */ void helper_asrtle_d (CPULoongArchState *env,target_ulong rj,target_ulong rk) {
target/loongarch/tcg/tcg_cpu.c +4 -6
@@ -59,9 +59,9 @@ static const char *loongarch_exception_name(int32_t exception)return "Unknown" ; } -void G_NORETURN do_raise_exception(CPULoongArchState *env, -uint32_t exception, -uintptr_t pc) +void G_NORETURN loongarch_do_raise_exception(CPULoongArchState *env, +uint32_t exception, +uintptr_t pc) {CPUState *cs =env_cpu (env);
@@ -69,9 +69,7 @@ void G_NORETURN do_raise_exception(CPULoongArchState *env, __func__, exception, loongarch_exception_name(exception)); - cs->exception_index = exception; - -cpu_loop_exit_restore (cs, pc); +cpu_raise_excp_restore (cs, exception, pc); }#ifndef CONFIG_USER_ONLY
target/loongarch/tcg/translate.c +1 -1
@@ -95,7 +95,7 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)void generate_exception (DisasContext *ctx,int excp) {tcg_gen_movi_tl (cpu_pc, ctx->base.pc_next); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (excp)); +gen_helper_raise_excp_restore (tcg_env,tcg_constant_i32 (excp)); ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH v3 18/27 target/hexagon: reuse cpu_raise_excp_restore
In reply to Yonggang LuoInline do_raise_exception as it's used by other arch.
--- target/hexagon/internal.h | 10 +++++++++- target/hexagon/op_helper.c | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-)
target/hexagon/internal.h +9 -1
@@ -36,11 +36,19 @@ extern const char * const hexagon_sregnames[];extern const char *const hexagon_gregnames[];#endif -void G_NORETURN do_raise_exception(CPUHexagonState *env, +void G_NORETURN hexagon_do_raise_exception(CPUHexagonState *env,uint32_t exception,uint32_t PC ,uintptr_t retaddr); +static inline void G_NORETURN do_raise_exception(CPUHexagonState *env, +uint32_t exception, +uint32_t PC , +uintptr_t retaddr) +{ +hexagon_do_raise_exception (env, exception,PC , retaddr); +} +#define hexagon_cpu_mmu_enabled (env) ({ \ HexagonCPU *cpu = env_archcpu(env); \ cpu->globalregs ? \
target/hexagon/op_helper.c +2 -3
@@ -73,7 +73,7 @@ uint64_t HELPER(utimer)(void)/* Exceptions processing helpers */ G_NORETURN -void do_raise_exception(CPUHexagonState *env, uint32_t exception, +void hexagon_do_raise_exception(CPUHexagonState *env, uint32_t exception,uint32_t PC ,uintptr_t retaddr) {CPUState *cs =env_cpu (env);
@@ -82,8 +82,7 @@ void do_raise_exception(CPUHexagonState *env, uint32_t exception,ASSERT_DIRECT_TO_GUEST_UNSET (env, exception); env->gpr[HEX_REG_PC ] =PC ; - cs->exception_index = exception; -cpu_loop_exit_restore (cs, retaddr); +cpu_raise_excp_restore (cs, exception, retaddr); } G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
Signature · 1 line
2.52.0.windows.1
PATCH v3 19/27 target/xtensa: reset yield state in the icount path
In reply to Yonggang LuoEmit the yield_needed reset from gen_yield() before calling gen_helper_exception() for EXCP_YIELD. This keeps the state change at the Xtensa icount-yield call site instead of adding EXCP_YIELD-specific behavior to the generic exception helper.
--- target/xtensa/cpu.h | 2 +- target/xtensa/exc_helper.c | 3 --- target/xtensa/translate.c | 8 +++++--- 3 files changed, 6 insertions(+), 7 deletions(-)
target/xtensa/cpu.h +1 -1
@@ -541,7 +541,7 @@ struct CPUArchState {uint32_t ccount_base;#endif -int yield_needed; +int32_t yield_needed;unsigned static_vectors;/* Watchpoints for DBREAK registers */
target/xtensa/exc_helper.c +0 -3
@@ -40,9 +40,6 @@ void HELPER(exception)(CPUXtensaState *env, uint32_t excp)CPUState *cs =env_cpu (env); cs->exception_index = excp; -if (excp ==EXCP_YIELD ) { - env->yield_needed =0 ; - }cpu_loop_exit (cs); }
target/xtensa/translate.c +5 -3
@@ -303,9 +303,11 @@ static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa) dc->sar_m32_5bit = true; } -static void gen_exception (DisasContext *dc,int excp) +static void gen_yield (DisasContext *dc) { -gen_helper_exception (tcg_env,tcg_constant_i32 (excp)); +tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, + offsetof(CPUXtensaState , yield_needed)); +gen_helper_exception (tcg_env,tcg_constant_i32 (EXCP_YIELD )); }static void gen_exception_cause (DisasContext *dc,uint32_t cause)
@@ -1167,7 +1169,7 @@ static void xtensa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)but this is the first TranslateOps hook that allows exiting. */ if ((tb_cflags (dc->base.tb) &CF_USE_ICOUNT ) && (dc->base.tb->flags &XTENSA_TBFLAG_YIELD )) { -gen_exception (dc,EXCP_YIELD ); +gen_yield (dc); dc->base.pc_next = dc->pc +1 ; dc->base.is_jmp =DISAS_NORETURN ;return ;
Signature · 1 line
2.52.0.windows.1
PATCH v3 20/27 target/xtensa: convert exception to raise_excp
In reply to Yonggang LuoReplace the forwarding wrapper with direct cpu_raise_excp() calls in Xtensa C helpers. Use gen_helper_raise_excp() for translated EXCP_YIELD, while preserving exception_cause helpers for architectural state updates.
--- target/xtensa/exc_helper.c | 14 +++----------- target/xtensa/helper.h | 1 - target/xtensa/translate.c | 2 +- target/xtensa/win_helper.c | 13 +++++++------ 4 files changed, 11 insertions(+), 19 deletions(-)
target/xtensa/exc_helper.c +3 -11
@@ -35,14 +35,6 @@#include "qemu/atomic.h" #include "qemu/plugin.h" -void HELPER (exception )(CPUXtensaState *env,uint32_t excp) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = excp; -cpu_loop_exit (cs); -} -void HELPER (exception_cause )(CPUXtensaState *env,uint32_t pc,uint32_t cause) {uint32_t vector;
@@ -63,7 +55,7 @@ void HELPER(exception_cause)(CPUXtensaState *env, uint32_t pc, uint32_t cause) env->sregs[EXCCAUSE ] = cause; env->sregs[PS ] |=PS_EXCM ; -HELPER (exception)(env, vector); +cpu_raise_excp (env_cpu (env), vector); } void HELPER(exception_cause_vaddr)(CPUXtensaState *env,
@@ -90,7 +82,7 @@ void HELPER(debug_exception)(CPUXtensaState *env, uint32_t pc, uint32_t cause) env->sregs[EPS2 + level -2 ] = env->sregs[PS ]; env->sregs[PS ] = (env->sregs[PS ] & ~PS_INTLEVEL ) |PS_EXCM | (level <<PS_INTLEVEL_SHIFT ); -HELPER (exception)(env,EXC_DEBUG ); +cpu_raise_excp (env_cpu (env),EXC_DEBUG ); }#ifndef CONFIG_USER_ONLY
@@ -113,7 +105,7 @@ void HELPER(waiti)(CPUXtensaState *env, uint32_t pc, uint32_t intlevel) } cpu->halted =1 ; -HELPER (exception)(env,EXCP_HLT ); +cpu_raise_excp (env_cpu (env),EXCP_HLT ); }void HELPER (check_interrupts )(CPUXtensaState *env)
target/xtensa/helper.h +0 -1
@@ -1,4 +1,3 @@ -DEF_HELPER_2(exception, noreturn, env, i32) DEF_HELPER_3(exception_cause, noreturn, env, i32, i32) DEF_HELPER_4(exception_cause_vaddr, noreturn, env, i32, i32, i32)DEF_HELPER_3 (debug_exception, noreturn, env, i32, i32)
target/xtensa/translate.c +1 -1
@@ -307,7 +307,7 @@ static void gen_yield(DisasContext *dc) {tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, offsetof(CPUXtensaState , yield_needed)); -gen_helper_exception (tcg_env,tcg_constant_i32 (EXCP_YIELD )); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (EXCP_YIELD )); }static void gen_exception_cause (DisasContext *dc,uint32_t cause)
target/xtensa/win_helper.c +7 -6
@@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "accel/tcg/cpu-loop.h" #include "cpu.h" #include "exec/helper-proto.h" #include "qemu/host-utils.h"
@@ -125,13 +126,13 @@ void HELPER(window_check)(CPUXtensaState *env, uint32_t pc, uint32_t w)switch (ctz32 (windowstart >> n)) {case 0 : -HELPER (exception)(env,EXC_WINDOW_OVERFLOW4 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_OVERFLOW4 );break ;case 1 : -HELPER (exception)(env,EXC_WINDOW_OVERFLOW8 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_OVERFLOW8 );break ;default : -HELPER (exception)(env,EXC_WINDOW_OVERFLOW12 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_OVERFLOW12 );break ; } }
@@ -174,11 +175,11 @@ void HELPER(test_underflow_retw)(CPUXtensaState *env, uint32_t pc) env->sregs[EPC1 ] = env->pc = pc;if (n ==1 ) { -HELPER (exception)(env,EXC_WINDOW_UNDERFLOW4 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_UNDERFLOW4 ); }else if (n ==2 ) { -HELPER (exception)(env,EXC_WINDOW_UNDERFLOW8 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_UNDERFLOW8 ); }else if (n ==3 ) { -HELPER (exception)(env,EXC_WINDOW_UNDERFLOW12 ); +cpu_raise_excp (env_cpu (env),EXC_WINDOW_UNDERFLOW12 ); } } }
Signature · 1 line
2.52.0.windows.1
PATCH v3 21/27 target/avr: convert debug/break/sleep to raise_excp
In reply to Yonggang LuoUse the shared raise_excp helper for AVR debug, break, and sleep exceptions while preserving target-specific unsupported handling.
--- target/avr/helper.c | 24 ------------------------ target/avr/helper.h | 3 --- target/avr/translate.c | 4 ++-- 3 files changed, 2 insertions(+), 29 deletions(-)
target/avr/helper.c +0 -24
@@ -152,14 +152,6 @@ bool avr_cpu_tlb_fill(CPUState *cs, vaddr address, int size,* helpers */ -void helper_sleep (CPUAVRState *env) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index =EXCP_HLT ; -cpu_loop_exit (cs); -} -void helper_unsupported (CPUAVRState *env) {CPUState *cs =env_cpu (env);
@@ -176,22 +168,6 @@ void helper_unsupported(CPUAVRState *env)cpu_loop_exit (cs); } -void helper_debug (CPUAVRState *env) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index =EXCP_DEBUG ; -cpu_loop_exit (cs); -} - -void helper_break (CPUAVRState *env) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index =EXCP_DEBUG ; -cpu_loop_exit (cs); -} -void helper_wdr (CPUAVRState *env) {qemu_log_mask (LOG_UNIMP ,"WDG reset (not implemented)\n" );
target/avr/helper.h +0 -3
@@ -19,8 +19,5 @@*/ DEF_HELPER_1(wdr, void, env) -DEF_HELPER_1(debug, noreturn, env) -DEF_HELPER_1(break, noreturn, env) -DEF_HELPER_1(sleep, noreturn, env) DEF_HELPER_1(unsupported, noreturn, env)DEF_HELPER_3 (fullwr, void, env, i32, i32)
target/avr/translate.c +2 -2
@@ -2554,7 +2554,7 @@ static bool trans_BREAK(DisasContext *ctx, arg_BREAK *a)#ifdef BREAKPOINT_ON_BREAK tcg_gen_movi_tl (cpu_pc, ctx->npc -1 ); -gen_helper_debug (tcg_env); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (EXCP_DEBUG )); ctx->base.is_jmp =DISAS_EXIT ;#else /* NOP */
@@ -2580,7 +2580,7 @@ static bool trans_NOP(DisasContext *ctx, arg_NOP *a)*/ static bool trans_SLEEP (DisasContext *ctx,arg_SLEEP *a) { -gen_helper_sleep (tcg_env); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (EXCP_HLT )); ctx->base.is_jmp =DISAS_NORETURN ;return true; }
Signature · 1 line
2.52.0.windows.1
PATCH v3 22/27 target/arm: convert exception_internal to raise_excp
In reply to Yonggang LuoUse the shared raise_excp helper for exception_internal and adapt zero-PC C exception exits to cpu_raise_excp(). Preserve ARM-specific exception helpers that carry additional state.
--- target/arm/tcg/helper-defs.h | 1 - target/arm/tcg/m_helper.c | 3 ++- target/arm/tcg/op_helper.c | 33 ++++++--------------------------- target/arm/tcg/translate.c | 2 +- 4 files changed, 9 insertions(+), 30 deletions(-)
target/arm/tcg/helper-defs.h +0 -1
@@ -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)
target/arm/tcg/m_helper.c +2 -1
@@ -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_raise_excp (env_cpu (env),EXCP_EXCEPTION_EXIT );/* notreached */ }
target/arm/tcg/op_helper.c +6 -27
@@ -64,10 +64,9 @@ 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_raise_excp (cs, excp); } void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
@@ -399,9 +398,8 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len) }qatomic_set (&env->halt_reason,HALT_WFI ); - cs->exception_index =EXCP_HLT ; cs->halted =1 ; -cpu_loop_exit (cs); +cpu_raise_excp (cs,EXCP_HLT );#endif }
@@ -462,9 +460,8 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd) timer_mod(cpu->wfxt_timer, nexttick); }qatomic_set (&env->halt_reason,HALT_WFI ); - cs->exception_index =EXCP_HLT ; cs->halted =1 ; -cpu_loop_exit (cs); +cpu_raise_excp (cs,EXCP_HLT );#endif }
@@ -631,9 +628,8 @@ void HELPER(wfe)(CPUARMState *env, uint32_t insn_len) }qatomic_set (&env->halt_reason,HALT_WFE ); - cs->exception_index =EXCP_HLT ; cs->halted =1 ; -cpu_loop_exit (cs); +cpu_raise_excp (cs,EXCP_HLT );#endif }
@@ -726,9 +722,8 @@ void HELPER(wfet)(CPUARMState *env, uint32_t rd) }qatomic_set (&env->halt_reason,HALT_WFE ); - cs->exception_index =EXCP_HLT ; cs->halted =1 ; -cpu_loop_exit (cs); +cpu_raise_excp (cs,EXCP_HLT );#endif }
@@ -740,23 +735,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_raise_excp (cs,EXCP_YIELD ); }/* Raise an exception with the specified syndrome register value */
target/arm/tcg/translate.c +1 -1
@@ -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)); }static void gen_singlestep_exception (DisasContext *s)
Signature · 1 line
2.52.0.windows.1
PATCH v3 23/27 target/riscv: use cpu_raise_excp_restore for exception exits
In reply to Yonggang LuoKeep riscv_raise_exception() for PMU bookkeeping, but delegate exception handling to cpu_raise_excp_restore(). It restores guest state when pc is nonzero and falls back to a plain exception exit otherwise.
--- target/riscv/tcg/op_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/tcg/op_helper.c +1 -2
@@ -47,8 +47,7 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env,riscv_cpu_get_trap_name (exception, false), env->pc); - cs->exception_index = exception; -cpu_loop_exit_restore (cs, pc); +cpu_raise_excp_restore (cs, exception, pc); }void helper_raise_exception (CPURISCVState *env,uint32_t exception)
Signature · 1 line
2.52.0.windows.1
PATCH v3 24/27 target/mips: call do_raise_exception directly
In reply to Yonggang LuoUse do_raise_exception() directly for reserved-instruction traps in the FPU helpers, passing GETPC() to restore guest state. Keep helper_wait() on the zero-PC path, where the guest PC was already updated.
--- target/mips/tcg/exception.c | 7 +------ target/mips/tcg/fpu_helper.c | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-)
target/mips/tcg/exception.c +1 -6
@@ -60,11 +60,6 @@ void helper_raise_exception_debug(CPUMIPSState *env)do_raise_exception (env,EXCP_DEBUG ,0 ); } -static void raise_exception (CPUMIPSState *env,uint32_t exception) -{ -do_raise_exception (env, exception,0 ); -} -void helper_wait (CPUMIPSState *env) {CPUState *cs =env_cpu (env);
@@ -75,7 +70,7 @@ void helper_wait(CPUMIPSState *env)* Last instruction in the block, PC was updated before * - no need to recover PC and icount. */ -raise_exception (env,EXCP_HLT ); +do_raise_exception (env,EXCP_HLT ,0 ); }void mips_cpu_synchronize_from_tb (CPUState *cs,const TranslationBlock *tb)
target/mips/tcg/fpu_helper.c +3 -3
@@ -61,7 +61,7 @@ target_ulong helper_cfc1(CPUMIPSState *env, uint32_t reg)if (env->CP0_Config5 & (1 <<CP0C5_UFE )) { arg1 = (env->CP0_Config5 >>CP0C5_FRE ) &1 ; }else { -helper_raise_exception (env,EXCP_RI ); +do_raise_exception (env,EXCP_RI ,GETPC ()); } }break ;
@@ -120,7 +120,7 @@ void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt) env->CP0_Config5 &= ~(1 <<CP0C5_FRE );compute_hflags (env); }else { -helper_raise_exception (env,EXCP_RI ); +do_raise_exception (env,EXCP_RI ,GETPC ()); }break ;case 6 :
@@ -132,7 +132,7 @@ void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt) env->CP0_Config5 |= (1 <<CP0C5_FRE );compute_hflags (env); }else { -helper_raise_exception (env,EXCP_RI ); +do_raise_exception (env,EXCP_RI ,GETPC ()); }break ;case 25 :
Signature · 1 line
2.52.0.windows.1
PATCH v3 25/27 target/mips: use shared TCG exception helpers
In reply to Yonggang LuoGenerate 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.
--- 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(-)
target/mips/cpu.h +1 -1
@@ -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 */
target/mips/helper.h +0 -4
@@ -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)
target/mips/tcg/exception.c +1 -19
@@ -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); }
target/mips/tcg/translate.c +6 -3
@@ -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)
Signature · 1 line
2.52.0.windows.1
PATCH v3 26/27 target/ppc: reuse the error-aware NIP exception path
In reply to Yonggang LuoRoute gen_exception_nip() through gen_exception_err_nip() with a zero error code, reusing its NIP update and exception-generation path.
--- target/ppc/translate.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
target/ppc/translate.c +1 -6
@@ -330,12 +330,7 @@ static inline void gen_exception_err(DisasContext *ctx, uint32_t excp,static void gen_exception_nip (DisasContext *ctx,uint32_t excp,target_ulong nip) { -TCGv_i32 t0; - -gen_update_nip (ctx, nip); - t0 =tcg_constant_i32 (excp); -gen_helper_raise_exception (tcg_env, t0); - ctx->base.is_jmp =DISAS_NORETURN ; +gen_exception_err_nip (ctx, excp,0 , nip); }static inline void gen_exception (DisasContext *ctx,uint32_t excp)
Signature · 1 line
2.52.0.windows.1
PATCH v3 27/27 target/ppc: use shared helpers for translated exceptions
In reply to Yonggang LuoStore error_code before gen_helper_raise_excp() and define raise_exception_err_ra() inline in internal.h to preserve PPC error-code handling while using cpu_raise_excp_restore(). Remove the obsolete TCG exception helpers.
--- target/ppc/cpu.h | 5 +---- target/ppc/helper.h | 2 -- target/ppc/internal.h | 9 +++++++++ target/ppc/misc_helper.c | 1 + target/ppc/tcg-excp_helper.c | 21 --------------------- target/ppc/timebase_helper.c | 1 + target/ppc/translate.c | 13 ++++++------- 7 files changed, 18 insertions(+), 34 deletions(-)
target/ppc/cpu.h +1 -4
@@ -1392,7 +1392,7 @@ struct CPUArchState {uint64_t insns_flags;uint64_t insns_flags2; -int error_code; +int32_t error_code;uint32_t pending_interrupts;#if !defined(CONFIG_USER_ONLY )uint64_t excp_stats[POWERPC_EXCP_NB ];
@@ -2819,9 +2819,6 @@ void cpu_write_xer(CPUPPCState *env, target_ulong xer);*/ #define is_book3s_arch2x (ctx) (!!((ctx)->insns_flags & PPC_SEGMENT_64B)) -G_NORETURN void raise_exception_err_ra(CPUPPCState *env, uint32_t exception, -uint32_t error_code,uintptr_t raddr); -/* PERFM EBB helper*/ #if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )void raise_ebb_perfm_exception (CPUPPCState *env);
target/ppc/helper.h +0 -2
@@ -1,5 +1,3 @@ -DEF_HELPER_FLAGS_3(raise_exception_err, TCG_CALL_NO_WG, noreturn, env, i32, i32) -DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32) DEF_HELPER_FLAGS_4(TW, TCG_CALL_NO_WG, void, env, tl, tl, i32)#if defined(TARGET_PPC64 )DEF_HELPER_FLAGS_4 (TD ,TCG_CALL_NO_WG , void, env, tl, tl, i32)
target/ppc/internal.h +9 -0
@@ -320,8 +320,17 @@ static inline int ger_pack_masks(int pmsk, int ymsk, int xmsk)#ifdef CONFIG_TCG #include "accel/tcg/tb-cpu-state.h" +#include "accel/tcg/cpu-loop.h" TCGTBCPUState ppc_get_tb_cpu_state (CPUState *cs); + +static inline G_NORETURN +void raise_exception_err_ra(CPUPPCState *env, uint32_t excp, +uint32_t err,uintptr_t ra) +{ + env->error_code = err; +cpu_raise_excp_restore (env_cpu (env), excp, ra); +}#endif #endif /* PPC_INTERNAL_H */
target/ppc/misc_helper.c +1 -0
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "cpu.h" +#include "internal.h" #include "exec/cputlb.h" #include "exec/helper-proto.h" #include "qemu/error-report.h"
target/ppc/tcg-excp_helper.c +0 -21
@@ -34,27 +34,6 @@/*****************************************************************************/ /* Exceptions processing helpers */ -void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, -uint32_t error_code,uintptr_t raddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = exception; - env->error_code = error_code; -cpu_loop_exit_restore (cs, raddr); -} - -void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, -uint32_t error_code) -{ -raise_exception_err_ra (env, exception, error_code,0 ); -} - -void helper_raise_exception (CPUPPCState *env,uint32_t exception) -{ -raise_exception_err_ra (env, exception,0 ,0 ); -} -#ifndef CONFIG_USER_ONLY static G_NORETURN void raise_exception_err(CPUPPCState *env, uint32_t exception,
target/ppc/timebase_helper.c +1 -0
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" +#include "internal.h" #include "hw/ppc/ppc.h" #include "exec/helper-proto.h" #include "qemu/log.h"
target/ppc/translate.c +6 -7
@@ -308,12 +308,10 @@ static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)static void gen_exception_err_nip (DisasContext *ctx,uint32_t excp,uint32_t error,target_ulong nip) { -TCGv_i32 t0, t1; -gen_update_nip (ctx, nip); - t0 =tcg_constant_i32 (excp); - t1 =tcg_constant_i32 (error); -gen_helper_raise_exception_err (tcg_env, t0, t1); +tcg_gen_st_i32 (tcg_constant_i32 (error), tcg_env, + offsetof(CPUPPCState , error_code)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (excp)); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -372,8 +370,9 @@ static void gen_debug_exception(DisasContext *ctx, bool rfi_type)gen_load_spr (t0,SPR_BOOKE_DBSR );tcg_gen_ori_tl (t0, t0, dbsr);gen_store_spr (SPR_BOOKE_DBSR , t0); -gen_helper_raise_exception (tcg_env, -tcg_constant_i32 (POWERPC_EXCP_DEBUG )); +tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, + offsetof(CPUPPCState , error_code)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (POWERPC_EXCP_DEBUG )); ctx->base.is_jmp =DISAS_NORETURN ; }else {if (!rfi_type) {/* BookS does not single step rfi type instructions */
Signature · 1 line
2.52.0.windows.1