[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/6] cpu-exec: wrap tcg_qemu_tb_exec() in a fn to re
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PATCH 3/6] cpu-exec: wrap tcg_qemu_tb_exec() in a fn to restore the PC |
Date: |
Fri, 22 Feb 2013 18:10:02 +0000 |
If tcg_qemu_tb_exec() returns a value whose low bits don't indicate a
link to an indexed next TB, this means that the TB execution never
started (eg because the instruction counter hit zero). In this case the
guest PC has to be reset to the address of the start of the TB.
Refactor the cpu-exec code to make all tcg_qemu_tb_exec() calls pass
through a wrapper function which does this restoration if necessary.
Note that the apparent change in cpu_exec_nocache() from calling
cpu_pc_from_tb() with the old TB to calling it with the TB returned by
do_tcg_qemu_tb_exec() is safe, because in the nocache case we can
guarantee that the TB we try to execute is not linked to any others,
so the only possible returned TB is the one we started at. That is,
we should arguably previously have included in cpu_exec_nocache() an
assert(next_tb & ~TB_EXIT_MASK) == tb), since the API requires restore
from next_tb but we were using tb.
Signed-off-by: Peter Maydell <address@hidden>
---
cpu-exec.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index ea63e7d..e80626a 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -51,13 +51,28 @@ void cpu_resume_from_signal(CPUArchState *env, void *puc)
}
#endif
+/* Execute a TB, and fix up the CPU state afterwards if necessary */
+static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
+{
+ CPUArchState *env = cpu->env_ptr;
+ tcg_target_ulong next_tb = tcg_qemu_tb_exec(env, tb_ptr);
+ if ((next_tb & TB_EXIT_MASK) > TB_EXIT_IDX1) {
+ /* We didn't start executing this TB (eg because the instruction
+ * counter hit zero); we must restore the guest PC to the address
+ * of the start of the TB.
+ */
+ TranslationBlock *tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
+ cpu_pc_from_tb(env, tb);
+ }
+ return next_tb;
+}
+
/* Execute the code without caching the generated code. An interpreter
could be used if available. */
static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
TranslationBlock *orig_tb)
{
CPUState *cpu = ENV_GET_CPU(env);
- tcg_target_ulong next_tb;
TranslationBlock *tb;
/* Should never happen.
@@ -69,14 +84,8 @@ static void cpu_exec_nocache(CPUArchState *env, int
max_cycles,
max_cycles);
cpu->current_tb = tb;
/* execute the generated code */
- next_tb = tcg_qemu_tb_exec(env, tb->tc_ptr);
+ cpu_tb_exec(cpu, tb->tc_ptr);
cpu->current_tb = NULL;
-
- if ((next_tb & TB_EXIT_MASK) == TB_EXIT_ICOUNT_EXPIRED) {
- /* Restore PC. This may happen if async event occurs before
- the TB starts executing. */
- cpu_pc_from_tb(env, tb);
- }
tb_phys_invalidate(tb, -1);
tb_free(tb);
}
@@ -598,13 +607,11 @@ int cpu_exec(CPUArchState *env)
if (likely(!cpu->exit_request)) {
tc_ptr = tb->tc_ptr;
/* execute the generated code */
- next_tb = tcg_qemu_tb_exec(env, tc_ptr);
+ next_tb = cpu_tb_exec(cpu, tc_ptr);
if ((next_tb & TB_EXIT_MASK) == TB_EXIT_ICOUNT_EXPIRED) {
/* Instruction counter expired. */
int insns_left;
tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
- /* Restore PC. */
- cpu_pc_from_tb(env, tb);
insns_left = env->icount_decr.u32;
if (env->icount_extra && insns_left >= 0) {
/* Refill decrementer and continue execution. */
--
1.7.9.5
- [Qemu-devel] [PATCH 0/6] Drop the irredeemably racy cpu_unlink_tb(), Peter Maydell, 2013/02/22
- [Qemu-devel] [PATCH 6/6] gen-icount.h: Rename gen_icount_start/end to gen_tb_start/end, Peter Maydell, 2013/02/22
- [Qemu-devel] [PATCH 5/6] translate-all.c: Remove cpu_unlink_tb(), Peter Maydell, 2013/02/22
- [Qemu-devel] [PATCH 3/6] cpu-exec: wrap tcg_qemu_tb_exec() in a fn to restore the PC,
Peter Maydell <=
- [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Peter Maydell, 2013/02/22
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Andreas Färber, 2013/02/22
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Peter Maydell, 2013/02/22
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Andreas Färber, 2013/02/24
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Peter Maydell, 2013/02/24
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Andreas Färber, 2013/02/24
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Peter Maydell, 2013/02/24
- Re: [Qemu-devel] [PATCH 2/6] cpu: Introduce ENV_OFFSET macros, Andreas Färber, 2013/02/24
Re: [Qemu-devel] [PATCH 0/6] Drop the irredeemably racy cpu_unlink_tb(), Richard Henderson, 2013/02/22