accel/tcg: Introduce translator_use_goto_tb
v3 cover accel/tcg: Introduce translator_use_goto_tb
There are a number of inconsistencies with goto_tb usage, and I plan to make changes in order to better support breakpoints.
(1) Testing CF_LAST_IO is a hold-over from since before ba3e7926691 ("icount: clean up cpu_can_io at the entry to the block"). Several targets still have this test.
(2) Testing singlestep is superfluous, as it doesn't mean anything besides limiting max_insns to 1.
(3) Not testing page crossing for CONFIG_USER_ONLY is wrong, because mmap and mprotect can change page permissions. It's a very uncommon case wrt executables, but it's still wrong.
(4) Not testing page crossing for non-mmu targets (where page permissions literally cannot change) is not currently wrong, but will be after the breakpoint changes.
(5) When the TB does cross two pages, considering non-page crossing from the second page is not currently wrong, but will be after the breakpoint changes.
Changes for v3:
* Adjust aarch32 ISB, SB change to simply set is_jmp.
Changes for v2:
* Fix aarch32 ISB, SB insns vs single-stepping.
* Drop use_goto_tb for aarch32
* Retain use_goto_tb for aarch64.
Patches lacking review:
05-target-arm-Use-DISAS_TOO_MANY-for-ISB-and-SB.patch
r~
Richard Henderson (28):
accel/tcg: Introduce translator_use_goto_tb target/alpha: Remove use_exit_tb target/alpha: Remove in_superpage target/alpha: Use translator_use_goto_tb target/arm: Use DISAS_TOO_MANY for ISB and SB target/arm: Use translator_use_goto_tb for aarch64 target/arm: Use translator_use_goto_tb for aarch32 target/avr: Use translator_use_goto_tb target/avr: Mark some helpers noreturn target/cris: Use translator_use_goto_tb target/hppa: Use translator_use_goto_tb target/i386: Use translator_use_goto_tb target/m68k: Use translator_use_goto_tb target/microblaze: Use translator_use_goto_tb target/mips: Use translator_use_goto_tb target/mips: Fix missing else in gen_goto_tb target/nios2: Use translator_use_goto_tb target/openrisc: Use translator_use_goto_tb target/ppc: Use translator_use_goto_tb target/riscv: Use translator_use_goto_tb target/rx: Use translator_use_goto_tb target/s390x: Use translator_use_goto_tb target/s390x: Remove use_exit_tb target/sh4: Use translator_use_goto_tb target/sparc: Use translator_use_goto_tb target/tricore: Use translator_use_goto_tb target/tricore: Use tcg_gen_lookup_and_goto_ptr target/xtensa: Use translator_use_goto_tb
include/exec/translator.h | 10 ++++++++ target/avr/helper.h | 8 +++--- accel/tcg/translator.c | 11 +++++++++ target/alpha/translate.c | 46 ++++------------------------------- target/arm/translate-a64.c | 25 ++++--------------- target/arm/translate.c | 16 +++--------- target/avr/translate.c | 9 ++++--- target/cris/translate.c | 5 ++-- target/hppa/translate.c | 5 +--- target/i386/tcg/translate.c | 14 ++--------- target/m68k/translate.c | 12 +-------- target/microblaze/translate.c | 11 +-------- target/mips/tcg/translate.c | 20 +++------------ target/nios2/translate.c | 15 +----------- target/openrisc/translate.c | 15 ++++++------ target/ppc/translate.c | 10 +------- target/riscv/translate.c | 20 +-------------- target/rx/translate.c | 11 +-------- target/s390x/translate.c | 18 +++----------- target/sh4/translate.c | 11 +++------ target/sparc/translate.c | 19 ++++----------- target/tricore/translate.c | 20 +++------------ target/xtensa/translate.c | 6 +---- 23 files changed, 83 insertions(+), 254 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/28 accel/tcg: Introduce translator_use_goto_tb
Add a generic version of the common use_goto_tb test.
Various targets avoid the page crossing test for CONFIG_USER_ONLY, but that is wrong: mmap and mprotect can change page permissions.
--- include/exec/translator.h | 10 ++++++++++ accel/tcg/translator.c | 11 +++++++++++ 2 files changed, 21 insertions(+)
include/exec/translator.h +10 -0
@@ -145,6 +145,16 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,void translator_loop_temp_check (DisasContextBase *db); +/** +* translator_use_goto_tb +* @db: Disassembly context +* @dest: target pc of the goto +* +* Return true if goto_tb is allowed between the current TB +* and the destination PC. +*/ +bool translator_use_goto_tb (DisasContextBase *db,target_ulong dest); +/* * Translator Load Functions *
accel/tcg/translator.c +11 -0
@@ -31,6 +31,17 @@ void translator_loop_temp_check(DisasContextBase *db) } } +bool translator_use_goto_tb (DisasContextBase *db,target_ulong dest) +{ +/* Suppress goto_tb in the case of single-steping. */ +if (db->singlestep_enabled || singlestep) { +return false; + } + +/* Check for the dest on the same page as the start of the TB. */ +return ((db->pc_first ^ dest) &TARGET_PAGE_MASK ) ==0 ; +} +void translator_loop (const TranslatorOps *ops,DisasContextBase *db,CPUState *cpu,TranslationBlock *tb,int max_insns) {
Signature · 1 line
2.25.1
PATCH v3 2/28 target/alpha: Remove use_exit_tb
In reply to Richard HendersonWe have not needed to end a TB for I/O since ba3e7926691 ("icount: clean up cpu_can_io at the entry to the block"). We do not need to use exit_tb for singlestep, which only means generate one insn per TB.
Which leaves only singlestep_enabled, which means raise a debug trap after every TB, which does not use exit_tb, which would leave the function mis-named.
--- target/alpha/translate.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
target/alpha/translate.c +2 -13
@@ -450,19 +450,8 @@ static bool in_superpage(DisasContext *ctx, int64_t addr)#endif } -static bool use_exit_tb (DisasContext *ctx) -{ -return ((tb_cflags (ctx->base.tb) &CF_LAST_IO ) - || ctx->base.singlestep_enabled - || singlestep); -} -static bool use_goto_tb (DisasContext *ctx,uint64_t dest) { -/* Suppress goto_tb in the case of single-steping and IO. */ -if (unlikely (use_exit_tb (ctx))) { -return false; - }#ifndef CONFIG_USER_ONLY /* If the destination is in the superpage, the page perms can't change. */ if (in_superpage (ctx, dest)) {
@@ -1271,7 +1260,7 @@ static DisasJumpType gen_call_pal(DisasContext *ctx, int palcode)need the page permissions check. We'll see the existence of the page when we create the TB, and we'll flush all TBs if we change the PAL base register. */ -if (!use_exit_tb (ctx)) { +if (!ctx->base.singlestep_enabled) {tcg_gen_goto_tb (0 );tcg_gen_movi_i64 (cpu_pc, entry);tcg_gen_exit_tb (ctx->base.tb,0 );
@@ -3095,7 +3084,7 @@ static void alpha_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)tcg_gen_movi_i64 (cpu_pc, ctx->base.pc_next);/* FALLTHRU */ case DISAS_PC_UPDATED : -if (!use_exit_tb (ctx)) { +if (!ctx->base.singlestep_enabled) {tcg_gen_lookup_and_goto_ptr ();break ; }
Signature · 1 line
2.25.1
PATCH v3 3/28 target/alpha: Remove in_superpage
In reply to Richard HendersonThe number of links across (normal) pages using this is low, and it will shortly violate the contract for breakpoints.
--- target/alpha/translate.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
target/alpha/translate.c +2 -22
@@ -439,24 +439,9 @@ static DisasJumpType gen_store_conditional(DisasContext *ctx, int ra, int rb,return DISAS_NEXT ; } -static bool in_superpage (DisasContext *ctx,int64_t addr) -{ -#ifndef CONFIG_USER_ONLY -return ((ctx->tbflags &ENV_FLAG_PS_USER ) ==0 - && addr >>TARGET_VIRT_ADDR_SPACE_BITS ==-1 - && ((addr >>41 ) &3 ) ==2 ); -#else -return false; -#endif -} -static bool use_goto_tb (DisasContext *ctx,uint64_t dest) {#ifndef CONFIG_USER_ONLY -/* If the destination is in the superpage, the page perms can't change. */ -if (in_superpage (ctx, dest)) { -return true; - }/* Check for the dest on the same page as the start of the TB. */ return ((ctx->base.tb->pc ^ dest) &TARGET_PAGE_MASK ) ==0 ;#else
@@ -2991,7 +2976,7 @@ static void alpha_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPUAlphaState *env = cpu->env_ptr; -int64_t bound, mask; +int64_t bound; ctx->tbflags = ctx->base.tb->flags; ctx->mem_idx =cpu_mmu_index (env, false);
@@ -3020,12 +3005,7 @@ static void alpha_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) ctx->lit =NULL ;/* Bound the number of insns to execute to those left on the page. */ -if (in_superpage (ctx, ctx->base.pc_first)) { - mask =-1ULL <<41 ; - }else { - mask =TARGET_PAGE_MASK ; - } - bound = -(ctx->base.pc_first | mask) /4 ; + bound = -(ctx->base.pc_first |TARGET_PAGE_MASK ) /4 ; ctx->base.max_insns =MIN (ctx->base.max_insns, bound); }
Signature · 1 line
2.25.1
PATCH v3 4/28 target/alpha: Use translator_use_goto_tb
In reply to Richard Henderson--- target/alpha/translate.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
target/alpha/translate.c +1 -6
@@ -441,12 +441,7 @@ static DisasJumpType gen_store_conditional(DisasContext *ctx, int ra, int rb,static bool use_goto_tb (DisasContext *ctx,uint64_t dest) { -#ifndef CONFIG_USER_ONLY -/* Check for the dest on the same page as the start of the TB. */ -return ((ctx->base.tb->pc ^ dest) &TARGET_PAGE_MASK ) ==0 ; -#else -return true; -#endif +return translator_use_goto_tb (&ctx->base, dest); }static DisasJumpType gen_bdirect (DisasContext *ctx,int ra,int32_t disp)
Signature · 1 line
2.25.1
PATCH v3 5/28 target/arm: Use DISAS_TOO_MANY for ISB and SB
In reply to Richard HendersonUsing gen_goto_tb directly misses the single-step check. Let the branch or debug exception be emitted by arm_tr_tb_stop.
--- target/arm/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate.c +2 -2
@@ -8905,7 +8905,7 @@ static bool trans_ISB(DisasContext *s, arg_ISB *a)* self-modifying code correctly and also to take * any pending interrupts immediately. */ -gen_goto_tb (s,0 , s->base.pc_next); + s->base.is_jmp =DISAS_TOO_MANY ;return true; }
@@ -8919,7 +8919,7 @@ static bool trans_SB(DisasContext *s, arg_SB *a)* for TCG; MB and end the TB instead. */ tcg_gen_mb (TCG_MO_ALL |TCG_BAR_SC ); -gen_goto_tb (s,0 , s->base.pc_next); + s->base.is_jmp =DISAS_TOO_MANY ;return true; }
Signature · 1 line
2.25.1
PATCH v3 6/28 target/arm: Use translator_use_goto_tb for aarch64
In reply to Richard HendersonWe have not needed to end a TB for I/O since ba3e7926691 ("icount: clean up cpu_can_io at the entry to the block"), and gdbstub singlestep is handled by the generic function.
Drop the unused 'n' argument to use_goto_tb.
--- target/arm/translate-a64.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
target/arm/translate-a64.c +5 -20
@@ -386,35 +386,20 @@ static void gen_step_complete_exception(DisasContext *s) s->base.is_jmp =DISAS_NORETURN ; } -static inline bool use_goto_tb (DisasContext *s,int n,uint64_t dest) +static inline bool use_goto_tb (DisasContext *s,uint64_t dest) { -/* No direct tb linking with singlestep (either QEMU's or the ARM -* debug architecture kind) or deterministic io -*/ -if (s->base.singlestep_enabled || s->ss_active || - (tb_cflags (s->base.tb) &CF_LAST_IO )) { +if (s->ss_active) {return false; } - -#ifndef CONFIG_USER_ONLY -/* Only link tbs from inside the same guest page */ -if ((s->base.tb->pc &TARGET_PAGE_MASK ) != (dest &TARGET_PAGE_MASK )) { -return false; - } -#endif - -return true; +return translator_use_goto_tb (&s->base, dest); }static inline void gen_goto_tb (DisasContext *s,int n,uint64_t dest) { -const TranslationBlock *tb; - - tb = s->base.tb; -if (use_goto_tb (s, n, dest)) { +if (use_goto_tb (s, dest)) {tcg_gen_goto_tb (n);gen_a64_set_pc_im (dest); -tcg_gen_exit_tb (tb, n); +tcg_gen_exit_tb (s->base.tb, n); s->base.is_jmp =DISAS_NORETURN ; }else {gen_a64_set_pc_im (dest);
Signature · 1 line
2.25.1
PATCH v3 7/28 target/arm: Use translator_use_goto_tb for aarch32
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/arm/translate.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
target/arm/translate.c +1 -11
@@ -2579,16 +2579,6 @@ static int disas_dsp_insn(DisasContext *s, uint32_t insn)return 1 ; } -static inline bool use_goto_tb (DisasContext *s,target_ulong dest) -{ -#ifndef CONFIG_USER_ONLY -return (s->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ) || - ((s->base.pc_next -1 ) &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -static void gen_goto_ptr (void ) {tcg_gen_lookup_and_goto_ptr ();
@@ -2600,7 +2590,7 @@ static void gen_goto_ptr(void)*/ static void gen_goto_tb (DisasContext *s,int n,target_ulong dest) { -if (use_goto_tb (s, dest)) { +if (translator_use_goto_tb (&s->base, dest)) {tcg_gen_goto_tb (n);gen_set_pc_im (s, dest);tcg_gen_exit_tb (s->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 8/28 target/avr: Use translator_use_goto_tb
In reply to Richard HendersonSingle stepping is not the only reason not to use goto_tb. If goto_tb is disallowed, and single-stepping is not enabled, then use tcg_gen_lookup_and_goto_tb to indirectly chain.
--- target/avr/translate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target/avr/translate.c +6 -3
@@ -1083,14 +1083,17 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) {const TranslationBlock *tb = ctx->base.tb; -if (!ctx->base.singlestep_enabled) { +if (translator_use_goto_tb (&ctx->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_i32 (cpu_pc, dest);tcg_gen_exit_tb (tb, n); }else {tcg_gen_movi_i32 (cpu_pc, dest); -gen_helper_debug (cpu_env); -tcg_gen_exit_tb (NULL ,0 ); +if (ctx->base.singlestep_enabled) { +gen_helper_debug (cpu_env); + }else { +tcg_gen_lookup_and_goto_ptr (); + } } ctx->base.is_jmp =DISAS_NORETURN ; }
Signature · 1 line
2.25.1
PATCH v3 9/28 target/avr: Mark some helpers noreturn
In reply to Richard HendersonAll of these helpers end with cpu_loop_exit.
--- target/avr/helper.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/avr/helper.h +4 -4
@@ -19,10 +19,10 @@*/ DEF_HELPER_1(wdr, void, env) -DEF_HELPER_1(debug, void, env) -DEF_HELPER_1(break, void, env) -DEF_HELPER_1(sleep, void, env) -DEF_HELPER_1(unsupported, 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(outb, void, env, i32, i32) DEF_HELPER_2(inb, tl, env, i32)DEF_HELPER_3 (fullwr, void, env, i32, i32)
Signature · 1 line
2.25.1
PATCH v3 10/28 target/cris: Use translator_use_goto_tb
In reply to Richard HendersonThe test for singlestepping is done in translator_use_goto_tb, so we may elide it from cris_tr_tb_stop.
--- target/cris/translate.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
target/cris/translate.c +2 -3
@@ -482,7 +482,7 @@ static void t_gen_swapr(TCGv d, TCGv s)static bool use_goto_tb (DisasContext *dc,target_ulong dest) { -return ((dest ^ dc->base.pc_first) &TARGET_PAGE_MASK ) ==0 ; +return translator_use_goto_tb (&dc->base, dest); }static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest)
@@ -3235,8 +3235,7 @@ static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)* Use a conditional branch if either taken or not-taken path * can use goto_tb. If neither can, then treat it as indirect. */ -if (likely (!dc->base.singlestep_enabled) - &&likely (!dc->cpustate_changed) +if (likely (!dc->cpustate_changed) && (use_goto_tb (dc, dc->jmp_pc) ||use_goto_tb (dc, npc))) {TCGLabel *not_taken =gen_new_label ();
Signature · 1 line
2.25.1
PATCH v3 11/28 target/hppa: Use translator_use_goto_tb
In reply to Richard Henderson--- target/hppa/translate.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
target/hppa/translate.c +1 -4
@@ -817,10 +817,7 @@ static bool gen_illegal(DisasContext *ctx)static bool use_goto_tb (DisasContext *ctx,target_ureg dest) { -/* Suppress goto_tb for page crossing, IO, or single-steping. */ -return !(((ctx->base.pc_first ^ dest) &TARGET_PAGE_MASK ) - || (tb_cflags (ctx->base.tb) &CF_LAST_IO ) - || ctx->base.singlestep_enabled); +return translator_use_goto_tb (&ctx->base, dest); }/* If the next insn is to be nullified, and it's on the same page,
Signature · 1 line
2.25.1
PATCH v3 12/28 target/i386: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/i386/tcg/translate.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
target/i386/tcg/translate.c +2 -12
@@ -2314,21 +2314,11 @@ static inline int insn_const_size(MemOp ot) } } -static inline bool use_goto_tb (DisasContext *s,target_ulong pc) -{ -#ifndef CONFIG_USER_ONLY -return (pc &TARGET_PAGE_MASK ) == (s->base.tb->pc &TARGET_PAGE_MASK ) || - (pc &TARGET_PAGE_MASK ) == (s->pc_start &TARGET_PAGE_MASK ); -#else -return true; -#endif -} - -static inline void gen_goto_tb (DisasContext *s,int tb_num,target_ulong eip) +static void gen_goto_tb (DisasContext *s,int tb_num,target_ulong eip) {target_ulong pc = s->cs_base + eip; -if (use_goto_tb (s, pc)) { +if (translator_use_goto_tb (&s->base, pc)) {/* jump to same page: we can use a direct jump */ tcg_gen_goto_tb (tb_num);gen_jmp_im (s, eip);
Signature · 1 line
2.25.1
PATCH v3 13/28 target/m68k: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/m68k/translate.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
target/m68k/translate.c +1 -11
@@ -1520,16 +1520,6 @@ static void gen_exit_tb(DisasContext *s) } \ }while (0 ) -static inline bool use_goto_tb(DisasContext *s, uint32_t dest) -{ -#ifndef CONFIG_USER_ONLY -return (s->base.pc_first &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ) - || (s->base.pc_next &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -/* Generate a jump to an immediate address. */ static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest) {
@@ -1537,7 +1527,7 @@ static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)update_cc_op (s);tcg_gen_movi_i32 (QREG_PC , dest);gen_singlestep_exception (s); - }else if (use_goto_tb (s, dest)) { + }else if (translator_use_goto_tb (&s->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_i32 (QREG_PC , dest);tcg_gen_exit_tb (s->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 14/28 target/microblaze: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/microblaze/translate.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
target/microblaze/translate.c +1 -10
@@ -125,15 +125,6 @@ static void gen_raise_hw_excp(DisasContext *dc, uint32_t esr_ec)gen_raise_exception_sync (dc,EXCP_HW_EXCP ); } -static inline bool use_goto_tb (DisasContext *dc,target_ulong dest) -{ -#ifndef CONFIG_USER_ONLY -return (dc->base.pc_first &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) {if (dc->base.singlestep_enabled) {
@@ -141,7 +132,7 @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest)tcg_gen_movi_i32 (cpu_pc, dest);gen_helper_raise_exception (cpu_env, tmp);tcg_temp_free_i32 (tmp); - }else if (use_goto_tb (dc, dest)) { + }else if (translator_use_goto_tb (&dc->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_i32 (cpu_pc, dest);tcg_gen_exit_tb (dc->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 15/28 target/mips: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/mips/tcg/translate.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
target/mips/tcg/translate.c +2 -15
@@ -4948,22 +4948,9 @@ static void gen_trap(DisasContext *ctx, uint32_t opc,tcg_temp_free (t1); } -static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest) +static void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest) { -if (unlikely (ctx->base.singlestep_enabled)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (ctx->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} - -static inline void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest) -{ -if (use_goto_tb (ctx, dest)) { +if (translator_use_goto_tb (&ctx->base, dest)) {tcg_gen_goto_tb (n);gen_save_pc (dest);tcg_gen_exit_tb (ctx->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 16/28 target/mips: Fix missing else in gen_goto_tb
In reply to Richard HendersonDo not emit dead code for the singlestep_enabled case, after having exited the TB with a debug exception.
--- target/mips/tcg/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/mips/tcg/translate.c +2 -1
@@ -4959,8 +4959,9 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)if (ctx->base.singlestep_enabled) {save_cpu_state (ctx,0 );gen_helper_raise_exception_debug (cpu_env); + }else { +tcg_gen_lookup_and_goto_ptr (); } -tcg_gen_lookup_and_goto_ptr (); } }
Signature · 1 line
2.25.1
PATCH v3 17/28 target/nios2: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/nios2/translate.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
target/nios2/translate.c +1 -14
@@ -150,24 +150,11 @@ static void t_gen_helper_raise_exception(DisasContext *dc, dc->base.is_jmp =DISAS_NORETURN ; } -static bool use_goto_tb (DisasContext *dc,uint32_t dest) -{ -if (unlikely (dc->base.singlestep_enabled)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (dc->base.pc_first &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -static void gen_goto_tb (DisasContext *dc,int n,uint32_t dest) {const TranslationBlock *tb = dc->base.tb; -if (use_goto_tb (dc, dest)) { +if (translator_use_goto_tb (&dc->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_tl (cpu_R[R_PC ], dest);tcg_gen_exit_tb (tb, n);
Signature · 1 line
2.25.1
PATCH v3 18/28 target/openrisc: Use translator_use_goto_tb
In reply to Richard HendersonReorder the control statements to allow using the page boundary check from translator_use_goto_tb().
--- target/openrisc/translate.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
target/openrisc/translate.c +8 -7
@@ -1720,16 +1720,17 @@ static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)/* fallthru */ case DISAS_TOO_MANY : -if (unlikely (dc->base.singlestep_enabled)) { -tcg_gen_movi_tl (cpu_pc, jmp_dest); -gen_exception (dc,EXCP_DEBUG ); - }else if ((dc->base.pc_first ^ jmp_dest) &TARGET_PAGE_MASK ) { -tcg_gen_movi_tl (cpu_pc, jmp_dest); -tcg_gen_lookup_and_goto_ptr (); - }else { +if (translator_use_goto_tb (&dc->base, jmp_dest)) {tcg_gen_goto_tb (0 );tcg_gen_movi_tl (cpu_pc, jmp_dest);tcg_gen_exit_tb (dc->base.tb,0 ); +break ; + } +tcg_gen_movi_tl (cpu_pc, jmp_dest); +if (unlikely (dc->base.singlestep_enabled)) { +gen_exception (dc,EXCP_DEBUG ); + }else { +tcg_gen_lookup_and_goto_ptr (); }break ;
Signature · 1 line
2.25.1
PATCH v3 19/28 target/ppc: Use translator_use_goto_tb
In reply to Richard Henderson--- target/ppc/translate.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
target/ppc/translate.c +1 -9
@@ -4302,15 +4302,7 @@ static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest) { -if (unlikely (ctx->singlestep_enabled)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (ctx->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif +return translator_use_goto_tb (&ctx->base, dest); }static void gen_lookup_and_goto_ptr (DisasContext *ctx)
Signature · 1 line
2.25.1
PATCH v3 20/28 target/riscv: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/riscv/translate.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
target/riscv/translate.c +1 -19
@@ -168,29 +168,11 @@ static void gen_exception_inst_addr_mis(DisasContext *ctx)generate_exception_mtval (ctx,RISCV_EXCP_INST_ADDR_MIS ); } -static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest) -{ -if (unlikely (ctx->base.singlestep_enabled)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (ctx->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -static void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest) { -if (use_goto_tb (ctx, dest)) { -/* chaining is only allowed when the jump is to the same page */ +if (translator_use_goto_tb (&ctx->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_tl (cpu_pc, dest); - -/* No need to check for single stepping here as use_goto_tb() will -* return false in case of single stepping. -*/ tcg_gen_exit_tb (ctx->base.tb, n); }else {tcg_gen_movi_tl (cpu_pc, dest);
Signature · 1 line
2.25.1
PATCH v3 21/28 target/rx: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/rx/translate.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
target/rx/translate.c +1 -10
@@ -143,18 +143,9 @@ void rx_cpu_dump_state(CPUState *cs, FILE *f, int flags) } } -static bool use_goto_tb (DisasContext *dc,target_ulong dest) -{ -if (unlikely (dc->base.singlestep_enabled)) { -return false; - }else { -return true; - } -} -static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) { -if (use_goto_tb (dc, dest)) { +if (translator_use_goto_tb (&dc->base, dest)) {tcg_gen_goto_tb (n);tcg_gen_movi_i32 (cpu_pc, dest);tcg_gen_exit_tb (dc->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 22/28 target/s390x: Use translator_use_goto_tb
In reply to Richard Henderson--- target/s390x/translate.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
target/s390x/translate.c +1 -6
@@ -697,12 +697,7 @@ static bool use_goto_tb(DisasContext *s, uint64_t dest)if (unlikely (use_exit_tb (s))) {return false; } -#ifndef CONFIG_USER_ONLY -return (dest &TARGET_PAGE_MASK ) == (s->base.tb->pc &TARGET_PAGE_MASK ) || - (dest &TARGET_PAGE_MASK ) == (s->base.pc_next &TARGET_PAGE_MASK ); -#else -return true; -#endif +return translator_use_goto_tb (&s->base, dest); }static void account_noninline_branch (DisasContext *s,int cc_op)
Signature · 1 line
2.25.1
PATCH v3 23/28 target/s390x: Remove use_exit_tb
In reply to Richard HendersonWe have not needed to end a TB for I/O since ba3e7926691 ("icount: clean up cpu_can_io at the entry to the block").
In use_goto_tb, the check for singlestep_enabled is in the generic translator_use_goto_tb. In s390x_tr_tb_stop, the check for singlestep_enabled is in the preceding do_debug test.
Which leaves only FLAG_MASK_PER: fold that test alone into the two callers of use_exit tb.
--- target/s390x/translate.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
target/s390x/translate.c +2 -9
@@ -685,16 +685,9 @@ static void gen_op_calc_cc(DisasContext *s)set_cc_static (s); } -static bool use_exit_tb (DisasContext *s) -{ -return s->base.singlestep_enabled || - (tb_cflags (s->base.tb) &CF_LAST_IO ) || - (s->base.tb->flags &FLAG_MASK_PER ); -} -static bool use_goto_tb (DisasContext *s,uint64_t dest) { -if (unlikely (use_exit_tb (s))) { +if (unlikely (s->base.tb->flags &FLAG_MASK_PER )) {return false; }return translator_use_goto_tb (&s->base, dest);
@@ -6634,7 +6627,7 @@ static void s390x_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)/* Exit the TB, either by raising a debug exception or by return. */ if (dc->do_debug) {gen_exception (EXCP_DEBUG ); - }else if (use_exit_tb (dc) || + }else if ((dc->base.tb->flags &FLAG_MASK_PER ) || dc->base.is_jmp ==DISAS_PC_STALE_NOCHAIN ) {tcg_gen_exit_tb (NULL ,0 ); }else {
Signature · 1 line
2.25.1
PATCH v3 24/28 target/sh4: Use translator_use_goto_tb
In reply to Richard Henderson--- target/sh4/translate.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
target/sh4/translate.c +3 -8
@@ -225,17 +225,12 @@ static inline bool use_exit_tb(DisasContext *ctx)return (ctx->tbflags &GUSA_EXCLUSIVE ) !=0 ; } -static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest) +static bool use_goto_tb (DisasContext *ctx,target_ulong dest) { -/* Use a direct jump if in same page and singlestep not enabled */ -if (unlikely (ctx->base.singlestep_enabled ||use_exit_tb (ctx))) { +if (use_exit_tb (ctx)) {return false; } -#ifndef CONFIG_USER_ONLY -return (ctx->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif +return translator_use_goto_tb (&ctx->base, dest); }static void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest)
Signature · 1 line
2.25.1
PATCH v3 25/28 target/sparc: Use translator_use_goto_tb
In reply to Richard Henderson--- target/sparc/translate.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
target/sparc/translate.c +5 -14
@@ -339,23 +339,14 @@ static inline TCGv gen_dest_gpr(DisasContext *dc, int reg) } } -static inline bool use_goto_tb (DisasContext *s,target_ulong pc, -target_ulong npc) +static bool use_goto_tb (DisasContext *s,target_ulong pc,target_ulong npc) { -if (unlikely (s->base.singlestep_enabled || singlestep)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (pc &TARGET_PAGE_MASK ) == (s->base.tb->pc &TARGET_PAGE_MASK ) && - (npc &TARGET_PAGE_MASK ) == (s->base.tb->pc &TARGET_PAGE_MASK ); -#else -return true; -#endif +return translator_use_goto_tb (&s->base, pc) && +translator_use_goto_tb (&s->base, npc); } -static inline void gen_goto_tb (DisasContext *s,int tb_num, -target_ulong pc,target_ulong npc) +static void gen_goto_tb (DisasContext *s,int tb_num, +target_ulong pc,target_ulong npc) {if (use_goto_tb (s, pc, npc)) {/* jump to same page: we can use a direct jump */
Signature · 1 line
2.25.1
PATCH v3 26/28 target/tricore: Use translator_use_goto_tb
In reply to Richard HendersonJust use translator_use_goto_tb directly at the one call site, rather than maintaining a local wrapper.
--- target/tricore/translate.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
target/tricore/translate.c +2 -15
@@ -3225,19 +3225,6 @@ static inline void gen_save_pc(target_ulong pc)tcg_gen_movi_tl (cpu_PC, pc); } -static inline bool use_goto_tb (DisasContext *ctx,target_ulong dest) -{ -if (unlikely (ctx->base.singlestep_enabled)) { -return false; - } - -#ifndef CONFIG_USER_ONLY -return (ctx->base.tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ); -#else -return true; -#endif -} -static void generate_qemu_excp (DisasContext *ctx,int excp) {TCGv_i32 tmp =tcg_const_i32 (excp);
@@ -3246,9 +3233,9 @@ static void generate_qemu_excp(DisasContext *ctx, int excp)tcg_temp_free (tmp); } -static inline void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest) +static void gen_goto_tb (DisasContext *ctx,int n,target_ulong dest) { -if (use_goto_tb (ctx, dest)) { +if (translator_use_goto_tb (&ctx->base, dest)) {tcg_gen_goto_tb (n);gen_save_pc (dest);tcg_gen_exit_tb (ctx->base.tb, n);
Signature · 1 line
2.25.1
PATCH v3 27/28 target/tricore: Use tcg_gen_lookup_and_goto_ptr
In reply to Richard HendersonThe non-single-step case of gen_goto_tb may usetcg_gen_lookup_and_goto_ptr to indirectly chain.
--- target/tricore/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/tricore/translate.c +2 -1
@@ -3243,8 +3243,9 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)gen_save_pc (dest);if (ctx->base.singlestep_enabled) {generate_qemu_excp (ctx,EXCP_DEBUG ); + }else { +tcg_gen_lookup_and_goto_ptr (); } -tcg_gen_exit_tb (NULL ,0 ); } }
Signature · 1 line
2.25.1
PATCH v3 28/28 target/xtensa: Use translator_use_goto_tb
In reply to Richard Henderson--- target/xtensa/translate.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/xtensa/translate.c +1 -5
@@ -406,11 +406,7 @@ static void gen_jump(DisasContext *dc, TCGv dest)static int adjust_jump_slot (DisasContext *dc,uint32_t dest,int slot) { -if (((dc->base.pc_first ^ dest) &TARGET_PAGE_MASK ) !=0 ) { -return -1 ; - }else { -return slot; - } +return translator_use_goto_tb (&dc->base, dest) ? slot :-1 ; }static void gen_jumpi (DisasContext *dc,uint32_t dest,int slot)
Signature · 1 line
2.25.1