[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/6] simplify cpu_exec
From: |
Glauber Costa |
Subject: |
[Qemu-devel] [PATCH 2/6] simplify cpu_exec |
Date: |
Wed, 28 May 2008 11:01:32 -0300 |
This is a first attempt to simplify cpu_exec(): it has simply
too many ifdefs, which is not a very good practice at all.
Following some work I've already posted in the past, I'm moving the target-b
ifdefs to target-xxx/helper.c, encapsuled into relevant functions.
Signed-off-by: Glauber Costa <address@hidden>
---
cpu-exec.c | 43 ++-----------------------------------------
exec-all.h | 10 ++++++++++
target-i386/exec.h | 15 +++++++++++++++
target-m68k/exec.h | 16 ++++++++++++++++
4 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 9b02447..af22e3c 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -262,27 +262,8 @@ int cpu_exec(CPUState *env1)
env = env1;
env_to_regs();
-#if defined(TARGET_I386)
- /* put eflags in CPU temporary format */
- CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
- DF = 1 - (2 * ((env->eflags >> 10) & 1));
- CC_OP = CC_OP_EFLAGS;
- env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-#elif defined(TARGET_SPARC)
-#elif defined(TARGET_M68K)
- env->cc_op = CC_OP_FLAGS;
- env->cc_dest = env->sr & 0xf;
- env->cc_x = (env->sr >> 4) & 1;
-#elif defined(TARGET_ALPHA)
-#elif defined(TARGET_ARM)
-#elif defined(TARGET_PPC)
-#elif defined(TARGET_MIPS)
-#elif defined(TARGET_SH4)
-#elif defined(TARGET_CRIS)
+ cpu_load_flags(env);
/* XXXXX */
-#else
-#error unsupported target CPU
-#endif
env->exception_index = -1;
/* prepare setjmp context for exception handling */
@@ -631,27 +612,7 @@ int cpu_exec(CPUState *env1)
}
} /* for(;;) */
-
-#if defined(TARGET_I386)
- /* restore flags in standard format */
- env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
-#elif defined(TARGET_ARM)
- /* XXX: Save/restore host fpu exception state?. */
-#elif defined(TARGET_SPARC)
-#elif defined(TARGET_PPC)
-#elif defined(TARGET_M68K)
- cpu_m68k_flush_flags(env, env->cc_op);
- env->cc_op = CC_OP_FLAGS;
- env->sr = (env->sr & 0xffe0)
- | env->cc_dest | (env->cc_x << 4);
-#elif defined(TARGET_MIPS)
-#elif defined(TARGET_SH4)
-#elif defined(TARGET_ALPHA)
-#elif defined(TARGET_CRIS)
- /* XXXXX */
-#else
-#error unsupported target CPU
-#endif
+ cpu_save_flags(env);
/* restore global registers */
#include "hostregs_helper.h"
diff --git a/exec-all.h b/exec-all.h
index 51b27b5..0eea2f1 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -82,6 +82,16 @@ int cpu_restore_state_copy(struct TranslationBlock *tb,
void *puc);
void cpu_resume_from_signal(CPUState *env1, void *puc);
void cpu_exec_init(CPUState *env);
+
+/* load flags for current execution. Architecture can override */
+#ifndef cpu_load_flags
+#define cpu_load_flags(env) do {} while (0)
+#endif
+/* save flags after cpu execution. Architecture can override */
+#ifndef cpu_save_flags
+#define cpu_save_flags(env) do {} while (0)
+#endif
+
int page_unprotect(target_ulong address, unsigned long pc, void *puc);
void tb_invalidate_phys_page_range(target_phys_addr_t start,
target_phys_addr_t end,
int is_cpu_write_access);
diff --git a/target-i386/exec.h b/target-i386/exec.h
index 5e46c5a..38ee96b 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -31,6 +31,21 @@
register struct CPUX86State *env asm(AREG0);
+#define cpu_load_flags(env) \
+do { \
+ /* put eflags in CPU temporary format */ \
+ CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); \
+ DF = 1 - (2 * ((env->eflags >> 10) & 1)); \
+ CC_OP = CC_OP_EFLAGS; \
+ env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);\
+} while (0)
+
+#define cpu_save_flags(env)
\
+do {
\
+ /* restore flags in standard format */
\
+ env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF &
DF_MASK); \
+} while (0)
+
extern FILE *logfile;
extern int loglevel;
diff --git a/target-m68k/exec.h b/target-m68k/exec.h
index 1269445..d4f51b3 100644
--- a/target-m68k/exec.h
+++ b/target-m68k/exec.h
@@ -26,6 +26,22 @@ register uint32_t T0 asm(AREG1);
/* ??? We don't use T1, but common code expects it to exist */
#define T1 env->t1
+#define cpu_load_flags(env) \
+do { \
+ env->cc_op = CC_OP_FLAGS; \
+ env->cc_dest = env->sr & 0xf; \
+ env->cc_x = (env->sr >> 4) & 1; \
+} while (0)
+
+#define cpu_save_flags(env) \
+do { \
+ cpu_m68k_flush_flags(env, env->cc_op); \
+ env->cc_op = CC_OP_FLAGS; \
+ env->sr = (env->sr & 0xffe0) \
+ | env->cc_dest | (env->cc_x << 4); \
+} while (0)
+
+
#include "cpu.h"
#include "exec-all.h"
--
1.5.4.5
- [Qemu-devel] [PATCH 0/6] Simplify cpu_exec - spin 3, Glauber Costa, 2008/05/28
- [Qemu-devel] [PATCH 1/6] remove REGWPTR, Glauber Costa, 2008/05/28
- [Qemu-devel] [PATCH 2/6] simplify cpu_exec,
Glauber Costa <=
- [Qemu-devel] [PATCH 3/6] Push common interrupt variables to cpu-defs.h, Glauber Costa, 2008/05/28
- [Qemu-devel] [PATCH 4/6] use halted attribute for i386 too., Glauber Costa, 2008/05/28
- [Qemu-devel] [PATCH 5/6] simply cpu_exec further, Glauber Costa, 2008/05/28
- [Qemu-devel] [PATCH 6/6] cpu-exec-dump, Glauber Costa, 2008/05/28
- Re: [Qemu-devel] [PATCH 5/6] simply cpu_exec further, Blue Swirl, 2008/05/28
- Re: [Qemu-devel] [PATCH 0/6] Simplify cpu_exec - spin 3, Paul Brook, 2008/05/28