Skip to contentSkip to conversation

Log reset events

PATCH Superseded Jan Kiszka 2 participants 3 messages Jun 23, 2008 – Jun 24, 2008

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/2 Log reset events

Original idea&code by Kevin Wolf, now split-up in two patches. This one introduces a flag to log CPU resets. Useful for tracing unexpected resets (such as those triggered by triple faults).

---
 cpu-all.h            |    1 +
 exec.c               |    2 ++
 target-i386/helper.c |    5 +++++
 3 files changed, 8 insertions(+)
exec.c +2 -0
Index: b/exec.c
===================================================================
@@ -1417,6 +1417,8 @@ CPULogItem cpu_log_items[] = {
 #ifdef TARGET_I386
     { CPU_LOG_PCALL, "pcall",
       "show protected mode far calls/returns/exceptions" },
+    { CPU_LOG_RESET, "cpu_reset",
+      "show CPU state before CPU resets" },
 #endif
 #ifdef DEBUG_IOPORT
     { CPU_LOG_IOPORT, "ioport",
target-i386/helper.c +5 -0
Index: b/target-i386/helper.c
===================================================================
@@ -383,6 +383,11 @@ void cpu_reset(CPUX86State *env)
 
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
+    }
+
     tlb_flush(env, 1);
 
     env->old_exception = -1;
cpu-all.h +1 -0
Index: b/cpu-all.h
===================================================================
@@ -825,6 +825,7 @@ target_phys_addr_t cpu_get_phys_page_deb
 #define CPU_LOG_PCALL      (1 << 6)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
+#define CPU_LOG_RESET      (1 << 9)
 
 /* define log items */
 typedef struct CPULogItem {
#1 lore raw
Quoted 6 lines · Jan Kiszka

Index: b/target-i386/helper.c
===================================================================

target-i386/helper.c +0 -0
@@ -383,6 +383,11 @@ void cpu_reset(CPUX86State *env)
 

target-i386/helper.c void cpu_reset(CPUX86State *env) · line 393

Quoted 10 lines
target-i386/helper.c +5 -0
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
+    }
+
     tlb_flush(env, 1);
 
     env->old_exception = -1;

I'd say you want to have the memset after the CPU dump, otherwise the dump is quite boring. ;-) Did you change that by intention? Your last patch still had the memset after the dump.

You can add a Signed-off-by: Kevin Wolf <[email protected]> to the next version of the patch.

Kevin

author
#2 lore raw

PATCH 1/2 Log reset events - v2

Quoted 17 lines · Kevin Wolf
Quoted 16 lines · Jan Kiszka

Index: b/target-i386/helper.c
===================================================================

target-i386/helper.c +5 -0
@@ -383,6 +383,11 @@ void cpu_reset(CPUX86State *env)
 
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, X86_DUMP_FPU |
 X86_DUMP_CCOP);
+    }
+
     tlb_flush(env, 1);
 
Quoted 5 lines
Quoted 1 line
     env->old_exception = -1;

I'd say you want to have the memset after the CPU dump, otherwise the dump is quite boring. ;-) Did you change that by intention? Your last patch still had the memset after the dump.

Good point, probably merge breakage. Moreover my patch was ignoring archs != x86. Better version below.

-----------

Original idea&code by Kevin Wolf, now split-up in two patches and added more archs.

This patch introduces a flag to log CPU resets. Useful for tracing unexpected resets (such as those triggered by x86 triple faults).

---
 cpu-all.h               |    1 +
 exec.c                  |    2 ++
 target-arm/helper.c     |    6 ++++++
 target-cris/translate.c |    5 +++++
 target-i386/helper.c    |    5 +++++
 target-m68k/helper.c    |    5 +++++
 target-mips/translate.c |    5 +++++
 target-ppc/helper.c     |    5 +++++
 target-sh4/translate.c  |    5 +++++
 target-sparc/helper.c   |    5 +++++
 10 files changed, 44 insertions(+)
