qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [patch] gdb-stub support for Alpha
@ 2008-12-03 18:16 Vince Weaver
  2008-12-04  5:25 ` Vince Weaver
  0 siblings, 1 reply; 5+ messages in thread
From: Vince Weaver @ 2008-12-03 18:16 UTC (permalink / raw)
  To: qemu-devel

Hello

the patch below enables gdb-stub support for Alpha.

It currently has two problems, hopefully someone who knows a bit more
about how gdb-stub works can be of help.

1).  When single-stepping through a branch, it double-steps after
     each branch instruction

2).  When viewing floating-point registers, the value displayed
     as being in the register is the integer equivelent of the
     value, not the actual floating point value.

     For example, if the value in the register is 197.0,
     the hex vale for the raw value is shown as
     0xc5 instead of 0x4068a0000000000

Vince

Index: target-alpha/translate.c
===================================================================
--- target-alpha/translate.c	(revision 5854)
+++ target-alpha/translate.c	(working copy)
@@ -2407,10 +2407,15 @@
          * generation
          */
         if (((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) ||
-            (env->singlestep_enabled) ||
             num_insns >= max_insns) {
             break;
         }
+
+        if (env->singlestep_enabled) {
+	   gen_excp(&ctx, EXCP_DEBUG, 0);
+	   break;
+	}
+
 #if defined (DO_SINGLE_STEP)
         break;
 #endif
Index: gdbstub.c
===================================================================
--- gdbstub.c	(revision 5854)
+++ gdbstub.c	(working copy)
@@ -990,6 +990,50 @@

     return 4;
 }
+#elif defined (TARGET_ALPHA)
+
+#define NUM_CORE_REGS 65
+
+static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    if (n < 31) {
+       GET_REGL(env->ir[n]);
+    }
+    else if (n == 31) {
+       GET_REGL(0);
+    }
+    else if (n<63) {
+       GET_REGL(env->fir[n-32]);
+    }
+    else if (n<64) {
+       GET_REGL(0);
+    }
+    else {
+       GET_REGL(env->pc);
+    }
+
+    return 0;
+}
+
+static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    target_ulong tmp;
+    tmp = ldtul_p(mem_buf);
+
+    if (n < 31) {
+	env->ir[n] = tmp;
+    }
+
+    if (n > 31 && n < 63) {
+	env->fir[n - 32] = ldfl_p(mem_buf);
+    }
+
+    if (n == 64 ) {
+       env->pc=tmp;
+    }
+
+    return 8;
+}
 #else

 #define NUM_CORE_REGS 0
@@ -1277,6 +1321,8 @@
             s->c_cpu->active_tc.PC = addr;
 #elif defined (TARGET_CRIS)
             s->c_cpu->pc = addr;
+#elif defined (TARGET_ALPHA)
+	    s->c_cpu->pc = addr;
 #endif
         }
         gdb_continue(s);
@@ -1313,6 +1359,8 @@
             s->c_cpu->active_tc.PC = addr;
 #elif defined (TARGET_CRIS)
             s->c_cpu->pc = addr;
+#elif defined (TARGET_ALPHA)
+	    s->c_cpu->pc = addr;
 #endif
         }
         cpu_single_step(s->c_cpu, sstep_flags);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [patch] gdb-stub support for Alpha
  2008-12-03 18:16 [Qemu-devel] [patch] gdb-stub support for Alpha Vince Weaver
@ 2008-12-04  5:25 ` Vince Weaver
  2008-12-04 15:58   ` [Qemu-devel] " Jan Kiszka
  2008-12-07 23:26   ` [Qemu-devel] " Aurelien Jarno
  0 siblings, 2 replies; 5+ messages in thread
From: Vince Weaver @ 2008-12-04  5:25 UTC (permalink / raw)
  To: qemu-devel


Here's an updated version of the patch.  It fixes floating point support.

It still double-steps after a branch for some reason though.

Vince

