From: Glauber Costa <gcosta@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 2/6] simplify cpu_exec
Date: Wed, 28 May 2008 11:01:32 -0300 [thread overview]
Message-ID: <1211983296-27395-3-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <1211983296-27395-2-git-send-email-gcosta@redhat.com>
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 <gcosta@redhat.com>
---
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
next prev parent reply other threads:[~2008-05-28 14:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-28 14:01 [Qemu-devel] [PATCH 0/6] Simplify cpu_exec - spin 3 Glauber Costa
2008-05-28 14:01 ` [Qemu-devel] [PATCH 1/6] remove REGWPTR Glauber Costa
2008-05-28 14:01 ` Glauber Costa [this message]
2008-05-28 14:01 ` [Qemu-devel] [PATCH 3/6] Push common interrupt variables to cpu-defs.h Glauber Costa
2008-05-28 14:01 ` [Qemu-devel] [PATCH 4/6] use halted attribute for i386 too Glauber Costa
2008-05-28 14:01 ` [Qemu-devel] [PATCH 5/6] simply cpu_exec further Glauber Costa
2008-05-28 14:01 ` [Qemu-devel] [PATCH 6/6] cpu-exec-dump Glauber Costa
2008-05-28 18:03 ` [Qemu-devel] [PATCH 5/6] simply cpu_exec further Blue Swirl
2008-05-28 14:25 ` [Qemu-devel] [PATCH 0/6] Simplify cpu_exec - spin 3 Paul Brook
2008-05-28 14:44 ` Glauber Costa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1211983296-27395-3-git-send-email-gcosta@redhat.com \
--to=gcosta@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).