qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 3/3] use halted attribute for i386 too.


From: Glauber Costa
Subject: [Qemu-devel] [PATCH 3/3] use halted attribute for i386 too.
Date: Wed, 21 May 2008 18:40:53 -0300

Unlike other architectures, i386 lacked a "halted" attribute, going
with a flag into hflags. By using the halted attribute, we can make
the code look like more other architectures, and simplify the code in
some instances. In this commit, we make the code for info_cpus simpler
in monitor.c

Signed-off-by: Glauber Costa <address@hidden>
---
 cpu-defs.h            |    2 ++
 exec-all.h            |    1 +
 hw/apic.c             |    4 ++--
 hw/pc.c               |    2 +-
 monitor.c             |   23 +++++------------------
 target-alpha/cpu.h    |    1 -
 target-alpha/helper.c |    1 +
 target-arm/cpu.h      |    1 -
 target-arm/helper.c   |    1 +
 target-cris/cpu.h     |    1 -
 target-cris/helper.c  |    1 +
 target-i386/exec.h    |    4 ++--
 target-i386/helper.c  |    9 ++++++++-
 target-m68k/cpu.h     |    1 -
 target-m68k/helper.c  |    1 +
 target-mips/cpu.h     |    2 --
 target-mips/helper.c  |    5 +++++
 target-ppc/cpu.h      |    2 --
 target-ppc/helper.c   |    6 ++++++
 target-sh4/cpu.h      |    1 -
 target-sh4/helper.c   |    1 +
 target-sparc/cpu.h    |    1 -
 target-sparc/helper.c |    5 +++++
 23 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/cpu-defs.h b/cpu-defs.h