Index: target-alpha/translate.c
===================================================================
--- target-alpha/translate.c	(revision 5854)
+++ target-alpha/translate.c	(working copy)
@@ -2407,10 +2407,15 @@
          * generation
          */
         if (((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) ||
-            (env->singlestep_enabled) ||
             num_insns >= max_insns) {
             break;
         }
+
+        if (env->singlestep_enabled) {
+	   gen_excp(&ctx, EXCP_DEBUG, 0);
+	   break;
+	}
+
 #if defined (DO_SINGLE_STEP)
         break;
 #endif
Index: gdbstub.c
===================================================================
--- gdbstub.c	(revision 5854)
+++ gdbstub.c	(working copy)
@@ -990,6 +990,56 @@

     return 4;
 }
+#elif defined (TARGET_ALPHA)
+
+#define NUM_CORE_REGS 65
+
+static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    if (n < 31) {
+       GET_REGL(env->ir[n]);
+    }
+    else if (n == 31) {
+       GET_REGL(0);
+    }
+    else if (n<63) {
+       uint64_t val;
+
+       val=*((uint64_t *)&env->fir[n-32]);
+       GET_REGL(val);
+    }
+    else if (n==63) {
+       GET_REGL(env->fpcr);
+    }
+    else if (n==64) {
+       GET_REGL(env->pc);
+    }
+    else {
+       GET_REGL(0);
+    }
+
+    return 0;
+}
+
+static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    target_ulong tmp;
+    tmp = ldtul_p(mem_buf);
+
+    if (n < 31) {
+	env->ir[n] = tmp;
+    }
+
+    if (n > 31 && n < 63) {
+	env->fir[n - 32] = ldfl_p(mem_buf);
+    }
+
+    if (n == 64 ) {
+       env->pc=tmp;
+    }
+
+    return 8;
+}
 #else

 #define NUM_CORE_REGS 0
@@ -1277,6 +1327,8 @@
             s->c_cpu->active_tc.PC = addr;
 #elif defined (TARGET_CRIS)
             s->c_cpu->pc = addr;
+#elif defined (TARGET_ALPHA)
+	    s->c_cpu->pc = addr;
 #endif
         }
         gdb_continue(s);
@@ -1313,6 +1365,8 @@
             s->c_cpu->active_tc.PC = addr;
 #elif defined (TARGET_CRIS)
             s->c_cpu->pc = addr;
+#elif defined (TARGET_ALPHA)
+	    s->c_cpu->pc = addr;
 #endif
         }
         cpu_single_step(s->c_cpu, sstep_flags);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] Re: [patch] gdb-stub support for Alpha
  2008-12-04  5:25 ` Vince Weaver
@ 2008-12-04 15:58   ` Jan Kiszka
  2008-12-04 19:26     ` Vince Weaver
  2008-12-07 23:26   ` [Qemu-devel] " Aurelien Jarno
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2008-12-04 15:58 UTC (permalink / raw)
  To: qemu-devel

Vince Weaver wrote:
> Here's an updated version of the patch.  It fixes floating point support.
> 
> It still double-steps after a branch for some reason though.

I would suggest checking out what gets translated, executed and
communicated by using '-d in_asm,out_asm' for the qemu command line,
running qemu itself inside gdb and maybe also enabling 'set debug remote
1' in the remote gdb instance (which will print the frontend<->backend
communication). That should help to get a better picture about what
happens and why you see double steps.

Jan

-- 
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] Re: [patch] gdb-stub support for Alpha
  2008-12-04 15:58   ` [Qemu-devel] " Jan Kiszka
@ 2008-12-04 19:26     ` Vince Weaver
  0 siblings, 0 replies; 5+ messages in thread
From: Vince Weaver @ 2008-12-04 19:26 UTC (permalink / raw)
  To: qemu-devel


On Thu, 4 Dec 2008, Jan Kiszka wrote:
> I would suggest checking out what gets translated, executed and
> communicated by using '-d in_asm,out_asm' for the qemu command line,
> running qemu itself inside gdb and maybe also enabling 'set debug remote
> 1' in the remote gdb instance (which will print the frontend<->backend
> communication). That should help to get a better picture about what
> happens and why you see double steps.

Thanks!  That helped track down the problem.

On Alpha, for non-branch instructions the move of ctx->pc to cpu_pc 
happens at the end of the TB (after the single-step exception is called).

However, for branches, the move of ctx->pc to cpu_pc happens within the 
instruction decoding, *before* the single-step exception is called, so the 
exception handler over-writes the proper new pc with an older one.