exec.c +2 -0
Index: b/exec.c
===================================================================
@@ -1417,6 +1417,8 @@ CPULogItem cpu_log_items[] = {
 #ifdef TARGET_I386
     { CPU_LOG_PCALL, "pcall",
       "show protected mode far calls/returns/exceptions" },
+    { CPU_LOG_RESET, "cpu_reset",
+      "show CPU state before CPU resets" },
 #endif
 #ifdef DEBUG_IOPORT
     { CPU_LOG_IOPORT, "ioport",
target-i386/helper.c +5 -0
Index: b/target-i386/helper.c
===================================================================
@@ -381,6 +381,11 @@ void cpu_reset(CPUX86State *env)
 {
     int i;
 
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
+    }
+
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
     tlb_flush(env, 1);
cpu-all.h +1 -0
Index: b/cpu-all.h
===================================================================
@@ -825,6 +825,7 @@ target_phys_addr_t cpu_get_phys_page_deb
 #define CPU_LOG_PCALL      (1 << 6)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
+#define CPU_LOG_RESET      (1 << 9)
 
 /* define log items */
 typedef struct CPULogItem {
target-arm/helper.c +6 -0
Index: b/target-arm/helper.c
===================================================================
@@ -153,6 +153,12 @@ static void cpu_reset_model_id(CPUARMSta
 void cpu_reset(CPUARMState *env)
 {
     uint32_t id;
+
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
     id = env->cp15.c0_cpuid;
     memset(env, 0, offsetof(CPUARMState, breakpoints));
     if (id)
target-cris/translate.c +5 -0
Index: b/target-cris/translate.c
===================================================================
@@ -3360,6 +3360,11 @@ CPUCRISState *cpu_cris_init (const char 
 
 void cpu_reset (CPUCRISState *env)
 {
+	if (loglevel & CPU_LOG_RESET) {
+		fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+		cpu_dump_state(env, logfile, fprintf, 0);
+	}
+
 	memset(env, 0, offsetof(CPUCRISState, breakpoints));
 	tlb_flush(env, 1);
 
target-m68k/helper.c +5 -0
Index: b/target-m68k/helper.c
===================================================================
@@ -110,6 +110,11 @@ static int cpu_m68k_set_model(CPUM68KSta
 
 void cpu_reset(CPUM68KState *env)
 {
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
     memset(env, 0, offsetof(CPUM68KState, breakpoints));
 #if !defined (CONFIG_USER_ONLY)
     env->sr = 0x2700;
target-mips/translate.c +5 -0
Index: b/target-mips/translate.c
===================================================================
@@ -7989,6 +7989,11 @@ CPUMIPSState *cpu_mips_init (const char 
 
 void cpu_reset (CPUMIPSState *env)
 {
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
     memset(env, 0, offsetof(CPUMIPSState, breakpoints));
 
     tlb_flush(env, 1);
target-ppc/helper.c +5 -0
Index: b/target-ppc/helper.c
===================================================================
@@ -2931,6 +2931,11 @@ void cpu_ppc_reset (void *opaque)
     CPUPPCState *env;
     target_ulong msr;
 
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
     env = opaque;
     msr = (target_ulong)0;
     if (0) {
target-sh4/translate.c +5 -0
Index: b/target-sh4/translate.c
===================================================================
@@ -118,6 +118,11 @@ void cpu_dump_state(CPUState * env, FILE
 
 void cpu_sh4_reset(CPUSH4State * env)
 {
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
 #if defined(CONFIG_USER_ONLY)
     env->sr = SR_FD;            /* FD - kernel does lazy fpu context switch */
 #else
target-sparc/helper.c +5 -0
Index: b/target-sparc/helper.c
===================================================================
@@ -881,6 +881,11 @@ void memcpy32(target_ulong *dst, const t
 
 void cpu_reset(CPUSPARCState *env)
 {
+    if (loglevel & CPU_LOG_RESET) {
+        fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+        cpu_dump_state(env, logfile, fprintf, 0);
+    }
+
     tlb_flush(env, 1);
     env->cwp = 0;
     env->wim = 1;