* [PATCH 1/4] exec: Move TranslationBlock typedef to qemu/typedefs.h
2021-02-08 23:39 [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
@ 2021-02-08 23:39 ` Richard Henderson
2021-02-08 23:39 ` [PATCH 2/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2021-02-08 23:39 UTC (permalink / raw)
To: qemu-devel; +Cc: alex.bennee, cfontana
This also means we don't need an extra declaration of
the structure in hw/core/cpu.h.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/exec/tb-context.h | 1 -
include/hw/core/cpu.h | 4 +---
include/hw/core/tcg-cpu-ops.h | 3 +--
include/qemu/typedefs.h | 1 +
target/arm/internals.h | 3 +--
target/cris/translate.c | 2 +-
target/lm32/translate.c | 2 +-
target/moxie/translate.c | 2 +-
target/unicore32/translate.c | 2 +-
9 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h
index ec4c13b455..cc33979113 100644
--- a/include/exec/tb-context.h
+++ b/include/exec/tb-context.h
@@ -26,7 +26,6 @@
#define CODE_GEN_HTABLE_BITS 15
#define CODE_GEN_HTABLE_SIZE (1 << CODE_GEN_HTABLE_BITS)
-typedef struct TranslationBlock TranslationBlock;
typedef struct TBContext TBContext;
struct TBContext {
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 38d813c389..c005d3dc2d 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -74,8 +74,6 @@ typedef enum MMUAccessType {
typedef struct CPUWatchpoint CPUWatchpoint;
-struct TranslationBlock;
-
/* see tcg-cpu-ops.h */
struct TCGCPUOps;
@@ -375,7 +373,7 @@ struct CPUState {
IcountDecr *icount_decr_ptr;
/* Accessed in parallel; all accesses must be atomic */
- struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
+ TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
struct GDBRegisterState *gdb_regs;
int gdb_num_regs;
diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h
index ccc97d1894..ac3bb051f2 100644
--- a/include/hw/core/tcg-cpu-ops.h
+++ b/include/hw/core/tcg-cpu-ops.h
@@ -30,8 +30,7 @@ struct TCGCPUOps {
* If more state needs to be restored, the target must implement a
* function to restore all the state, and register it here.
*/
- void (*synchronize_from_tb)(CPUState *cpu,
- const struct TranslationBlock *tb);
+ void (*synchronize_from_tb)(CPUState *cpu, const TranslationBlock *tb);
/** @cpu_exec_enter: Callback for cpu_exec preparation */
void (*cpu_exec_enter)(CPUState *cpu);
/** @cpu_exec_exit: Callback for cpu_exec cleanup */
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index dc39b05c30..ee60eb3de4 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -120,6 +120,7 @@ typedef struct ReservedRegion ReservedRegion;
typedef struct SavedIOTLB SavedIOTLB;
typedef struct SHPCDevice SHPCDevice;
typedef struct SSIBus SSIBus;
+typedef struct TranslationBlock TranslationBlock;
typedef struct VirtIODevice VirtIODevice;
typedef struct Visitor Visitor;
typedef struct VMChangeStateEntry VMChangeStateEntry;
diff --git a/target/arm/internals.h b/target/arm/internals.h
index 448982dd2f..7d26ce0c9d 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -172,8 +172,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
void arm_translate_init(void);
#ifdef CONFIG_TCG
-void arm_cpu_synchronize_from_tb(CPUState *cs,
- const struct TranslationBlock *tb);
+void arm_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb);
#endif /* CONFIG_TCG */
diff --git a/target/cris/translate.c b/target/cris/translate.c
index c893f877ab..65c168c0c7 100644
--- a/target/cris/translate.c
+++ b/target/cris/translate.c
@@ -132,7 +132,7 @@ typedef struct DisasContext {
int delayed_branch;
- struct TranslationBlock *tb;
+ TranslationBlock *tb;
int singlestep_enabled;
} DisasContext;
diff --git a/target/lm32/translate.c b/target/lm32/translate.c
index 030b232d66..20c70d03f1 100644
--- a/target/lm32/translate.c
+++ b/target/lm32/translate.c
@@ -93,7 +93,7 @@ typedef struct DisasContext {
unsigned int tb_flags, synced_flags; /* tb dependent flags. */
int is_jmp;
- struct TranslationBlock *tb;
+ TranslationBlock *tb;
int singlestep_enabled;
uint32_t features;
diff --git a/target/moxie/translate.c b/target/moxie/translate.c
index d5fb27dfb8..24a742b25e 100644
--- a/target/moxie/translate.c
+++ b/target/moxie/translate.c
@@ -36,7 +36,7 @@
/* This is the state at translation time. */
typedef struct DisasContext {
- struct TranslationBlock *tb;
+ TranslationBlock *tb;
target_ulong pc, saved_pc;
uint32_t opcode;
uint32_t fp_status;
diff --git a/target/unicore32/translate.c b/target/unicore32/translate.c
index 962f9877a0..370709c9ea 100644
--- a/target/unicore32/translate.c
+++ b/target/unicore32/translate.c
@@ -34,7 +34,7 @@ typedef struct DisasContext {
int condjmp;
/* The label that will be jumped to when the instruction is skipped. */
TCGLabel *condlabel;
- struct TranslationBlock *tb;
+ TranslationBlock *tb;
int singlestep_enabled;
#ifndef CONFIG_USER_ONLY
int user;
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] accel/tcg: Create io_recompile_replay_branch hook
2021-02-08 23:39 [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
2021-02-08 23:39 ` [PATCH 1/4] exec: Move TranslationBlock typedef to qemu/typedefs.h Richard Henderson
@ 2021-02-08 23:39 ` Richard Henderson
2021-02-09 17:05 ` Peter Maydell
2021-02-08 23:39 ` [PATCH 3/4] target/mips: Create mips_io_recompile_replay_branch Richard Henderson
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2021-02-08 23:39 UTC (permalink / raw)
To: qemu-devel; +Cc: alex.bennee, cfontana
Create a hook in which to split out the mips and
sh4 ifdefs from cpu_io_recompile.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/hw/core/tcg-cpu-ops.h | 10 ++++++++++
accel/tcg/translate-all.c | 17 +++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h
index ac3bb051f2..ddf334411f 100644
--- a/include/hw/core/tcg-cpu-ops.h
+++ b/include/hw/core/tcg-cpu-ops.h
@@ -88,6 +88,16 @@ struct TCGCPUOps {
*/
bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
+ /**
+ * @io_recompile_replay_branch: Callback for cpu_io_recompile.
+ *
+ * The cpu has been stoped, and cpu_restore_state_from_tb has been
+ * called. If the faulting instruction is in a delay slot, and the
+ * target architecture requires re-execution of the branch, then
+ * adjust the cpu state as required and return true.
+ */
+ bool (*io_recompile_replay_branch)(CPUState *cpu,
+ const TranslationBlock *tb);
#endif /* CONFIG_SOFTMMU */
#endif /* NEED_CPU_H */
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 81d4c83f22..6eb37883bd 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -60,6 +60,7 @@
#include "sysemu/cpu-timers.h"
#include "sysemu/tcg.h"
#include "qapi/error.h"
+#include "hw/core/tcg-cpu-ops.h"
#include "internal.h"
/* #define DEBUG_TB_INVALIDATE */
@@ -2420,6 +2421,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
CPUArchState *env = cpu->env_ptr;
#endif
TranslationBlock *tb;
+ CPUClass *cc;
uint32_t n;
tb = tcg_tb_lookup(retaddr);
@@ -2429,11 +2431,18 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
}
cpu_restore_state_from_tb(cpu, tb, retaddr, true);
- /* On MIPS and SH, delay slot instructions can only be restarted if
- they were already the first instruction in the TB. If this is not
- the first instruction in a TB then re-execute the preceding
- branch. */
+ /*
+ * Some guests must re-execute the branch when re-executing a delay
+ * slot instruction. When this is the case, adjust icount and N
+ * to account for the re-execution of the branch.
+ */
n = 1;
+ cc = CPU_GET_CLASS(cpu);
+ if (cc->tcg_ops->io_recompile_replay_branch &&
+ cc->tcg_ops->io_recompile_replay_branch(cpu, tb)) {
+ cpu_neg(cpu)->icount_decr.u16.low++;
+ n = 2;
+ }
#if defined(TARGET_MIPS)
if ((env->hflags & MIPS_HFLAG_BMASK) != 0
&& env->active_tc.PC != tb->pc) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] accel/tcg: Create io_recompile_replay_branch hook
2021-02-08 23:39 ` [PATCH 2/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
@ 2021-02-09 17:05 ` Peter Maydell
0 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2021-02-09 17:05 UTC (permalink / raw)
To: Richard Henderson; +Cc: Alex Bennée, QEMU Developers, Claudio Fontana
On Tue, 9 Feb 2021 at 00:29, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Create a hook in which to split out the mips and
> sh4 ifdefs from cpu_io_recompile.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/hw/core/tcg-cpu-ops.h | 10 ++++++++++
> accel/tcg/translate-all.c | 17 +++++++++++++----
> 2 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h
> index ac3bb051f2..ddf334411f 100644
> --- a/include/hw/core/tcg-cpu-ops.h
> +++ b/include/hw/core/tcg-cpu-ops.h
> @@ -88,6 +88,16 @@ struct TCGCPUOps {
> */
> bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
>
> + /**
> + * @io_recompile_replay_branch: Callback for cpu_io_recompile.
> + *
> + * The cpu has been stoped, and cpu_restore_state_from_tb has been
"stopped"
> + * called. If the faulting instruction is in a delay slot, and the
> + * target architecture requires re-execution of the branch, then
> + * adjust the cpu state as required and return true.
> + */
> + bool (*io_recompile_replay_branch)(CPUState *cpu,
> + const TranslationBlock *tb);
> #endif /* CONFIG_SOFTMMU */
thanks
-- PMM
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/4] target/mips: Create mips_io_recompile_replay_branch
2021-02-08 23:39 [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
2021-02-08 23:39 ` [PATCH 1/4] exec: Move TranslationBlock typedef to qemu/typedefs.h Richard Henderson
2021-02-08 23:39 ` [PATCH 2/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
@ 2021-02-08 23:39 ` Richard Henderson
2021-02-08 23:39 ` [PATCH 4/4] target/sh4: Create superh_io_recompile_replay_branch Richard Henderson
2021-02-09 16:51 ` [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Alex Bennée
4 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2021-02-08 23:39 UTC (permalink / raw)
To: qemu-devel
Cc: alex.bennee, cfontana, Aurelien Jarno,
Philippe Mathieu-Daudé
Move the code from accel/tcg/translate-all.c to target/mips/cpu.c.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
accel/tcg/translate-all.c | 12 ++----------
target/mips/cpu.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 6eb37883bd..470657b02a 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2417,7 +2417,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
*/
void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
{
-#if defined(TARGET_MIPS) || defined(TARGET_SH4)
+#if defined(TARGET_SH4)
CPUArchState *env = cpu->env_ptr;
#endif
TranslationBlock *tb;
@@ -2443,15 +2443,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
cpu_neg(cpu)->icount_decr.u16.low++;
n = 2;
}
-#if defined(TARGET_MIPS)
- if ((env->hflags & MIPS_HFLAG_BMASK) != 0
- && env->active_tc.PC != tb->pc) {
- env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4);
- cpu_neg(cpu)->icount_decr.u16.low++;
- env->hflags &= ~MIPS_HFLAG_BMASK;
- n = 2;
- }
-#elif defined(TARGET_SH4)
+#if defined(TARGET_SH4)
if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) != 0
&& env->pc != tb->pc) {
env->pc -= 2;
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index ad163ead62..bf70c77295 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -268,6 +268,23 @@ static void mips_cpu_synchronize_from_tb(CPUState *cs,
env->hflags &= ~MIPS_HFLAG_BMASK;
env->hflags |= tb->flags & MIPS_HFLAG_BMASK;
}
+
+# ifndef CONFIG_USER_ONLY
+static bool mips_io_recompile_replay_branch(CPUState *cs,
+ const TranslationBlock *tb)
+{
+ MIPSCPU *cpu = MIPS_CPU(cs);
+ CPUMIPSState *env = &cpu->env;
+
+ if ((env->hflags & MIPS_HFLAG_BMASK) != 0
+ && env->active_tc.PC != tb->pc) {
+ env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4);
+ env->hflags &= ~MIPS_HFLAG_BMASK;
+ return true;
+ }
+ return false;
+}
+# endif /* !CONFIG_USER_ONLY */
#endif /* CONFIG_TCG */
static bool mips_cpu_has_work(CPUState *cs)
@@ -679,6 +696,7 @@ static struct TCGCPUOps mips_tcg_ops = {
.do_interrupt = mips_cpu_do_interrupt,
.do_transaction_failed = mips_cpu_do_transaction_failed,
.do_unaligned_access = mips_cpu_do_unaligned_access,
+ .io_recompile_replay_branch = mips_io_recompile_replay_branch,
#endif /* !CONFIG_USER_ONLY */
};
#endif /* CONFIG_TCG */
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] target/sh4: Create superh_io_recompile_replay_branch
2021-02-08 23:39 [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
` (2 preceding siblings ...)
2021-02-08 23:39 ` [PATCH 3/4] target/mips: Create mips_io_recompile_replay_branch Richard Henderson
@ 2021-02-08 23:39 ` Richard Henderson
2021-02-09 16:51 ` [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Alex Bennée
4 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2021-02-08 23:39 UTC (permalink / raw)
To: qemu-devel; +Cc: alex.bennee, cfontana, Yoshinori Sato
Move the code from accel/tcg/translate-all.c to target/sh4/cpu.c.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
---
accel/tcg/translate-all.c | 12 ------------
target/sh4/cpu.c | 18 ++++++++++++++++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 470657b02a..b8ad95aa1b 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2417,9 +2417,6 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
*/
void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
{
-#if defined(TARGET_SH4)
- CPUArchState *env = cpu->env_ptr;
-#endif
TranslationBlock *tb;
CPUClass *cc;
uint32_t n;
@@ -2443,15 +2440,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
cpu_neg(cpu)->icount_decr.u16.low++;
n = 2;
}
-#if defined(TARGET_SH4)
- if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) != 0
- && env->pc != tb->pc) {
- env->pc -= 2;
- cpu_neg(cpu)->icount_decr.u16.low++;
- env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL);
- n = 2;
- }
-#endif
/* Generate a new TB executing the I/O insn. */
cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | n;
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index a78d283bc8..ac65c88f1f 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -43,6 +43,23 @@ static void superh_cpu_synchronize_from_tb(CPUState *cs,
cpu->env.flags = tb->flags & TB_FLAG_ENVFLAGS_MASK;
}
+#ifndef CONFIG_USER_ONLY
+static bool superh_io_recompile_replay_branch(CPUState *cs,
+ const TranslationBlock *tb)
+{
+ SuperHCPU *cpu = SUPERH_CPU(cs);
+ CPUSH4State *env = &cpu->env;
+
+ if ((env->flags & ((DELAY_SLOT | DELAY_SLOT_CONDITIONAL))) != 0
+ && env->pc != tb->pc) {
+ env->pc -= 2;
+ env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL);
+ return true;
+ }
+ return false;
+}
+#endif
+
static bool superh_cpu_has_work(CPUState *cs)
{
return cs->interrupt_request & CPU_INTERRUPT_HARD;
@@ -217,6 +234,7 @@ static struct TCGCPUOps superh_tcg_ops = {
#ifndef CONFIG_USER_ONLY
.do_interrupt = superh_cpu_do_interrupt,
.do_unaligned_access = superh_cpu_do_unaligned_access,
+ .io_recompile_replay_branch = superh_io_recompile_replay_branch,
#endif /* !CONFIG_USER_ONLY */
};
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook
2021-02-08 23:39 [PATCH 0/4] accel/tcg: Create io_recompile_replay_branch hook Richard Henderson
` (3 preceding siblings ...)
2021-02-08 23:39 ` [PATCH 4/4] target/sh4: Create superh_io_recompile_replay_branch Richard Henderson
@ 2021-02-09 16:51 ` Alex Bennée
4 siblings, 0 replies; 7+ messages in thread
From: Alex Bennée @ 2021-02-09 16:51 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel, cfontana
Richard Henderson <richard.henderson@linaro.org> writes:
> I noticed this today while Alex and I were discussing cpu_io_recompile.
> This cleanup seems much easier now that Claudio has split out TCGCPUOps.
>
> I see that mips has a ReplayKernel test, but sh4 does not, so this
> probably has non-zero testing.
All looks good to me so have a:
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
for the series. I'm going to re-post with the patches I've added to make
one nice clean-up patch ;-)
>
>
> r~
>
>
> Richard Henderson (4):
> exec: Move TranslationBlock typedef to qemu/typedefs.h
> accel/tcg: Create io_recompile_replay_branch hook
> target/mips: Create mips_io_recompile_replay_branch
> target/sh4: Create superh_io_recompile_replay_branch
>
> include/exec/tb-context.h | 1 -
> include/hw/core/cpu.h | 4 +---
> include/hw/core/tcg-cpu-ops.h | 13 +++++++++++--
> include/qemu/typedefs.h | 1 +
> target/arm/internals.h | 3 +--
> accel/tcg/translate-all.c | 31 ++++++++++---------------------
> target/cris/translate.c | 2 +-
> target/lm32/translate.c | 2 +-
> target/mips/cpu.c | 18 ++++++++++++++++++
> target/moxie/translate.c | 2 +-
> target/sh4/cpu.c | 18 ++++++++++++++++++
> target/unicore32/translate.c | 2 +-
> 12 files changed, 64 insertions(+), 33 deletions(-)
--
Alex Bennée
^ permalink raw reply [flat|nested] 7+ messages in thread