This is tricky to fix.  Either all the branch code needs to be re-written 
to write to a temporary nextpc value that is written at the end, or else
I have to somehow wrap the single-step exception code to preserve the new 
pc value.

Vince

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [patch] gdb-stub support for Alpha
  2008-12-04  5:25 ` Vince Weaver
  2008-12-04 15:58   ` [Qemu-devel] " Jan Kiszka
@ 2008-12-07 23:26   ` Aurelien Jarno
  1 sibling, 0 replies; 5+ messages in thread
From: Aurelien Jarno @ 2008-12-07 23:26 UTC (permalink / raw)
  To: qemu-devel

On Thu, Dec 04, 2008 at 12:25:58AM -0500, Vince Weaver wrote:
> 
> Here's an updated version of the patch.  It fixes floating point support.
> 
> It still double-steps after a branch for some reason though.
> 
> Vince

Thanks applied.

> Index: target-alpha/translate.c
> ===================================================================
> --- target-alpha/translate.c	(revision 5854)
> +++ target-alpha/translate.c	(working copy)
> @@ -2407,10 +2407,15 @@
>           * generation
>           */
>          if (((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) ||
> -            (env->singlestep_enabled) ||
>              num_insns >= max_insns) {
>              break;
>          }
> +
> +        if (env->singlestep_enabled) {
> +	   gen_excp(&ctx, EXCP_DEBUG, 0);
> +	   break;
> +	}
> +
>  #if defined (DO_SINGLE_STEP)
>          break;
>  #endif
> Index: gdbstub.c
> ===================================================================
> --- gdbstub.c	(revision 5854)
> +++ gdbstub.c	(working copy)
> @@ -990,6 +990,56 @@
> 
>      return 4;
>  }
> +#elif defined (TARGET_ALPHA)
> +
> +#define NUM_CORE_REGS 65
> +
> +static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n)
> +{
> +    if (n < 31) {
> +       GET_REGL(env->ir[n]);
> +    }
> +    else if (n == 31) {
> +       GET_REGL(0);
> +    }
> +    else if (n<63) {
> +       uint64_t val;
> +
> +       val=*((uint64_t *)&env->fir[n-32]);
> +       GET_REGL(val);
> +    }
> +    else if (n==63) {
> +       GET_REGL(env->fpcr);
> +    }
> +    else if (n==64) {
> +       GET_REGL(env->pc);
> +    }
> +    else {
> +       GET_REGL(0);
> +    }
> +
> +    return 0;
> +}
> +
> +static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
> +{
> +    target_ulong tmp;
> +    tmp = ldtul_p(mem_buf);
> +
> +    if (n < 31) {
> +	env->ir[n] = tmp;
> +    }
> +
> +    if (n > 31 && n < 63) {
> +	env->fir[n - 32] = ldfl_p(mem_buf);
> +    }
> +
> +    if (n == 64 ) {
> +       env->pc=tmp;
> +    }
> +
> +    return 8;
> +}
>  #else
> 
>  #define NUM_CORE_REGS 0
> @@ -1277,6 +1327,8 @@
>              s->c_cpu->active_tc.PC = addr;
>  #elif defined (TARGET_CRIS)
>              s->c_cpu->pc = addr;
> +#elif defined (TARGET_ALPHA)
> +	    s->c_cpu->pc = addr;
>  #endif
>          }
>          gdb_continue(s);
> @@ -1313,6 +1365,8 @@
>              s->c_cpu->active_tc.PC = addr;
>  #elif defined (TARGET_CRIS)
>              s->c_cpu->pc = addr;
> +#elif defined (TARGET_ALPHA)
> +	    s->c_cpu->pc = addr;
>  #endif
>          }
>          cpu_single_step(s->c_cpu, sstep_flags);
> 
> 
> 
> 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-12-07 23:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03 18:16 [Qemu-devel] [patch] gdb-stub support for Alpha Vince Weaver
2008-12-04  5:25 ` Vince Weaver
2008-12-04 15:58   ` [Qemu-devel] " Jan Kiszka
2008-12-04 19:26     ` Vince Weaver
2008-12-07 23:26   ` [Qemu-devel] " Aurelien Jarno

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).