index bb00c80..5bcd1ee 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -164,6 +164,8 @@ typedef struct CPUTLBEntry {
     int exception_index;                                                \
     int error_code;                                                     \
                                                                         \
+    int halted;                                                         \
+                                                                        \
     void *next_cpu; /* next CPU sharing TB cache */                     \
     int cpu_index; /* CPU index (informative) */                        \
     /* user data */                                                     \
diff --git a/exec-all.h b/exec-all.h
index ce0e839..3a98826 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -83,6 +83,7 @@ int cpu_restore_state_copy(struct TranslationBlock *tb,
 void cpu_resume_from_signal(CPUState *env1, void *puc);
 void cpu_exec_init(CPUState *env);
 
+extern int  cpu_info_ip(CPUState *env, char *buf);
 void cpu_pre_exec(CPUState *env);
 void cpu_post_exec(CPUState *env);
 
diff --git a/hw/apic.c b/hw/apic.c
index a1ebf21..0dc9f8e 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -443,12 +443,12 @@ static void apic_init_ipi(APICState *s)
 static void apic_startup(APICState *s, int vector_num)
 {
     CPUState *env = s->cpu_env;
-    if (!(env->hflags & HF_HALTED_MASK))
+    if (!(env->halted))
         return;
     env->eip = 0;
     cpu_x86_load_seg_cache(env, R_CS, vector_num << 8, vector_num << 12,
                            0xffff, 0);
-    env->hflags &= ~HF_HALTED_MASK;
+    env->halted = 0;
 }
 
 static void apic_deliver(APICState *s, uint8_t dest, uint8_t dest_mode,
diff --git a/hw/pc.c b/hw/pc.c
index c92384c..c68323b 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -761,7 +761,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
             exit(1);
         }
         if (i != 0)
-            env->hflags |= HF_HALTED_MASK;
+            env->halted = 1;
         if (smp_cpus > 1) {
             /* XXX: enable it in all cases */
             env->cpuid_features |= CPUID_APIC;
diff --git a/monitor.c b/monitor.c
index 236b827..f34d147 100644
--- a/monitor.c
+++ b/monitor.c
@@ -36,6 +36,8 @@
 #include "disas.h"
 #include <dirent.h>
 
+#include "exec-all.h"
+
 #ifdef CONFIG_PROFILER
 #include "qemu-timer.h" /* for ticks_per_sec */
 #endif
@@ -304,6 +306,7 @@ static void do_info_registers(void)
 static void do_info_cpus(void)
 {
     CPUState *env;
+    char buf[1024];
 
     /* just to set the default cpu if not already done */
     mon_get_cpu();
@@ -312,24 +315,8 @@ static void do_info_cpus(void)
         term_printf("%c CPU #%d:",
                     (env == mon_cpu) ? '*' : ' ',
                     env->cpu_index);
-#if defined(TARGET_I386)
-        term_printf(" pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base);
-        if (env->hflags & HF_HALTED_MASK)
-            term_printf(" (halted)");
-#elif defined(TARGET_PPC)
-        term_printf(" nip=0x" TARGET_FMT_lx, env->nip);
-        if (env->halted)
-            term_printf(" (halted)");
-#elif defined(TARGET_SPARC)
-        term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, 
env->npc);
-        if (env->halted)
-            term_printf(" (halted)");
-#elif defined(TARGET_MIPS)
-        term_printf(" PC=0x" TARGET_FMT_lx, env->PC[env->current_tc]);
-        if (env->halted)
-            term_printf(" (halted)");
-#endif
-        term_printf("\n");
+        if (cpu_info_ip(env, buf))
+            term_printf("%s %s\n", buf, env->halted ? "(halted)" : "");
     }
 }
 
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index b3c10d7..dc2460a 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -284,7 +284,6 @@ struct CPUAlphaState {
 
     int user_mode_only; /* user mode only simulation */
     uint32_t hflags;
-    int halted;
 
     int interrupt_request;
 
diff --git a/target-alpha/helper.c b/target-alpha/helper.c
index 73d565f..6056d6c 100644
--- a/target-alpha/helper.c
+++ b/target-alpha/helper.c
@@ -453,5 +453,6 @@ void cpu_dump_EA (target_ulong EA)
     fprintf(f, "Memory access at address " TARGET_FMT_lx "\n", EA);
 }
 
+int cpu_info_ip(CPUState *env, char *buf) { return 0; }
 void cpu_pre_exec(CPUState *env) {}
 void cpu_post_exec(CPUState *env) {}
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 60a7a64..8d0558c 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -158,7 +158,6 @@ typedef struct CPUARMState {
     /* exception/interrupt handling */
     int interrupt_request;
     int user_mode_only;
-    int halted;
 
     /* VFP coprocessor state.  */
     struct {
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 496f326..6724909 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -2523,6 +2523,7 @@ uint32_t HELPER(rsqrte_u32)(uint32_t a, CPUState *env)
     return float32_to_int32(tmp, s);
 }
 
+int cpu_info_ip(CPUState *env, char *buf) { return 0; }
 void cpu_pre_exec(CPUState *env) { }
 /* XXX: Save/restore host fpu exception state?.  */
 void cpu_post_exec(CPUState *env) { }
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index d45abea..acc1b5d 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -161,7 +161,6 @@ typedef struct CPUCRISState {
 
        int features;
        int user_mode_only;
-       int halted;
 
        CPU_COMMON
 } CPUCRISState;
diff --git a/target-cris/helper.c b/target-cris/helper.c
index 1e216aa..0ed169c 100644
--- a/target-cris/helper.c
+++ b/target-cris/helper.c
@@ -184,5 +184,6 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, 
target_ulong addr)
 }
 #endif
 
+int  cpu_info_ip(CPUState *env, char *buf) { return 0; }
 void cpu_pre_exec(CPUState *env) {}
 void cpu_post_exec(CPUState *env) {}
diff --git a/target-i386/exec.h b/target-i386/exec.h
index 8597e79..f6517ce 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -425,13 +425,13 @@ static inline void regs_to_env(void)
 
 static inline int cpu_halted(CPUState *env) {
     /* handle exit of HALTED state */
-    if (!(env->hflags & HF_HALTED_MASK))
+    if (!(env->halted))
         return 0;
     /* disable halt condition */
     if (((env->interrupt_request & CPU_INTERRUPT_HARD) &&
          (env->eflags & IF_MASK)) ||
         (env->interrupt_request & CPU_INTERRUPT_NMI)) {
-        env->hflags &= ~HF_HALTED_MASK;
+        env->halted = 0;
         return 0;
     }
     return EXCP_HALTED;
diff --git a/target-i386/helper.c b/target-i386/helper.c
index e8809c2..9d5c3de 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -4511,7 +4511,7 @@ void helper_idivq_EAX(target_ulong t0)
 void helper_hlt(void)
 {
     env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
-    env->hflags |= HF_HALTED_MASK;
+    env->halted = 1;
     env->exception_index = EXCP_HLT;
     cpu_loop_exit();
 }
@@ -4692,6 +4692,13 @@ void helper_clgi(void)
 {
     env->hflags &= ~HF_GIF_MASK;
 }
+
+int cpu_info_ip(CPUState *env, char *buf)
+{
+    sprintf(buf, " pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base);
+    return 1;
+}
+
 void cpu_pre_exec(CPUState *env)
 {
     /* put eflags in CPU temporary format */
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index ba36387..e8c1dfc 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -106,7 +106,6 @@ typedef struct CPUM68KState {
     /* exception/interrupt handling */
     int interrupt_request;
     int user_mode_only;
-    int halted;
 
     int pending_vector;
     int pending_level;
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 73e93bc..82b5576 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -339,6 +339,7 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, 
target_ulong addr)
     return addr;
 }
 
+int  cpu_info_ip(CPUState *env, char *buf) { return 0; }
 void cpu_pre_exec(CPUState *env)
 {
     env->cc_op = CC_OP_FLAGS;
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 08aad3e..38ae0b4 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -445,8 +445,6 @@ struct CPUMIPSState {
     target_ulong btarget;        /* Jump / branch target               */
     int bcond;                   /* Branch condition (if needed)       */
 
-    int halted; /* TRUE if the CPU is in suspend state */
-
     int SYNCI_Step; /* Address step size for SYNCI */
     int CCRes; /* Cycle count resolution/divisor */
     uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
diff --git a/target-mips/helper.c b/target-mips/helper.c
index 90e6dbe..1499be2 100644
--- a/target-mips/helper.c
+++ b/target-mips/helper.c
@@ -637,5 +637,10 @@ void r4k_invalidate_tlb (CPUState *env, int idx, int 
use_extra)
     }
 }
 
+int cpu_info_ip(CPUState *env, char *buf)
+{
+    sprintf(buf, " PC=0x" TARGET_FMT_lx, env->PC[env->current_tc]);
+}
+
 void cpu_post_exec(CPUState *env) { }
 void cpu_pre_exec(CPUState *env) { }
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index e9f9287..a1f90e2 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -586,8 +586,6 @@ struct CPUPPCState {
 
     CPU_COMMON
 
-    int halted; /* TRUE if the CPU is in suspend state */
-
     int access_type; /* when a memory exception occurs, the access
                         type is stored here */
 
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 300532f..2858780 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -2989,5 +2989,11 @@ void cpu_ppc_close (CPUPPCState *env)
     qemu_free(env);
 }
 
+int cpu_info_ip(CPUState *env, char *buf)
+{
+    sprintf(buf, " nip=0x" TARGET_FMT_lx, env->nip);
+    return 1;
+}
+
 void cpu_pre_exec(CPUState *env) { }
 void cpu_post_exec(CPUState *env) { }
diff --git a/target-sh4/cpu.h b/target-sh4/cpu.h
index 534ada3..c03cdb1 100644
--- a/target-sh4/cpu.h
+++ b/target-sh4/cpu.h
@@ -116,7 +116,6 @@ typedef struct CPUSH4State {
 
     int user_mode_only;
     int interrupt_request;
-    int halted;
      CPU_COMMON tlb_t utlb[UTLB_SIZE]; /* unified translation table */
     tlb_t itlb[ITLB_SIZE];     /* instruction translation table */
     void *intc_handle;
diff --git a/target-sh4/helper.c b/target-sh4/helper.c
index ebc16ac..df64d28 100644
--- a/target-sh4/helper.c
+++ b/target-sh4/helper.c
@@ -535,5 +535,6 @@ void cpu_load_tlb(CPUState * env)
 
 #endif
 
+int  cpu_info_ip(CPUState *env, char *buf) { return 0; }
 void cpu_pre_exec(CPUState *env) {}
 void cpu_post_exec(CPUState *env) {}
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index b663fe2..ba3ee01 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -217,7 +217,6 @@ typedef struct CPUSPARCState {
     int user_mode_only;
     int interrupt_index;
     int interrupt_request;
-    int halted;
     uint32_t mmu_bm;
     uint32_t mmu_ctpr_mask;
     uint32_t mmu_cxr_mask;
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 76c68fa..2f887f1 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -1320,6 +1320,11 @@ void cpu_dump_state(CPUState *env, FILE *f,
 static uint32_t *saved_regwptr;
 #endif
 
+int cpu_info_ip(CPUState *env, char *buf)
+{
+    term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, 
env->npc);
+}
+
 void cpu_pre_exec(CPUState *env)
 {
 #if defined(reg_REGWPTR)
-- 
1.5.4.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]