accel/tcg: share raise_excp across TCG targets
Subsystems (2)
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 a shared C exit and a shared TCG helper, then converts one target per commit. Joiners call gen_helper_raise_excp and drop the copied DEF. Leftover TCG helpers that still do extra work take an arch prefix. C wrappers keep the short name as static inline where that is enough. The shared helper only touches CPUState. Translate may store arch state (error_code, PC) first. Guest trap numbers stay below 0x10000. TCG loop codes such as EXCP_INTERRUPT start at 0x10000.
- Add cpu_loop_exit_excp next to cpu_loop_exit_restore. Set cpu->exception_index then restore and exit. host_pc == 0 skips restore.
- Move helper_info_* extern into each gen_helper_* body so a comment on DEF_HELPER attaches to gen_helper_*, not helper_info_*.
- Add TCG raise_excp (env, exception, restore). restore 1 exits with GETPC(); restore 0 skips unwind.
- Convert RX and SH4: name guest traps RX_EXCP_* / SH4_EXCP_*. Join privilege, illegal, BRK, and INT on RX, and illegal / FPU-disable on SH4. Prefix leftover rx_wait. Keep SH4 sleep, trapa, and exclusive.
- Convert the remaining joiners one arch per commit: m68k, or1k, microblaze, sparc, loongarch, hppa, alpha, s390x, xtensa, avr, arm exception_internal, mips, and ppc. Store error_code or PC in translate where needed, then call the shared helper.
- Prefix leftover TCG helpers that still do extra work:
i386_raise_exception, riscv_raise_exception, and hexagon_raise_exception. Prefix leftover wait as mips_wait and hexagon_wait. Tricore raise_exception_sync does not join.
Yonggang Luo (21):
accel/tcg: add cpu_loop_exit_excp
helper-gen: move helper_info extern into gen_helper accel/tcg: add helper raise_excp
target/rx: convert raises to raise_excp
target/sh4: convert raises 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: convert raise_exception to hexagon_raise_exception target/hppa: convert excp to raise_excp
target/alpha: convert excp to raise_excp
target/s390x: convert exception to raise_excp 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: convert raise_exception to riscv_raise_exception target/mips: convert raise_exception to raise_excp target/ppc: convert raise_exception to raise_excp target/i386: convert raise_exception to i386_raise_exception
accel/tcg/cpu-exec-common.c | 6 ++ accel/tcg/tcg-runtime.c | 6 ++ accel/tcg/tcg-runtime.h | 11 +++ include/accel/tcg/cpu-loop.h | 13 +++ include/exec/helper-gen.h.inc | 24 ++++-- target/alpha/helper.c | 11 --- target/alpha/helper.h | 1 - target/alpha/translate.c | 9 +- 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 +- target/avr/helper.c | 24 ------ target/avr/helper.h | 3 - target/avr/translate.c | 6 +- target/hexagon/cpu.c | 13 +-- target/hexagon/cpu.h | 2 +- target/hexagon/gen_tcg_sys.h | 2 +- target/hexagon/helper.h | 5 +- target/hexagon/internal.h | 5 -- target/hexagon/macros.h | 2 +- target/hexagon/op_helper.c | 37 ++++----- target/hexagon/translate.c | 11 +-- target/hppa/helper.h | 2 - target/hppa/op_helper.c | 15 +--- target/hppa/sys_helper.c | 4 +- target/hppa/translate.c | 3 +- target/i386/helper.h | 2 +- target/i386/tcg/excp_helper.c | 18 ++-- target/i386/tcg/helper-tcg.h | 42 ++++++++-- target/i386/tcg/translate.c | 2 +- target/loongarch/tcg/helper.h | 2 - target/loongarch/tcg/op_helper.c | 6 -- target/loongarch/tcg/tcg_cpu.c | 4 +- target/loongarch/tcg/translate.c | 3 +- target/m68k/helper.c | 12 +-- target/m68k/helper.h | 1 - target/m68k/op_helper.c | 19 ----- target/m68k/translate.c | 2 +- target/microblaze/helper.c | 3 +- target/microblaze/helper.h | 2 - target/microblaze/op_helper.c | 22 +---- target/microblaze/translate.c | 3 +- target/mips/helper.h | 6 +- target/mips/tcg/exception.c | 22 +---- target/mips/tcg/fpu_helper.c | 6 +- target/mips/tcg/translate.c | 13 ++- 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 | 3 - 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 | 23 +++--- target/riscv/helper.h | 2 +- target/riscv/tcg/insn_trans/trans_rvi.c.inc | 6 +- .../tcg/insn_trans/trans_rvzicfiss.c.inc | 3 +- target/riscv/tcg/op_helper.c | 5 +- target/riscv/tcg/translate.c | 10 ++- target/rx/cpu.h | 13 +++ target/rx/helper.c | 16 ++-- target/rx/helper.h | 7 +- target/rx/op_helper.c | 46 +---------- target/rx/translate.c | 19 +++-- 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 | 24 ++++++ target/sh4/helper.c | 82 ++++++++++--------- target/sh4/helper.h | 4 - target/sh4/op_helper.c | 43 ++-------- target/sh4/translate.c | 17 +++- target/sparc/helper.c | 21 +---- target/sparc/helper.h | 2 - target/sparc/translate.c | 7 +- target/xtensa/cpu.h | 1 + target/xtensa/exc_helper.c | 13 ++- target/xtensa/helper.h | 1 - target/xtensa/translate.c | 7 +- target/xtensa/win_helper.c | 12 +-- 89 files changed, 399 insertions(+), 577 deletions(-) delete mode 100644 target/or1k/exception.c
Signature · 1 line
2.52.0.windows.1
PATCH 1/21 accel/tcg: add cpu_loop_exit_excp
Add cpu_loop_exit_excp next to cpu_loop_exit_restore. Set cpu->exception_index then restore and exit the TB. host_pc == 0 skips restore, matching existing wrappers.
--- accel/tcg/cpu-exec-common.c | 6 ++++++ include/accel/tcg/cpu-loop.h | 13 +++++++++++++ 2 files changed, 19 insertions(+)
accel/tcg/cpu-exec-common.c +6 -0
@@ -82,6 +82,12 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)cpu_loop_exit (cpu); } +void cpu_loop_exit_excp (CPUState *cpu,int exception_index,uintptr_t pc) +{ + cpu->exception_index = exception_index; +cpu_loop_exit_restore (cpu, pc); +} +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 +13 -0
@@ -65,6 +65,19 @@ 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_loop_exit_excp: +* @cpu: the cpu context +* @exception_index: EXCP_* or target trap number +* @host_pc: the host pc within the translation, or 0 +* +* Set cpu->exception_index and exit the TB. If @host_pc is in +* translated code, restore guest state first (same as +* cpu_loop_exit_restore). @host_pc == 0 skips restore. +*/ +G_NORETURN void cpu_loop_exit_excp(CPUState *cpu, int exception_index, +uintptr_t host_pc); +/** * cpu_loop_exit: * @cpu: the cpu context
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 01/21] accel/tcg: add cpu_loop_exit_excp
Quoted 34 lines · Yonggang Luo
Add
cpu_loop_exit_excpnext tocpu_loop_exit_restore. Setcpu->exception_indexthen restore and exit the TB.host_pc== 0 skips restore, matching existing wrappers.Signed-off-by Yonggang Luo <[email protected]>--- accel/tcg/cpu-exec-common.c | 6 ++++++ include/accel/tcg/cpu-loop.h | 13 +++++++++++++ 2 files changed, 19 insertions(+)accel/tcg/cpu-exec-common.c +6
-0@@ -82,6 +82,12 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)cpu_loop_exit (cpu); } +void cpu_loop_exit_excp (CPUState *cpu,int exception_index,uintptr_t pc) +{ + cpu->exception_index = exception_index; +cpu_loop_exit_restore (cpu, pc); +} +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 +0
-0@@ -65,6 +65,19 @@ 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);
include/accel/tcg/cpu-loop.h G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu); · line 76
Quoted 10 lines
include/accel/tcg/cpu-loop.h +9
-0+/** +* cpu_loop_exit_excp: +* @cpu: the cpu context +* @exception_index: EXCP_* or target trap number +* @host_pc: the host pc within the translation, or 0 +* +* Set cpu->exception_index and exit the TB. If @host_pc is in +* translated code, restore guest state first (same as +* cpu_loop_exit_restore). @host_pc == 0 skips restore.
This comment sounds like implementation detail, why mention that in the API contract? Otherwise LGTM.
Quoted 7 lines
include/accel/tcg/cpu-loop.h +4
-0+*/ +G_NORETURN void cpu_loop_exit_excp(CPUState *cpu, int exception_index, +uintptr_t host_pc); +/** * cpu_loop_exit: * @cpu: the cpu context
PATCH 2/21 helper-gen: move helper_info extern into gen_helper
In reply to Yonggang LuoDeclare helper_info inside each gen_helper_* body so a comment on DEF_HELPER attaches to gen_helper_*, not helper_info_*. The extern still refers to the global from helper-info.c.inc. Silence -Wnested-externs around the HELPER_H expansion only.
--- include/exec/helper-gen.h.inc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
include/exec/helper-gen.h.inc +16 -8
@@ -11,49 +11,49 @@ #include "exec/helper-head.h.inc" #define DEF_HELPER_FLAGS_0(name, flags, ret) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl0(ret)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call0(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret)); \ } #define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call1(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1)); \ } #define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call2(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2)); \ } #define DEF_HELPER_FLAGS_3(name, flags, ret, t1, t2, t3) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call3(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3)); \ } #define DEF_HELPER_FLAGS_4(name, flags, ret, t1, t2, t3, t4) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), \ dh_arg_decl(t3, 3), dh_arg_decl(t4, 4)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call4(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2), \
@@ -61,11 +61,11 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ } #define DEF_HELPER_FLAGS_5(name, flags, ret, t1, t2, t3, t4, t5) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), \ dh_arg_decl(t4, 4), dh_arg_decl(t5, 5)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call5(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \
@@ -73,11 +73,11 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ } #define DEF_HELPER_FLAGS_6(name, flags, ret, t1, t2, t3, t4, t5, t6) \ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), \ dh_arg_decl(t4, 4), dh_arg_decl(t5, 5), dh_arg_decl(t6, 6)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call6(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \
@@ -85,12 +85,12 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ } #define DEF_HELPER_FLAGS_7(name, flags, ret, t1, t2, t3, t4, t5, t6, t7)\ -extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg_decl(t1, 1), dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), \ dh_arg_decl(t4, 4), dh_arg_decl(t5, 5), dh_arg_decl(t6, 6), \ dh_arg_decl(t7, 7)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call7(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret), \ dh_arg(t1, 1), dh_arg(t2, 2), dh_arg(t3, 3), \
@@ -98,7 +98,15 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ dh_arg(t7, 7)); \ } +/* + * helper_info_* is declared inside gen_helper_* so a comment on + * DEF_HELPER attaches to gen_helper_*, not helper_info_*. That is a + * nested extern; silence -Wnested-externs for this expansion only. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnested-externs" #include HELPER_H +#pragma GCC diagnostic pop #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 02/21] helper-gen: move helper_info extern into gen_helper
Quoted 9 lines · Yonggang Luo
Declare
helper_infoinside each gen_helper_* body so a comment onDEF_HELPERattaches to gen_helper_*, not helper_info_*. The extern still refers to the global from helper-info.c.inc. Silence -Wnested-externs around theHELPER_Hexpansion only.Signed-off-by Yonggang Luo <[email protected]>--- include/exec/helper-gen.h.inc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
Huh? Why does comment placement matter?
include/exec/helper-gen.h.inc line 19
Quoted 8 lines
#define DEF_HELPER_FLAGS_0(name, flags, ret) \include/exec/helper-gen.h.inc +1
-1-extern TCGHelperInfo glue(helper_info_, name); \ static inline void glue(gen_helper_, name)(dh_retvar_decl0(ret)) \ { \ + extern TCGHelperInfo glue(helper_info_, name); \ tcg_gen_call0(glue(helper_info_,name).func, \ &glue(helper_info_,name), dh_retvar(ret)); \ }
...> +/*
include/exec/helper-gen.h.inc static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ · line 112
Quoted 11 lines
+ * helper_info_* is declared inside gen_helper_* so a comment on
+ *DEF_HELPERattaches to gen_helper_*, not helper_info_*. That is a
+ * nested extern; silence -Wnested-externs for this expansion only.
+ */include/exec/helper-gen.h.inc +3
-0+#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnested-externs" #include HELPER_H +#pragma GCC diagnostic pop #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1
That you have to have to have this workaround makes me less than receptive.
r~
Re: [PATCH 02/21] helper-gen: move helper_info extern into gen_helper
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Yonggang Luo
Declare
helper_infoinside each gen_helper_* body so a comment onDEF_HELPERattaches to gen_helper_*, not helper_info_*. The extern still refers to the global from helper-info.c.inc. Silence -Wnested-externs around theHELPER_Hexpansion only.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Yonggang Luo <[email protected]>--- include/exec/helper-gen.h.inc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)Huh? Why does comment placement matter?
Quoted 1 line
#define DEF_HELPER_FLAGS_0(name, flags, ret)
\
Quoted 1 line
Quoted 1 line
-extern TCGHelperInfo
glue(helper_info_, name);
\
Quoted 1 line
Quoted 1 line
static inline void
glue(gen_helper_, name)(dh_retvar_decl0(ret))
\
Please look here, this is the implementation in the header already, so we have no .c file to
comment on it. comments on &glue(helper_info_,name) do not help, because we are always calling
to gen_helper_$name. The clangd and other auto-tools can not infer comments from &glue(helper_info_,name).
If we move extern TCGHelperInfo glue(helper_info_, name); into inline
function content, then the comment on
DEF_HELPER_*() macros will take effect.
The static inline void is the source of the issue. I have no other way to deal with it.
Quoted 1 line
Quoted 1 line
{
\
Quoted 1 line
Quoted 1 line
+ extern TCGHelperInfo
glue(helper_info_, name);
\
Quoted 1 line
Quoted 1 line
tcg_gen_call0(glue(helper_info_,name).func,
\
Quoted 1 line
Quoted 1 line
&glue(helper_info_,name), dh_retvar(ret));
\
Quoted 13 lines
Quoted 1 line
}...> +/*
Quoted 9 lines
+ * helper_info_* is declared inside gen_helper_* so a comment on
+ *DEF_HELPERattaches to gen_helper_*, not helper_info_*. That is a
+ * nested extern; silence -Wnested-externs for this expansion only.
+ */include/exec/helper-gen.h.inc +3
-0+#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnested-externs" #include HELPER_H +#pragma GCC diagnostic pop
Quoted 4 lines
Quoted 2 lines
#undef
DEF_HELPER_FLAGS_0
#undefDEF_HELPER_FLAGS_1That you have to have to have this workaround makes me less than
receptive.
Quoted 3 lines
r~
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
PATCH 3/21 accel/tcg: add helper raise_excp
In reply to Yonggang LuoAdd TCG raise_excp (env, exception, restore) that exits with GETPC() or 0 via cpu_loop_exit_excp.
--- accel/tcg/tcg-runtime.c | 6 ++++++ accel/tcg/tcg-runtime.h | 11 +++++++++++ 2 files changed, 17 insertions(+)
accel/tcg/tcg-runtime.c +6 -0
@@ -130,6 +130,12 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg)return ctpop64 (arg); } +void HELPER (raise_excp )(CPUArchState *env,uint32_t exception, +uint32_t restore) +{ +cpu_loop_exit_excp (env_cpu (env), exception, restore ?GETPC () :0 ); +} +void HELPER (exit_atomic )(CPUArchState *env) {cpu_loop_exit_atomic (env_cpu (env),GETPC ());
accel/tcg/tcg-runtime.h +11 -0
@@ -22,6 +22,17 @@ 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) +/** +* raise_excp: +* @arg1: env -- CPU env +* @arg2: exception -- EXCP_* or target trap number +* @arg3: restore -- 0 skip unwind, 1 use GETPC() +* +* Shared TCG exception raise. Translate calls gen_helper_raise_excp. +* Exits via cpu_loop_exit_excp. + */ +DEF_HELPER_FLAGS_3(raise_excp, TCG_CALL_NO_WG, noreturn, env, i32, i32) + DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env)#ifndef IN_HELPER_PROTO
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
Quoted 38 lines · Yonggang Luo
Add TCG
raise_excp(env, exception, restore) that exits withGETPC()or 0 viacpu_loop_exit_excp.Signed-off-by Yonggang Luo <[email protected]>--- accel/tcg/tcg-runtime.c | 6 ++++++ accel/tcg/tcg-runtime.h | 11 +++++++++++ 2 files changed, 17 insertions(+)accel/tcg/tcg-runtime.c +6
-0@@ -130,6 +130,12 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg)return ctpop64 (arg); } +void HELPER (raise_excp )(CPUArchState *env,uint32_t exception, +uint32_t restore) +{ +cpu_loop_exit_excp (env_cpu (env), exception, restore ?GETPC () :0 ); +} +void HELPER (exit_atomic )(CPUArchState *env) {cpu_loop_exit_atomic (env_cpu (env),GETPC ());accel/tcg/tcg-runtime.h +4
-0@@ -22,6 +22,17 @@ 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) +/** +* raise_excp: +* @arg1: env -- CPU env +* @arg2: exception -- EXCP_* or target trap number
accel/tcg/tcg-runtime.h DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64) · line 38
Quoted 10 lines
accel/tcg/tcg-runtime.h +7
-0+* @arg3: restore -- 0 skip unwind, 1 use GETPC() +* +* Shared TCG exception raise. Translate calls gen_helper_raise_excp. +* Exits via cpu_loop_exit_excp. +*/ +DEF_HELPER_FLAGS_3(raise_excp, TCG_CALL_NO_WG, noreturn, env, i32, i32) + DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env)#ifndef IN_HELPER_PROTO
(1) Put the comment before the implementation, not the header. That avoids whatever you're concerned about vs patch 2.
(2) Don't pass an extra argument that changes behavior like this. Better to have two separate functions, each doing one thing.
(3) Maybe better to place the functions in cpu-exec-common.c, so that the compiler can see all the definitions at once.
r~
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Yonggang Luo
Add TCG
raise_excp(env, exception, restore) that exits withGETPC()or 0 viacpu_loop_exit_excp.Signed-off-by Yonggang Luo <[email protected]>--- accel/tcg/tcg-runtime.c | 6 ++++++ accel/tcg/tcg-runtime.h | 11 +++++++++++ 2 files changed, 17 insertions(+)accel/tcg/tcg-runtime.c +0
-0@@ -130,6 +130,12 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg)return ctpop64 (arg); }
Quoted 14 lines
accel/tcg/tcg-runtime.h DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE,
Quoted 14 lines
accel/tcg/tcg-runtime.c +6
-0+void HELPER (raise_excp )(CPUArchState *env,uint32_t exception, +uint32_t restore) +{ +cpu_loop_exit_excp (env_cpu (env), exception, restore ?GETPC () :0 ); +} +void HELPER (exit_atomic )(CPUArchState *env) {cpu_loop_exit_atomic (env_cpu (env),GETPC ());accel/tcg/tcg-runtime.h +0
-0@@ -22,6 +22,17 @@ DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE,
i64, i64)
Quoted 16 lines
Quoted 16 lines
accel/tcg/tcg-runtime.h +11
-0DEF_HELPER_FLAGS_1 (lookup_tb_ptr,TCG_CALL_NO_WG_SE , cptr, env) +/** +* raise_excp: +* @arg1: env -- CPU env +* @arg2: exception -- EXCP_* or target trap number +* @arg3: restore -- 0 skip unwind, 1 use GETPC() +* +* Shared TCG exception raise. Translate calls gen_helper_raise_excp. +* Exits via cpu_loop_exit_excp. + */ +DEF_HELPER_FLAGS_3(raise_excp, TCG_CALL_NO_WG, noreturn, env, i32, i32) +DEF_HELPER_FLAGS_1 (exit_atomic,TCG_CALL_NO_WG , noreturn, env)
Quoted 4 lines
accel/tcg/tcg-runtime.h DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64) · line 38
Quoted 1 line
accel/tcg/tcg-runtime.h +0
-0#ifndef IN_HELPER_PROTO (1) Put the comment before the implementation, not the header. That avoids whatever you're concerned about vs patch 2.
Indeed I tried, and I found basically all tcg's gen_ function have no comment(detect by the auto-tools),
and it's parameter arg0 arg1 arg2 that can not understand at all; and can not link to the impl
helper_* that defined as HELPEP(X) that makes me reading the tcg code very hard.
Quoted 3 lines
(2) Don't pass an extra argument that changes behavior like this. Better to have two separate functions, each doing one thing.
how about gen_helper_raise_excp and gen_helper_raise_excp_restore
Quoted 5 lines
(3) Maybe better to place the functions in
cpu-exec-common.c, so that the compiler can see all the definitions at once.
Do you mean do not use DEF_HELPER_FLAGS_3 at all? directly decl and imp in cpu-loop.h and cpu-exec-common.c
If this is allowed, then (1) won't be a issue
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
Quoted 6 lines · Yonggang Luo
Quoted 2 lines
(1) Put the comment before the implementation, not the header. That avoids whatever you're concerned about vs patch 2.
Indeed I tried, and I found basically all tcg's
gen_function have no comment(detect by the auto-tools), and it's parameter arg0 arg1 arg2 that can not understand at all; and can not link to the impl helper_* that defined as HELPEP(X) that makes me reading the tcg code very hard.
Ah, new-fangled tooling. Something I don't use.
To me, the only thing that's interesting is the implementation. That is, helper_foo. The wrapper, gen_helper_foo is not interesting.
Since I don't use it, I'm not sure what to suggest. Putting big block comments in what are essentially templates does not make much sense. Is there something the tooling can use to cross-reference the "real" code?
Quoted 4 lines
Quoted 2 lines
(2) Don't pass an extra argument that changes behavior like this. Better to have two separate functions, each doing one thing.
how about
gen_helper_raise_excpandgen_helper_raise_excp_restore
Sure.
Quoted 4 lines
Quoted 2 lines
(3) Maybe better to place the functions in
cpu-exec-common.c, so that the compiler can see all the definitions at once.Do you mean do not use DEF_HELPER_FLAGS_3 at all?
Absolutely not. I meant put helper_raise_excp* in cpu-exec-common.c instead of tcg-runtime.c.
r~
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Yonggang Luo
Quoted 2 lines
(1) Put the comment before the implementation, not the header. That avoids whatever you're concerned about vs patch 2.
Quoted 8 lines
Quoted 6 lines
Indeed I tried, and I found basically all tcg's
gen_function have no comment(detect by the auto-tools),
and it's parameter arg0 arg1 arg2 that can not understand at all; and can not link to the impl
helper_* that defined as HELPEP(X) that makes me reading the tcg code very hard.Ah, new-fangled tooling. Something I don't use.
I
Quoted 7 lines
To me, the only thing that's interesting is the implementation. That is,
helper_foo. The wrapper,gen_helper_foois not interesting.Since I don't use it, I'm not sure what to suggest. Putting big block comments in what are essentially templates does not make much sense. Is there something the tooling can use to cross-reference the "real" code?
Using clangd can do that, any IDE along with clangd e Language Server Protocol (LSP) will work with that.
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
(2) Don't pass an extra argument that changes behavior like this. Better to have two separate functions, each doing one thing.
how about
gen_helper_raise_excpandgen_helper_raise_excp_restore
Quoted 8 lines
Sure.
Quoted 4 lines
Quoted 2 lines
(3) Maybe better to place the functions in
cpu-exec-common.c, so that the compiler can see all the definitions at once.Do you mean do not use
DEF_HELPER_FLAGS_3at all?Absolutely not. I meant put helper_raise_excp* in
cpu-exec-common.cinstead oftcg-runtime.c.
Thanks, now I know how to go next,
void HELPER(raise_excp)(CPUArchState *env, uint32_t exception)
{
cpu_loop_exit_excp(env_cpu(env), exception, 0);
}or
void helper_raise_excp(CPUArchState *env, uint32_t exception)
{
cpu_loop_exit_excp(env_cpu(env), exception, 0);
}which I should use? I'll prefer HELPER(raise_excp)
Quoted 3 lines
r~
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
Quoted 1 line · Yonggang Luo
I'll prefer
HELPER(raise_excp)
Yes, please.
r~
Re: [PATCH 03/21] accel/tcg: add helper raise_excp
In reply to Richard HendersonQuoted 4 lines · Richard Henderson
(1) Put the comment before the implementation, not the header. That avoids whatever you're concerned about vs patch 2.
Quoted 8 lines
(2) Don't pass an extra argument that changes behavior like this. Better to have two separate functions, each doing one thing.
(3) Maybe better to place the functions in
cpu-exec-common.c, so that the compiler can see all the definitions at once.r~
accel/tcg/gen-helpers.c | 27 ++++++++ accel/tcg/meson.build | 1 + include/accel/tcg/gen-helpers.h | 37 ++++++++++ include/exec/helper-gen-common.h | 2 + include/exec/helper-impl.h | 146 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 213 insertions(+)
accel/tcg/gen-helpers.c new file +12 -0
@@ -0,0 +1,27 @@ +/* +* Shared TCG helpers implemented with IMPL_HELPER_FLAGS_*. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "accel/tcg/cpu-loop.h" +#include "accel/tcg/getpc.h" +#include "exec/helper-impl.h" + +static G_NORETURN void helper_raise_excp(CPUArchState *env, uint32_t
exception)
+ __attribute__((noinline))
+{
+ cpu_loop_exit_excp(env_cpu(env), exception, 0);
+}
+
+IMPL_HELPER_FLAGS_2(raise_excp, TCG_CALL_NO_WG, noreturn, env, i32) +
+static G_NORETURN void helper_raise_excp_restore(CPUArchState *env,
+ uint32_t exception)
+ __attribute__((noinline))
+{
+ cpu_loop_exit_excp(env_cpu(env), exception, GETPC());
+}
+
+IMPL_HELPER_FLAGS_2(raise_excp_restore, TCG_CALL_NO_WG, noreturn, env, i32)
accel/tcg/meson.build +1 -0
@@ -7,6 +7,7 @@ tcg_ss = ss.source_set() tcg_ss.add(files( 'cpu-exec.c', 'cpu-exec-common.c', + 'gen-helpers.c', 'tcg-runtime.c', 'tcg-runtime-gvec.c', 'tb-maint.c',
(quoted diff) +0 -0
b/include/accel/tcg/gen-helpers.h
new file mode 100644
index 00000000000..19787d6de24
include/accel/tcg/gen-helpers.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Shared TCG gen_helper_* APIs implemented with IMPL_HELPER_FLAGS_*. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef ACCEL_TCG_GEN_HELPERS_H +#define ACCEL_TCG_GEN_HELPERS_H + +#ifndef CONFIG_TCG +#error Can only include this header with TCG +#endif + +#include "tcg/tcg.h" + +/** +* gen_helper_raise_excp: +* @env: CPU env (tcg_env) +* @exception: EXCP_* or target trap number +* +* Shared TCG exception raise without unwind. Body is helper_raise_excp +* in accel/tcg/gen-helpers.c. Exits via cpu_loop_exit_excp with +* host_pc 0. +*/ +void gen_helper_raise_excp (TCGv_env env,TCGv_i32 exception); + +/** +* gen_helper_raise_excp_restore: +* @env: CPU env (tcg_env) +* @exception: EXCP_* or target trap number +* +* Shared TCG exception raise with GETPC() unwind. Body is +* helper_raise_excp_restore in accel/tcg/gen-helpers.c. Exits via +* cpu_loop_exit_excp. +*/ +void gen_helper_raise_excp_restore (TCGv_env env,TCGv_i32 exception); + +#endif
(quoted diff) +0 -0
b/include/exec/helper-gen-common.h
index 834590dc4e5..16548830ec8 100644
include/exec/helper-gen-common.h +2 -0
@@ -11,4 +11,6 @@#include "exec/helper-gen.h.inc" #undef HELPER_H +#include "accel/tcg/gen-helpers.h" +#endif /* HELPER_GEN_COMMON_H */
include/exec/helper-impl.h new file +146 -0
146 lines not on this page · raw message
Do you mean doing like this?
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
PATCH 4/21 target/rx: convert raises to raise_excp
In reply to Yonggang LuoName guest trap numbers RX_EXCP_* in cpu.h. TCG loop codes such as EXCP_INTERRUPT start at 0x10000. Translate privilege, illegal, BRK, and INT through gen_helper_raise_excp. Prefix leftover TCG wait as rx_wait, and drop unused raise_access_fault and the one-line raise_exception wrapper. FPSW still exits with RX_EXCP_ACCESS.
--- target/rx/cpu.h | 13 ++++++++++++ target/rx/helper.c | 16 +++++++-------- target/rx/helper.h | 7 +------ target/rx/op_helper.c | 46 +++---------------------------------------- target/rx/translate.c | 19 ++++++++++-------- 5 files changed, 36 insertions(+), 65 deletions(-)
target/rx/cpu.h +13 -0
@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +/* +* Guest trap numbers in cs->exception_index. TCG loop codes such as +* EXCP_INTERRUPT start at 0x10000 in cpu-common.h and do not overlap these. +*/ +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_INT =0x100 , +}; + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */
target/rx/helper.c +8 -8
@@ -86,13 +86,13 @@ void rx_cpu_do_interrupt(CPUState *cs) env->isp -=4 ;cpu_stl_le_data (env, env->isp, env->pc); -if (vec <0x100 ) { +if (vec <RX_EXCP_INT ) { env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); }else { env->pc =cpu_ldl_le_data (env, env->intb + (vec &0xff ) *4 ); } -if (vec ==30 ) { +if (vec ==RX_EXCP_NMI ) {/* Non-maskable interrupt */ qemu_plugin_vcpu_interrupt_cb (cs, last_pc); }else {
@@ -100,22 +100,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_INT ... RX_EXCP_INT + 0xff: expname ="unconditional trap" ; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n",
target/rx/helper.h +1 -6
@@ -1,9 +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(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) +DEF_HELPER_1(rx_wait, noreturn, env) 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 +3 -43
68 lines not on this page · raw message
target/rx/translate.c +11 -8
@@ -245,7 +245,9 @@ 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 (tcg_env, +tcg_constant_i32 (RX_EXCP_PRIVILEGE_VIOLATION ), +tcg_constant_i32 (1 )); }return 0 ; }else {
@@ -2174,7 +2176,8 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)static bool trans_BRK (DisasContext *ctx,arg_BRK *a) {tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxbrk (tcg_env); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (RX_EXCP_INT ), +tcg_constant_i32 (0 )); ctx->base.is_jmp =DISAS_NORETURN ;return true; }
@@ -2182,12 +2185,10 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a)/* 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); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (RX_EXCP_INT + a->imm), +tcg_constant_i32 (0 )); ctx->base.is_jmp =DISAS_NORETURN ;return true; }
@@ -2197,7 +2198,7 @@ static bool trans_WAIT(DisasContext *ctx, arg_WAIT *a) {if (is_privileged (ctx,1 )) {tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_wait (tcg_env); +gen_helper_rx_wait (tcg_env); }return true; }
@@ -2228,7 +2229,9 @@ 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 (tcg_env, +tcg_constant_i32 (RX_EXCP_ILLEGAL_INSTRUCTION ), +tcg_constant_i32 (1 )); } }
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 04/21] target/rx: convert raises to raise_excp
Quoted 20 lines · Yonggang Luo
Name guest trap numbers RX_EXCP_* in
cpu.h. TCG loop codes such asEXCP_INTERRUPTstart at0x10000. Translate privilege, illegal, BRK, and INT throughgen_helper_raise_excp. Prefix leftover TCG wait asrx_wait, and drop unusedraise_access_faultand the one-lineraise_exceptionwrapper. FPSW still exits withRX_EXCP_ACCESS.Signed-off-by Yonggang Luo <[email protected]>--- target/rx/cpu.h | 13 ++++++++++++ target/rx/helper.c | 16 +++++++-------- target/rx/helper.h | 7 +------ target/rx/op_helper.c | 46 +++---------------------------------------- target/rx/translate.c | 19 ++++++++++-------- 5 files changed, 36 insertions(+), 65 deletions(-)target/rx/cpu.h +0
-0
target/rx/cpu.h enum { · line 76
Quoted 6 lines
target/rx/cpu.h +3
-0@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +/* +* Guest trap numbers in cs->exception_index. TCG loop codes such as +* EXCP_INTERRUPT start at 0x10000 in cpu-common.h and do not overlap these.
The "TCG loop codes such as EXCP_INTERRUPT start at 0x10000 in cpu-common.h and do not overlap these." comment is generic, why mention it here?
target/rx/cpu.h enum { · line 85
Quoted 9 lines
target/rx/cpu.h +9
-0+*/ +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_INT =0x100 , +};
Otherwise LGTM as a separate patch.
PATCH 5/21 target/sh4: convert raises to raise_excp
In reply to Yonggang LuoName guest trap numbers SH4_EXCP_* in cpu.h. TCG loop codes such as EXCP_INTERRUPT start at 0x10000. Translate illegal and FPU-disable through gen_helper_raise_excp. Drop unused raise_* TCG helpers and the one-line raise_exception wrapper. Keep leftover sleep, trapa, and exclusive helpers. Exit unaligned and tlb_fill through cpu_loop_exit_excp. Log reset, manual reset, TLB multiple, and user break.
--- target/sh4/cpu.h | 24 +++++++++++++ target/sh4/helper.c | 82 +++++++++++++++++++++--------------------- target/sh4/helper.h | 4 --- target/sh4/op_helper.c | 43 +++------------------- target/sh4/translate.c | 17 ++++++--- 5 files changed, 84 insertions(+), 86 deletions(-)
target/sh4/cpu.h +24 -0
@@ -137,6 +137,30 @@ typedef struct memory_content {struct memory_content *next; } memory_content; +/* +* Guest trap numbers in cs->exception_index. TCG loop codes such as +* EXCP_INTERRUPT start at 0x10000 in cpu-common.h and do not overlap these. +*/ +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 +42 -40
156 lines not on this page · raw message
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 +5 -38
76 lines not on this page · raw message
target/sh4/translate.c +13 -4
@@ -1765,10 +1765,15 @@ 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 ), +tcg_constant_i32 (0 )); }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 ), +tcg_constant_i32 (0 )); } ctx->base.is_jmp =DISAS_NORETURN ;return ;
@@ -1776,9 +1781,13 @@ 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 ), +tcg_constant_i32 (0 )); }else { -gen_helper_raise_fpu_disable (tcg_env); +gen_helper_raise_excp (tcg_env, +tcg_constant_i32 (SH4_EXCP_FPU_DISABLE ), +tcg_constant_i32 (0 )); } ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 05/21] target/sh4: convert raises to raise_excp
Quoted 18 lines · Yonggang Luo
Name guest trap numbers SH4_EXCP_* in
cpu.h. TCG loop codes such asEXCP_INTERRUPTstart at0x10000. Translate illegal and FPU-disable throughgen_helper_raise_excp. Drop unused raise_* TCG helpers and the one-lineraise_exceptionwrapper. Keep leftover sleep, trapa, and exclusive helpers. Exit unaligned andtlb_fillthroughcpu_loop_exit_excp. Log reset, manual reset, TLB multiple, and user break.Signed-off-by Yonggang Luo <[email protected]>--- target/sh4/cpu.h | 24 +++++++++++++ target/sh4/helper.c | 82 +++++++++++++++++++++--------------------- target/sh4/helper.h | 4 --- target/sh4/op_helper.c | 43 +++------------------- target/sh4/translate.c | 17 ++++++--- 5 files changed, 84 insertions(+), 86 deletions(-)
Quoted 3 lines
+/*
+ * Guest trap numbers incs->exception_index. TCG loop codes such as
+ *EXCP_INTERRUPTstart at0x10000incpu-common.hand do not overlap these.
Again this is the definition of outer loop QEMU exceptions versus per-target inner loop ones. No need to mention it each time.
Quoted 10 lines
+ */
target/sh4/cpu.h +9
-0+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 ,
target/sh4/cpu.h typedef struct memory_content { · line 162
Quoted 10 lines
target/sh4/cpu.h +10
-0+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, +};
LGTM as a separate patch adding definitions.
PATCH 6/21 target/m68k: convert raises to raise_excp
In reply to Yonggang LuoTranslate through gen_helper_raise_excp with restore 0. Drop TCG raise_exception and the one-line raise_exception_ra wrappers. Keep leftover raise_exception_format2.
--- 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_loop_exit_excp (env_cpu (env),EXCP_ILLEGAL ,0 ); }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_loop_exit_excp (env_cpu (env),EXCP_ILLEGAL ,0 );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),tcg_constant_i32 (0 )); } static void gen_raise_exception_format2(DisasContext *s, int nr,
Signature · 1 line
2.52.0.windows.1
PATCH 7/21 target/or1k: convert exception to raise_excp
In reply to Yonggang LuoTranslate through gen_helper_raise_excp with restore 0. Drop TCG exception helper and exception.c. Keep C raise_exception as a static inline in exception.h. Exit RANGE overflow through cpu_loop_exit_excp.
--- 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_loop_exit_excp (CPU (cpu), excp,0 ); +}#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_loop_exit_excp (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),tcg_constant_i32 (0 )); }static void gen_illegal_exception (DisasContext *dc)
Signature · 1 line
2.52.0.windows.1
PATCH 8/21 target/microblaze: convert raise_exception to raise_excp
In reply to Yonggang LuoTranslate through gen_helper_raise_excp with restore 0 after syncing PC. Drop TCG raise_exception. Exit HW_EXCP and MMU through cpu_loop_exit_excp.
--- target/microblaze/helper.c | 3 +-- target/microblaze/helper.h | 2 -- target/microblaze/op_helper.c | 22 ++++------------------ target/microblaze/translate.c | 3 ++- 4 files changed, 7 insertions(+), 23 deletions(-)
target/microblaze/helper.c +1 -2
@@ -146,8 +146,7 @@ bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size, }/* TLB miss. */ - cs->exception_index =EXCP_MMU ; -cpu_loop_exit_restore (cs, retaddr); +cpu_loop_exit_excp (cs,EXCP_MMU , retaddr); }void mb_cpu_do_interrupt (CPUState *cs)
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 +4 -18
@@ -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_loop_exit_excp (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_loop_exit_excp (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_loop_exit_excp (cs,EXCP_HW_EXCP ,GETPC ()); } }
@@ -444,8 +431,7 @@ static void mb_transaction_failed_internal(CPUState *cs, hwaddr physaddr,if (take) { env->esr = esr; env->ear = addr; - cs->exception_index =EXCP_HW_EXCP ; -cpu_loop_exit_restore (cs, retaddr); +cpu_loop_exit_excp (cs,EXCP_HW_EXCP , retaddr); } }
target/microblaze/translate.c +2 -1
@@ -100,7 +100,8 @@ 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), +tcg_constant_i32 (0 )); dc->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH 9/21 target/sparc: convert raise_exception to raise_excp
In reply to Yonggang LuoTranslate through gen_helper_raise_excp with restore 0 after save_state. Drop TCG raise_exception. Keep C cpu_raise_exception_ra. Exit DEBUG and HLT through cpu_loop_exit_excp.
--- target/sparc/helper.c | 21 +++------------------ target/sparc/helper.h | 2 -- target/sparc/translate.c | 7 ++++--- 3 files changed, 7 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_loop_exit_excp (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_loop_exit_excp (env_cpu (env),EXCP_DEBUG ,0 ); }#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_loop_exit_excp (cs,EXCP_HLT ,0 ); }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 +4 -3
@@ -1048,7 +1048,8 @@ 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), +tcg_constant_i32 (0 )); dc->base.is_jmp =DISAS_NORETURN ; }
@@ -2811,7 +2812,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,tcg_constant_i32 (0 )); dc->base.is_jmp =DISAS_NORETURN ;return true; }
@@ -5833,7 +5834,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,tcg_constant_i32 (0 )); e_next = e->next;g_free (e);
Signature · 1 line
2.52.0.windows.1
PATCH 10/21 target/loongarch: convert raise_exception to raise_excp
In reply to Yonggang LuoTranslate through gen_helper_raise_excp with restore 1 after storing PC. Drop TCG raise_exception. Keep C do_raise_exception and use cpu_loop_exit_excp.
--- target/loongarch/tcg/helper.h | 2 -- target/loongarch/tcg/op_helper.c | 6 ------ target/loongarch/tcg/tcg_cpu.c | 4 +--- target/loongarch/tcg/translate.c | 3 ++- 4 files changed, 3 insertions(+), 12 deletions(-)
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 +1 -3
@@ -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_loop_exit_excp (cs, exception, pc); }#ifndef CONFIG_USER_ONLY
target/loongarch/tcg/translate.c +2 -1
@@ -95,7 +95,8 @@ 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 (tcg_env,tcg_constant_i32 (excp), +tcg_constant_i32 (1 )); ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH 11/21 target/hexagon: convert raise_exception to hexagon_raise_exception
In reply to Yonggang LuoFold C do_raise_exception into hexagon_raise_exception_err with vaddr pc and a retaddr parameter, and exit via cpu_loop_exit_excp. Prefix leftover TCG raise_exception to hexagon_raise_exception so translate keeps the CPU_LOG_INT log and ASSERT_DIRECT_TO_GUEST_UNSET. Prefix leftover TCG wait to hexagon_wait with vaddr pc.
--- target/hexagon/cpu.c | 13 +++++++------ target/hexagon/cpu.h | 2 +- target/hexagon/gen_tcg_sys.h | 2 +- target/hexagon/helper.h | 5 +++-- target/hexagon/internal.h | 5 ----- target/hexagon/macros.h | 2 +- target/hexagon/op_helper.c | 37 +++++++++++++++--------------------- target/hexagon/translate.c | 11 ++++++----- 8 files changed, 34 insertions(+), 43 deletions(-)
target/hexagon/cpu.c +7 -6
@@ -333,7 +333,7 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs) }if (pc &PCALIGN_MASK ) { env->cause_code =HEX_CAUSE_PC_NOT_ALIGNED ; -hexagon_raise_exception_err (env,HEX_EVENT_PRECISE , pc); +hexagon_raise_exception_err (env,HEX_EVENT_PRECISE , pc,0 ); }#ifndef CONFIG_USER_ONLY
@@ -711,14 +711,15 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,return false; }raise_perm_exception (cs, address, slot, access_type, excp); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], - retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC ], retaddr); }if (probe) {return false; }raise_tlbmiss_exception (cs, address, slot, access_type); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC ], retaddr); }#include "hw/core/sysemu-cpu-ops.h"
@@ -761,8 +762,8 @@ void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr,CPUHexagonState *env =cpu_env (cs);raise_misaligned_exception (cs, addr,0 , access_type); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], - retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC], retaddr); }#endif
target/hexagon/cpu.h +1 -1
@@ -210,7 +210,7 @@ FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1) G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,uint32_t exception, -uintptr_t pc); +vaddr pc,uintptr_t retaddr);#ifndef CONFIG_USER_ONLY /*
target/hexagon/gen_tcg_sys.h +1 -1
@@ -80,7 +80,7 @@#define fGEN_TCG_Y2_wait (SHORTCODE ) \ do { \ RsV = RsV; \ - gen_helper_wait(tcg_env, tcg_constant_tl(ctx->pkt.pc)); \ + gen_helper_hexagon_wait(tcg_env, tcg_constant_vaddr(ctx->pkt.pc)); \ } while (0)#define fGEN_TCG_Y2_resume (SHORTCODE ) \
target/hexagon/helper.h +3 -2
@@ -18,7 +18,8 @@#include "internal.h" #include "helper_protos_generated.h.inc" -DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32) +DEF_HELPER_FLAGS_3 (hexagon_raise_exception,TCG_CALL_NO_RETURN , noreturn, + env, i32, vaddr) DEF_HELPER_2(commit_store, void, env, int) DEF_HELPER_3(gather_store, void, env, i32, int)DEF_HELPER_1 (commit_hvx_stores, void, env)
@@ -136,7 +137,7 @@ DEF_HELPER_3(sreg_write_masked, void, env, i32, i32) DEF_HELPER_3(setprio, void, env, i32, i32) DEF_HELPER_2(start, void, env, i32) DEF_HELPER_1(stop, void, env) -DEF_HELPER_2(wait, void, env, i32) +DEF_HELPER_2(hexagon_wait, void, env, vaddr) DEF_HELPER_2(resume, void, env, i32) DEF_HELPER_1(resched, void, env)DEF_HELPER_3 (modify_ssr, void, env, i32, i32)
target/hexagon/internal.h +0 -5
@@ -36,11 +36,6 @@ extern const char * const hexagon_sregnames[];extern const char *const hexagon_gregnames[];#endif -void G_NORETURN do_raise_exception(CPUHexagonState *env, -uint32_t exception, -uint32_t PC , -uintptr_t retaddr); -#define hexagon_cpu_mmu_enabled (env) ({ \ HexagonCPU *cpu = env_archcpu(env); \ cpu->globalregs ? \
target/hexagon/macros.h +1 -1
@@ -637,7 +637,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#ifdef CONFIG_USER_ONLY #define fTRAP (TRAPTYPE ,IMM ) \ do { \ - hexagon_raise_exception_err(env, HEX_EVENT_TRAP0, PC); \ + hexagon_raise_exception_err(env, HEX_EVENT_TRAP0, PC, 0); \ } while (0)#endif
target/hexagon/op_helper.c +15 -22
@@ -72,31 +72,24 @@ uint64_t HELPER(utimer)(void)#define SF_MANTBITS 23/* Exceptions processing helpers */ -G_NORETURN -void do_raise_exception(CPUHexagonState *env, uint32_t exception, -uint32_t PC ,uintptr_t retaddr) +G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, +uint32_t exception, +vaddr pc,uintptr_t retaddr) {CPUState *cs =env_cpu (env); -qemu_log_mask (CPU_LOG_INT ,"%s: 0x%08" PRIx32", @ %08" PRIx32"\n" , - __func__, exception,PC ); +qemu_log_mask (CPU_LOG_INT ,"%s: 0x%08" PRIx32", @ %08" VADDR_PRIx"\n" , + __func__, exception, pc);ASSERT_DIRECT_TO_GUEST_UNSET (env, exception); - env->gpr[HEX_REG_PC ] =PC ; - cs->exception_index = exception; -cpu_loop_exit_restore (cs, retaddr); -} - -G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, -uint32_t exception, -uintptr_t pc) -{ -do_raise_exception (env, exception, pc,0 ); + env->gpr[HEX_REG_PC ] = pc; +cpu_loop_exit_excp (cs, exception, retaddr); } -G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp, -uint32_t PC ) +G_NORETURN void HELPER(hexagon_raise_exception)(CPUHexagonState *env, +uint32_t exception, +vaddr pc) { -hexagon_raise_exception_err (env, excp,PC ); +hexagon_raise_exception_err (env, exception, pc,0 ); } void log_store32(CPUHexagonState *env, target_ulong addr,
@@ -1733,7 +1726,7 @@ static void set_wait_mode(CPUHexagonState *env)SET_SYSTEM_FIELD (env,HEX_SREG_MODECTL ,MODECTL_W , thread_wait_mask); } -static void hexagon_wait_thread (CPUHexagonState *env,uint32_t PC ) +static void hexagon_wait_thread (CPUHexagonState *env,vaddr pc) {CPUState *cs;
@@ -1760,7 +1753,7 @@ static void hexagon_wait_thread(CPUHexagonState *env, uint32_t PC)return ; }set_wait_mode (env); - env->wait_next_pc =PC +4 ; + env->wait_next_pc = pc +4 ;cpu_interrupt (cs,CPU_INTERRUPT_HALT ); }
@@ -1828,12 +1821,12 @@ void HELPER(resched)(CPUHexagonState *env)resched (env); } -void HELPER (wait )(CPUHexagonState *env,uint32_t PC ) +void HELPER (hexagon_wait )(CPUHexagonState *env,vaddr pc) {BQL_LOCK_GUARD ();if (!fIN_DEBUG_MODE (env->threadId)) { -hexagon_wait_thread (env,PC ); +hexagon_wait_thread (env, pc); } }
target/hexagon/translate.c +6 -5
@@ -129,11 +129,12 @@ intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,return offset; } -static void gen_precise_exception (int cause,uint32_t PC ) +static void gen_precise_exception (int cause,vaddr pc) {tcg_gen_movi_i32 (hex_cause_code, cause); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (HEX_EVENT_PRECISE ), -tcg_constant_i32 (PC )); +gen_helper_hexagon_raise_exception (tcg_env, +tcg_constant_i32 (HEX_EVENT_PRECISE ), +tcg_constant_vaddr (pc)); }#ifndef CONFIG_USER_ONLY
@@ -1071,11 +1072,11 @@ static void update_exec_counters(DisasContext *ctx)*/ static void check_imprecise_exception (DisasContext *ctx) { -TCGv PC =tcg_constant_tl (ctx->pkt.pc);TCGLabel *label =gen_new_label ();tcg_gen_brcondi_tl (TCG_COND_EQ , hex_imprecise_exception,0 , label); -gen_helper_raise_exception (tcg_env, hex_imprecise_exception,PC ); +gen_helper_hexagon_raise_exception (tcg_env, hex_imprecise_exception, +tcg_constant_vaddr (ctx->pkt.pc));gen_set_label (label); }#endif
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 11/21] target/hexagon: convert raise_exception to hexagon_raise_exception
Quoted 8 lines · Yonggang Luo
Fold C
do_raise_exceptionintohexagon_raise_exception_errwith vaddr pc and a retaddr parameter, and exit viacpu_loop_exit_excp. Prefix leftover TCGraise_exceptiontohexagon_raise_exceptionso translate keeps theCPU_LOG_INTlog andASSERT_DIRECT_TO_GUEST_UNSET. Prefix leftover TCG wait tohexagon_waitwith vaddr pc.Signed-off-by Yonggang Luo <[email protected]>---
Quoted 245 lines
target/hexagon/cpu.c | 13 +++++++------ target/hexagon/cpu.h | 2 +- target/hexagon/gen_tcg_sys.h | 2 +- target/hexagon/helper.h | 5 +++-- target/hexagon/internal.h | 5 ----- target/hexagon/macros.h | 2 +- target/hexagon/op_helper.c | 37 +++++++++++++++--------------------- target/hexagon/translate.c | 11 ++++++----- 8 files changed, 34 insertions(+), 43 deletions(-)target/hexagon/cpu.c +7
-6@@ -333,7 +333,7 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs) }if (pc &PCALIGN_MASK ) { env->cause_code =HEX_CAUSE_PC_NOT_ALIGNED ; -hexagon_raise_exception_err (env,HEX_EVENT_PRECISE , pc); +hexagon_raise_exception_err (env,HEX_EVENT_PRECISE , pc,0 ); }#ifndef CONFIG_USER_ONLY @@ -711,14 +711,15 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,return false; }raise_perm_exception (cs, address, slot, access_type, excp); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], - retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC ], retaddr); }if (probe) {return false; }raise_tlbmiss_exception (cs, address, slot, access_type); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC ], retaddr); }#include "hw/core/sysemu-cpu-ops.h" @@ -761,8 +762,8 @@ void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr,CPUHexagonState *env =cpu_env (cs);raise_misaligned_exception (cs, addr,0 , access_type); -do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], - retaddr); +hexagon_raise_exception_err (env, cs->exception_index, + env->gpr[HEX_REG_PC], retaddr); }#endif target/hexagon/cpu.h +1
-1@@ -210,7 +210,7 @@ FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1) G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,uint32_t exception, -uintptr_t pc); +vaddr pc,uintptr_t retaddr);#ifndef CONFIG_USER_ONLY /* target/hexagon/gen_tcg_sys.h +1
-1@@ -80,7 +80,7 @@#define fGEN_TCG_Y2_wait (SHORTCODE ) \ do { \ RsV = RsV; \ - gen_helper_wait(tcg_env, tcg_constant_tl(ctx->pkt.pc)); \ + gen_helper_hexagon_wait(tcg_env, tcg_constant_vaddr(ctx->pkt.pc)); \ } while (0)#define fGEN_TCG_Y2_resume (SHORTCODE ) \target/hexagon/helper.h +3
-2@@ -18,7 +18,8 @@#include "internal.h" #include "helper_protos_generated.h.inc" -DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32) +DEF_HELPER_FLAGS_3 (hexagon_raise_exception,TCG_CALL_NO_RETURN , noreturn, + env, i32, vaddr) DEF_HELPER_2(commit_store, void, env, int) DEF_HELPER_3(gather_store, void, env, i32, int)DEF_HELPER_1 (commit_hvx_stores, void, env)@@ -136,7 +137,7 @@ DEF_HELPER_3(sreg_write_masked, void, env, i32, i32) DEF_HELPER_3(setprio, void, env, i32, i32) DEF_HELPER_2(start, void, env, i32) DEF_HELPER_1(stop, void, env) -DEF_HELPER_2(wait, void, env, i32) +DEF_HELPER_2(hexagon_wait, void, env, vaddr) DEF_HELPER_2(resume, void, env, i32) DEF_HELPER_1(resched, void, env)DEF_HELPER_3 (modify_ssr, void, env, i32, i32)target/hexagon/internal.h +0
-5@@ -36,11 +36,6 @@ extern const char * const hexagon_sregnames[];extern const char *const hexagon_gregnames[];#endif -void G_NORETURN do_raise_exception(CPUHexagonState *env, -uint32_t exception, -uint32_t PC , -uintptr_t retaddr); -#define hexagon_cpu_mmu_enabled (env) ({ \ HexagonCPU *cpu = env_archcpu(env); \ cpu->globalregs ? \target/hexagon/macros.h +1
-1@@ -637,7 +637,7 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#ifdef CONFIG_USER_ONLY #define fTRAP (TRAPTYPE ,IMM ) \ do { \ - hexagon_raise_exception_err(env, HEX_EVENT_TRAP0, PC); \ + hexagon_raise_exception_err(env, HEX_EVENT_TRAP0, PC, 0); \ } while (0)#endif target/hexagon/op_helper.c +15
-22@@ -72,31 +72,24 @@ uint64_t HELPER(utimer)(void)#define SF_MANTBITS 23/* Exceptions processing helpers */ -G_NORETURN -void do_raise_exception(CPUHexagonState *env, uint32_t exception, -uint32_t PC ,uintptr_t retaddr) +G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, +uint32_t exception, +vaddr pc,uintptr_t retaddr) {CPUState *cs =env_cpu (env); -qemu_log_mask (CPU_LOG_INT ,"%s: 0x%08" PRIx32", @ %08" PRIx32"\n" , - __func__, exception,PC ); +qemu_log_mask (CPU_LOG_INT ,"%s: 0x%08" PRIx32", @ %08" VADDR_PRIx"\n" , + __func__, exception, pc);ASSERT_DIRECT_TO_GUEST_UNSET (env, exception); - env->gpr[HEX_REG_PC ] =PC ; - cs->exception_index = exception; -cpu_loop_exit_restore (cs, retaddr); -} - -G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env, -uint32_t exception, -uintptr_t pc) -{ -do_raise_exception (env, exception, pc,0 ); + env->gpr[HEX_REG_PC ] = pc; +cpu_loop_exit_excp (cs, exception, retaddr); } -G_NORETURN void HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp, -uint32_t PC ) +G_NORETURN void HELPER(hexagon_raise_exception)(CPUHexagonState *env, +uint32_t exception, +vaddr pc) { -hexagon_raise_exception_err (env, excp,PC ); +hexagon_raise_exception_err (env, exception, pc,0 ); } void log_store32(CPUHexagonState *env, target_ulong addr,@@ -1733,7 +1726,7 @@ static void set_wait_mode(CPUHexagonState *env)SET_SYSTEM_FIELD (env,HEX_SREG_MODECTL ,MODECTL_W , thread_wait_mask); } -static void hexagon_wait_thread (CPUHexagonState *env,uint32_t PC ) +static void hexagon_wait_thread (CPUHexagonState *env,vaddr pc) {CPUState *cs;@@ -1760,7 +1753,7 @@ static void hexagon_wait_thread(CPUHexagonState *env, uint32_t PC)return ; }set_wait_mode (env); - env->wait_next_pc =PC +4 ; + env->wait_next_pc = pc +4 ;cpu_interrupt (cs,CPU_INTERRUPT_HALT ); }@@ -1828,12 +1821,12 @@ void HELPER(resched)(CPUHexagonState *env)resched (env); } -void HELPER (wait )(CPUHexagonState *env,uint32_t PC ) +void HELPER (hexagon_wait )(CPUHexagonState *env,vaddr pc) {BQL_LOCK_GUARD ();if (!fIN_DEBUG_MODE (env->threadId)) { -hexagon_wait_thread (env,PC ); +hexagon_wait_thread (env, pc); } }target/hexagon/translate.c +6
-5@@ -129,11 +129,12 @@ intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,return offset; } -static void gen_precise_exception (int cause,uint32_t PC ) +static void gen_precise_exception (int cause,vaddr pc) {tcg_gen_movi_i32 (hex_cause_code, cause); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (HEX_EVENT_PRECISE ), -tcg_constant_i32 (PC )); +gen_helper_hexagon_raise_exception (tcg_env, +tcg_constant_i32 (HEX_EVENT_PRECISE ), +tcg_constant_vaddr (pc)); }#ifndef CONFIG_USER_ONLY @@ -1071,11 +1072,11 @@ static void update_exec_counters(DisasContext *ctx)*/ static void check_imprecise_exception (DisasContext *ctx) { -TCGv PC =tcg_constant_tl (ctx->pkt.pc);TCGLabel *label =gen_new_label ();tcg_gen_brcondi_tl (TCG_COND_EQ , hex_imprecise_exception,0 , label); -gen_helper_raise_exception (tcg_env, hex_imprecise_exception,PC ); +gen_helper_hexagon_raise_exception (tcg_env, hex_imprecise_exception, +tcg_constant_vaddr (ctx->pkt.pc));gen_set_label (label); }#endif
PATCH 12/21 target/hppa: convert excp to raise_excp
In reply to Yonggang LuoDrop TCG excp and call gen_helper_raise_excp with restore 0. Keep C hppa_dynamic_excp and use cpu_loop_exit_excp. Route leftover C callers through hppa_dynamic_excp instead of helper_excp.
--- target/hppa/helper.h | 2 -- target/hppa/op_helper.c | 15 ++------------- target/hppa/sys_helper.c | 4 ++-- target/hppa/translate.c | 3 ++- 4 files changed, 6 insertions(+), 18 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 +2 -13
@@ -30,20 +30,9 @@#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); - - cs->exception_index = excp; -cpu_loop_exit_restore (cs, ra); +cpu_loop_exit_excp (env_cpu (env), excp, ra); } static void atomic_store_mask32(CPUHPPAState *env, target_ulong addr,
@@ -341,7 +330,7 @@ target_ulong HELPER(probe)(CPUHPPAState *env, target_ulong addr,if (excp ==EXCP_DTLB_MISS ) { excp =EXCP_NA_DTLB_MISS ; } - helper_excp(env, excp); + hppa_dynamic_excp(env, excp, 0); }return (want & prot) !=0 ;#endif
target/hppa/sys_helper.c +2 -2
@@ -51,13 +51,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 ); +hppa_dynamic_excp (env,EXCP_HLT ,0 ); }void HELPER (reset )(CPUHPPAState *env) {qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); -helper_excp (env,EXCP_HLT ); +hppa_dynamic_excp (env,EXCP_HLT ,0 ); }target_ulong HELPER (swap_system_mask )(CPUHPPAState *env,target_ulong nsm)
target/hppa/translate.c +2 -1
@@ -726,7 +726,8 @@ 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), +tcg_constant_i32 (0 )); }static void gen_excp (DisasContext *ctx,int exception)
Signature · 1 line
2.52.0.windows.1
PATCH 13/21 target/alpha: convert excp to raise_excp
In reply to Yonggang LuoStore error_code in translate, then call gen_helper_raise_excp with restore 0. Drop TCG excp. Keep C dynamic_excp and arith_excp.
--- target/alpha/helper.c | 11 ----------- target/alpha/helper.h | 1 - target/alpha/translate.c | 9 ++++----- 3 files changed, 4 insertions(+), 17 deletions(-)
target/alpha/helper.c +0 -11
@@ -533,17 +533,6 @@ void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)qemu_fprintf (f,"\n" ); } -/* This should only be called from translate, via gen_excp. -We expect that ENV->PC has already been updated. */ -G_NORETURN void helper_excp(CPUAlphaState *env, int excp, int error) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = excp; - env->error_code = error; -cpu_loop_exit (cs); -} -/* This may be called from any of the helpers to set up EXCEPTION_INDEX. */ G_NORETURN void dynamic_excp(CPUAlphaState *env, uintptr_t retaddr,int excp,int error)
target/alpha/helper.h +0 -1
@@ -1,4 +1,3 @@ -DEF_HELPER_3(excp, noreturn, env, int, int) DEF_HELPER_FLAGS_1(load_pcc, TCG_CALL_NO_RWG_SE, i64, env)DEF_HELPER_FLAGS_3 (check_overflow,TCG_CALL_NO_WG , void, env, i64, i64)
target/alpha/translate.c +4 -5
@@ -264,11 +264,10 @@ static void gen_pc_disp(DisasContext *ctx, TCGv_i64 dest, int32_t disp)static void gen_excp_1 (int exception,int error_code) { -TCGv_i32 tmp1, tmp2; - - tmp1 =tcg_constant_i32 (exception); - tmp2 =tcg_constant_i32 (error_code); -gen_helper_excp (tcg_env, tmp1, tmp2); +tcg_gen_st_i32 (tcg_constant_i32 (error_code), tcg_env, + offsetof(CPUAlphaState , error_code)); +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (exception), +tcg_constant_i32 (0 )); }static DisasJumpType gen_excp (DisasContext *ctx,int exception,int error_code)
Signature · 1 line
2.52.0.windows.1
PATCH 14/21 target/s390x: convert exception to raise_excp
In reply to Yonggang LuoDrop TCG exception and call gen_helper_raise_excp with restore 0. Keep data_exception. Route leftover C SVC execute through cpu_loop_exit_excp.
--- 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_loop_exit_excp (env_cpu (env),EXCP_SVC ,0 );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),tcg_constant_i32 (0 )); }static void gen_program_exception (DisasContext *s,int code)
Signature · 1 line
2.52.0.windows.1
PATCH 15/21 target/xtensa: convert exception to raise_excp
In reply to Yonggang LuoStore yield_needed = 0 when raising YIELD, then call gen_helper_raise_excp with restore 0. Drop TCG exception. Keep exception_cause helpers. C callers use xtensa_exception for the old helper_exception body.
--- target/xtensa/cpu.h | 1 + target/xtensa/exc_helper.c | 13 +++++-------- target/xtensa/helper.h | 1 - target/xtensa/translate.c | 7 ++++++- target/xtensa/win_helper.c | 12 ++++++------ 5 files changed, 18 insertions(+), 16 deletions(-)
target/xtensa/cpu.h +1 -0
@@ -601,6 +601,7 @@ int xtensa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); G_NORETURN void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr); +G_NORETURN void xtensa_exception(CPUXtensaState *env, uint32_t excp);#define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
target/xtensa/exc_helper.c +5 -8
@@ -35,15 +35,12 @@#include "qemu/atomic.h" #include "qemu/plugin.h" -void HELPER (exception )(CPUXtensaState *env,uint32_t excp) +void xtensa_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); +cpu_loop_exit_excp (env_cpu (env), excp,0 ); }void HELPER (exception_cause )(CPUXtensaState *env,uint32_t pc,uint32_t cause)
@@ -66,7 +63,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); +xtensa_exception (env, vector); } void HELPER(exception_cause_vaddr)(CPUXtensaState *env,
@@ -93,7 +90,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 ); +xtensa_exception (env,EXC_DEBUG ); }#ifndef CONFIG_USER_ONLY
@@ -116,7 +113,7 @@ void HELPER(waiti)(CPUXtensaState *env, uint32_t pc, uint32_t intlevel) } cpu->halted =1 ; -HELPER (exception)(env,EXCP_HLT ); +xtensa_exception (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 +6 -1
@@ -305,7 +305,12 @@ static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa)static void gen_exception (DisasContext *dc,int excp) { -gen_helper_exception (tcg_env,tcg_constant_i32 (excp)); +if (excp ==EXCP_YIELD ) { +tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, + offsetof(CPUXtensaState , yield_needed)); + } +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (excp), +tcg_constant_i32 (0 )); }static void gen_exception_cause (DisasContext *dc,uint32_t cause)
target/xtensa/win_helper.c +6 -6
@@ -125,13 +125,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 ); +xtensa_exception (env,EXC_WINDOW_OVERFLOW4 );break ;case 1 : -HELPER (exception)(env,EXC_WINDOW_OVERFLOW8 ); +xtensa_exception (env,EXC_WINDOW_OVERFLOW8 );break ;default : -HELPER (exception)(env,EXC_WINDOW_OVERFLOW12 ); +xtensa_exception (env,EXC_WINDOW_OVERFLOW12 );break ; } }
@@ -174,11 +174,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 ); +xtensa_exception (env,EXC_WINDOW_UNDERFLOW4 ); }else if (n ==2 ) { -HELPER (exception)(env,EXC_WINDOW_UNDERFLOW8 ); +xtensa_exception (env,EXC_WINDOW_UNDERFLOW8 ); }else if (n ==3 ) { -HELPER (exception)(env,EXC_WINDOW_UNDERFLOW12 ); +xtensa_exception (env,EXC_WINDOW_UNDERFLOW12 ); } } }
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 15/21] target/xtensa: convert exception to raise_excp
Quoted 20 lines · Yonggang Luo
Store
yield_needed= 0 when raising YIELD, then callgen_helper_raise_excpwith restore 0. Drop TCG exception. Keepexception_causehelpers. C callers usextensa_exceptionfor the oldhelper_exceptionbody.Signed-off-by Yonggang Luo <[email protected]>--- target/xtensa/cpu.h | 1 + target/xtensa/exc_helper.c | 13 +++++-------- target/xtensa/helper.h | 1 - target/xtensa/translate.c | 7 ++++++- target/xtensa/win_helper.c | 12 ++++++------ 5 files changed, 18 insertions(+), 16 deletions(-)target/xtensa/translate.c +0
-0
target/xtensa/translate.c static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa) · line 310
Quoted 7 lines
target/xtensa/translate.c +3
-1@@ -305,7 +305,12 @@ static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa)static void gen_exception (DisasContext *dc,int excp) { -gen_helper_exception (tcg_env,tcg_constant_i32 (excp)); +if (excp ==EXCP_YIELD ) { +tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, + offsetof(CPUXtensaState , yield_needed));
This is the single call, rename as gen_yield() dropping the if in a preliminary patch? Otherwise patch LGTM.
Quoted 4 lines
target/xtensa/translate.c +3
-0+ } +gen_helper_raise_excp (tcg_env,tcg_constant_i32 (excp), +tcg_constant_i32 (0 )); }
PATCH 16/21 target/avr: convert debug/break/sleep to raise_excp
In reply to Yonggang LuoReplace debug, break, and sleep TCG helpers withgen_helper_raise_excp. Keep unsupported.
--- target/avr/helper.c | 24 ------------------------ target/avr/helper.h | 3 --- target/avr/translate.c | 6 ++++-- 3 files changed, 4 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 +4 -2
@@ -2554,7 +2554,8 @@ 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 ), +tcg_constant_i32 (0 )); ctx->base.is_jmp =DISAS_EXIT ;#else /* NOP */
@@ -2580,7 +2581,8 @@ 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 ), +tcg_constant_i32 (0 )); ctx->base.is_jmp =DISAS_NORETURN ;return true; }
Signature · 1 line
2.52.0.windows.1
PATCH 17/21 target/arm: convert exception_internal to raise_excp
In reply to Yonggang LuoSwitch 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.
--- 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(-)
target/arm/internals.h +20 -7
@@ -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.
target/arm/tcg-stubs.c +2 -2
@@ -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 (); }
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_loop_exit_excp (env_cpu (env),EXCP_EXCEPTION_EXIT ,0 );/* notreached */ }
target/arm/tcg/op_helper.c +11 -32
99 lines not on this page · raw message
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),tcg_constant_i32 (0 )); }static void gen_singlestep_exception (DisasContext *s)
Signature · 1 line
2.52.0.windows.1
PATCH 18/21 target/riscv: convert raise_exception to riscv_raise_exception
In reply to Yonggang LuoPrefix leftover TCG raise_exception to riscv_raise_exception so translate still decrements instret then exits with restore 0. Keep C riscv_raise_exception via cpu_loop_exit_excp.
--- target/riscv/helper.h | 2 +- target/riscv/tcg/insn_trans/trans_rvi.c.inc | 6 ++---- target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc | 3 +-- target/riscv/tcg/op_helper.c | 5 ++--- target/riscv/tcg/translate.c | 10 +++++++--- 5 files changed, 13 insertions(+), 13 deletions(-)
target/riscv/helper.h +1 -1
@@ -1,5 +1,5 @@/* Exceptions */ -DEF_HELPER_2 (raise_exception, noreturn, env, i32) +DEF_HELPER_2 (riscv_raise_exception, noreturn, env, i32) /* Floating Point - rounding mode */DEF_HELPER_FLAGS_2 (set_rounding_mode,TCG_CALL_NO_WG , void, env, i32)
target/riscv/tcg/insn_trans/trans_rvi.c.inc +2 -4
@@ -55,8 +55,7 @@ static bool trans_lpad(DisasContext *ctx, arg_lpad *a) */ tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_FCFI_TVAL), tcg_env, offsetof(CPURISCVState, sw_check_code)); - gen_helper_raise_exception(tcg_env, - tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_raise_exception(RISCV_EXCP_SW_CHECK); return true; }
@@ -68,8 +67,7 @@ static bool trans_lpad(DisasContext *ctx, arg_lpad *a) tcg_gen_brcondi_tl(TCG_COND_EQ, tmp, a->label, skip); tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_FCFI_TVAL), tcg_env, offsetof(CPURISCVState, sw_check_code)); - gen_helper_raise_exception(tcg_env, - tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_raise_exception(RISCV_EXCP_SW_CHECK); gen_set_label(skip); }
target/riscv/tcg/insn_trans/trans_rvzicfiss.c.inc +1 -2
@@ -43,8 +43,7 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a) tcg_gen_brcond_tl(TCG_COND_EQ, data, rs1, skip); tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_BCFI_TVAL), tcg_env, offsetof(CPURISCVState, sw_check_code)); - gen_helper_raise_exception(tcg_env, - tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_raise_exception(RISCV_EXCP_SW_CHECK); gen_set_label(skip); tcg_gen_addi_tl(addr, addr, tmp); tcg_gen_ext_tl_i64(wide_addr, addr);
target/riscv/tcg/op_helper.c +2 -3
@@ -44,11 +44,10 @@ 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_loop_exit_excp (cs, exception, pc); } -void helper_raise_exception (CPURISCVState *env,uint32_t exception) +void HELPER (riscv_raise_exception )(CPURISCVState *env,uint32_t exception) {#ifndef CONFIG_USER_ONLY riscv_pmu_decr_instret (env);
target/riscv/tcg/translate.c +7 -3
@@ -254,10 +254,15 @@ static void gen_update_pc(DisasContext *ctx, target_long diff) ctx->pc_save = ctx->base.pc_next + diff; } +static void gen_raise_exception (uint32_t excp) +{ +gen_helper_riscv_raise_exception (tcg_env,tcg_constant_i32 (excp)); +} +static void generate_exception (DisasContext *ctx,RISCVException excp) {gen_update_pc (ctx,0 ); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (excp)); +gen_raise_exception (excp); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -1394,8 +1399,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) tcg_ctx->emit_before_op =QTAILQ_NEXT (ctx->base.insn_start, link);tcg_gen_st8_i32 (tcg_constant_i32 (RISCV_EXCP_SW_CHECK_FCFI_TVAL ), tcg_env, offsetof(CPURISCVState , sw_check_code)); -gen_helper_raise_exception (tcg_env, -tcg_constant_i32 (RISCV_EXCP_SW_CHECK )); +gen_raise_exception (RISCV_EXCP_SW_CHECK ); tcg_ctx->emit_before_op =NULL ; ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1
PATCH 19/21 target/mips: convert raise_exception to raise_excp
In reply to Yonggang LuoStore error_code then call raise_excp, with restore 0 for _err and 1 for the 2-arg path. Drop TCG raise_exception, raise_exception_err, and unused debug DEF. Prefix leftover TCG wait to mips_wait. Keep C do_raise_exception_err via cpu_loop_exit_excp.
--- target/mips/helper.h | 6 +----- target/mips/tcg/exception.c | 22 ++-------------------- target/mips/tcg/fpu_helper.c | 6 +++--- target/mips/tcg/translate.c | 13 +++++++++---- 4 files changed, 15 insertions(+), 32 deletions(-)
target/mips/helper.h +1 -5
@@ -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)
@@ -250,7 +246,7 @@ DEF_HELPER_1(rdhwr_xnp, tl, env) DEF_HELPER_1(rdhwr_chord, tl, env) DEF_HELPER_1(rdhwr_cvmcount, tl, env) DEF_HELPER_2(pmon, void, env, int) -DEF_HELPER_1(wait, void, env) +DEF_HELPER_1(mips_wait, void, env)#ifdef TARGET_MIPS64 DEF_HELPER_FLAGS_2 (lcsr_cpucfg,TCG_CALL_NO_RWG_SE , tl, env, tl)
target/mips/tcg/exception.c +2 -20
@@ -44,28 +44,12 @@ 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 ); -} -static void raise_exception (CPUMIPSState *env,uint32_t exception) {do_raise_exception (env, exception,0 ); } -void helper_wait (CPUMIPSState *env) +void helper_mips_wait (CPUMIPSState *env) {CPUState *cs =env_cpu (env);
@@ -145,8 +129,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_loop_exit_excp (cs, exception, pc); }
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 :
target/mips/tcg/translate.c +9 -4
@@ -1316,14 +1316,19 @@ 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), +tcg_constant_i32 (0 )); 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 (tcg_env,tcg_constant_i32 (excp), +tcg_constant_i32 (1 )); }void generate_exception_end (DisasContext *ctx,int excp)
@@ -8683,7 +8688,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc, ctx->base.pc_next +=4 ;save_cpu_state (ctx,1 ); ctx->base.pc_next -=4 ; -gen_helper_wait (tcg_env); +gen_helper_mips_wait (tcg_env); ctx->base.is_jmp =DISAS_NORETURN ;break ;default :
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 19/21] target/mips: convert raise_exception to raise_excp
target/mips/tcg/translate.c static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc, · line 8691
Quoted 6 lines · Yonggang Luo
target/mips/tcg/translate.c +1
-1@@ -8683,7 +8688,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc, ctx->base.pc_next +=4 ;save_cpu_state (ctx,1 ); ctx->base.pc_next -=4 ; -gen_helper_wait (tcg_env); +gen_helper_mips_wait (tcg_env);
This is unrelated to $SUBJECT.
r~
Re: [PATCH 19/21] target/mips: convert raise_exception to raise_excp
In reply to Yonggang LuoQuoted 4 lines · Yonggang Luo
Store
error_codethen callraise_excp, with restore 0 for_errand 1 for the 2-arg path. Drop TCGraise_exception,raise_exception_err, and unused debug DEF. Prefix leftover TCG wait tomips_wait. Keep Cdo_raise_exception_errviacpu_loop_exit_excp.
Please move "Prefix leftover TCG wait to mips_wait." in a distinct patch.
Quoted 8 lines
Signed-off-by Yonggang Luo <[email protected]>--- target/mips/helper.h | 6 +----- target/mips/tcg/exception.c | 22 ++-------------------- target/mips/tcg/fpu_helper.c | 6 +++--- target/mips/tcg/translate.c | 13 +++++++++---- 4 files changed, 15 insertions(+), 32 deletions(-)
PATCH 20/21 target/ppc: convert raise_exception to raise_excp
In reply to Yonggang LuoStore error_code then call raise_excp with restore 0. Drop TCG raise_exception and raise_exception_err. Move C raise_exception_err_ra to static inline in internal.h, and remove the cpu.h prototype. Callers include internal.h.
--- target/ppc/cpu.h | 3 --- 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 | 23 ++++++++++------------- 7 files changed, 21 insertions(+), 39 deletions(-)
target/ppc/cpu.h +0 -3
@@ -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_loop_exit_excp (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 +10 -13
@@ -308,12 +308,11 @@ 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), +tcg_constant_i32 (0 )); ctx->base.is_jmp =DISAS_NORETURN ; }
@@ -330,12 +329,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)
@@ -377,8 +371,11 @@ 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 ), +tcg_constant_i32 (0 )); 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
Re: [PATCH 20/21] target/ppc: convert raise_exception to raise_excp
Quoted 4 lines · Yonggang Luo
Store
error_codethen callraise_excpwith restore 0. Drop TCGraise_exceptionandraise_exception_err. Move Craise_exception_err_rato static inline ininternal.h, and remove thecpu.hprototype. Callers includeinternal.h.
You are squashing too many distinct changes (this is a general comment for this series). Here for example use gen_exception_err_nip in a preliminary patch.
Quoted 11 lines
Signed-off-by Yonggang Luo <[email protected]>--- target/ppc/cpu.h | 3 --- 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 | 23 ++++++++++------------- 7 files changed, 21 insertions(+), 39 deletions(-)
PATCH 21/21 target/i386: convert raise_exception to i386_raise_exception
In reply to Yonggang LuoPrefix leftover TCG raise_exception to i386_raise_exception. Rename C raise_exception family globals to i386_raise_exception*, and keep the short names as static inline wrappers in helper-tcg.h. Wrappers still call raise_interrupt2.
--- target/i386/helper.h | 2 +- target/i386/tcg/excp_helper.c | 18 +++++++-------- target/i386/tcg/helper-tcg.h | 42 +++++++++++++++++++++++++++++------ target/i386/tcg/translate.c | 2 +- 4 files changed, 46 insertions(+), 18 deletions(-)
target/i386/helper.h +1 -1
@@ -56,7 +56,7 @@ DEF_HELPER_2(syscall, void, env, int) DEF_HELPER_2(sysret, void, env, int) DEF_HELPER_FLAGS_1(pause, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) -DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_2(i386_raise_exception, TCG_CALL_NO_WG, noreturn, env, int) DEF_HELPER_FLAGS_1(icebp, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_3(boundw, void, env, tl, int)DEF_HELPER_3 (boundl, void, env, tl, int)
target/i386/tcg/excp_helper.c +9 -9
@@ -32,9 +32,9 @@ G_NORETURN void helper_raise_interrupt(CPUX86State *env, int intno,raise_interrupt (env, intno, next_eip_addend); } -G_NORETURN void helper_raise_exception(CPUX86State *env, int exception_index) +G_NORETURN void helper_i386_raise_exception(CPUX86State *env, int exception_index) { -raise_exception (env, exception_index); +i386_raise_exception (env, exception_index); }/*
@@ -120,25 +120,25 @@ G_NORETURN void raise_interrupt(CPUX86State *env, int intno, int next_eip_addendraise_interrupt2 (env, intno,1 ,0 , next_eip_addend,0 ); } -G_NORETURN void raise_exception_err(CPUX86State *env, int exception_index, -int error_code) +G_NORETURN void i386_raise_exception_err(CPUX86State *env, int exception_index, +int error_code) {raise_interrupt2 (env, exception_index,0 , error_code,0 ,0 ); } -G_NORETURN void raise_exception_err_ra(CPUX86State *env, int exception_index, -int error_code,uintptr_t retaddr) +G_NORETURN void i386_raise_exception_err_ra(CPUX86State *env, int exception_index, +int error_code,uintptr_t retaddr) {raise_interrupt2 (env, exception_index,0 , error_code,0 , retaddr); } -G_NORETURN void raise_exception(CPUX86State *env, int exception_index) +G_NORETURN void i386_raise_exception(CPUX86State *env, int exception_index) {raise_interrupt2 (env, exception_index,0 ,0 ,0 ,0 ); } -G_NORETURN void raise_exception_ra(CPUX86State *env, int exception_index, -uintptr_t retaddr) +G_NORETURN void i386_raise_exception_ra(CPUX86State *env, int exception_index, +uintptr_t retaddr) {raise_interrupt2 (env, exception_index,0 ,0 ,0 , retaddr); }
target/i386/tcg/helper-tcg.h +35 -7
48 lines not on this page · raw message
target/i386/tcg/translate.c +1 -1
@@ -1506,7 +1506,7 @@ static void gen_exception(DisasContext *s, int trapno) {gen_update_cc_op (s);gen_update_eip_cur (s); -gen_helper_raise_exception (tcg_env,tcg_constant_i32 (trapno)); +gen_helper_i386_raise_exception (tcg_env,tcg_constant_i32 (trapno)); s->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.52.0.windows.1