Patchwork target-moxie: set do_interrupt to a target-specific helper function

login
register
mail settings
Submitter Dunrong Huang
Date March 31, 2013, 1:35 a.m.
Message ID <1364693753-3311-1-git-send-email-huangdr@cloud-times.com>
Download mbox | patch
Permalink /patch/232586/
State New
Headers show

Comments

Dunrong Huang - March 31, 2013, 1:35 a.m.
The value of "do_interrupt" member of CPUClass shoule be set to a
target-specific function, or it will lead to a segfault like below:

$ moxie-softmmu/qemu-system-moxie -M moxiesim
Segmentation fault

Cc: Anthony Green <green@moxielogic.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Cc: Andreas Färber <afaerber@suse.de>
Signed-off-by: Dunrong Huang <huangdr@cloud-times.com>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
Anthony Green - March 31, 2013, 12:33 p.m.
Hi Dunrong,

  I can't reproduce the segfault, but your patch still looks right to
me.  Thanks!

Signed-of-by: Anthony Green <green@moxielogic.com>

AG


On Sat, Mar 30, 2013 at 9:35 PM, Dunrong Huang <huangdr@cloud-times.com> wrote:
> The value of "do_interrupt" member of CPUClass shoule be set to a
> target-specific function, or it will lead to a segfault like below:
>
> $ moxie-softmmu/qemu-system-moxie -M moxiesim
> Segmentation fault
>
> Cc: Anthony Green <green@moxielogic.com>
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Dunrong Huang <huangdr@cloud-times.com>
> ---
>  target-moxie/cpu.c    | 1 +
>  target-moxie/cpu.h    | 2 +-
>  target-moxie/helper.c | 7 +++++--
>  3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
> index c17d3f0..c0855f0 100644
> --- a/target-moxie/cpu.c
> +++ b/target-moxie/cpu.c
> @@ -98,6 +98,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data)
>      cc->class_by_name = moxie_cpu_class_by_name;
>
>      dc->vmsd = &vmstate_moxie_cpu;
> +    cc->do_interrupt = moxie_cpu_do_interrupt;
>  }
>
>  static void moxielite_initfn(Object *obj)
> diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
> index b96236f..988729a 100644
> --- a/target-moxie/cpu.h
> +++ b/target-moxie/cpu.h
> @@ -117,7 +117,7 @@ static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
>
>  MoxieCPU *cpu_moxie_init(const char *cpu_model);
>  int cpu_moxie_exec(CPUMoxieState *s);
> -void do_interrupt(CPUMoxieState *env);
> +void moxie_cpu_do_interrupt(CPUState *cs);
>  void moxie_translate_init(void);
>  int cpu_moxie_signal_handler(int host_signum, void *pinfo,
>                               void *puc);
> diff --git a/target-moxie/helper.c b/target-moxie/helper.c
> index 8604ce8..6e0ac2a 100644
> --- a/target-moxie/helper.c
> +++ b/target-moxie/helper.c
> @@ -102,7 +102,7 @@ void helper_debug(CPUMoxieState *env)
>
>  #if defined(CONFIG_USER_ONLY)
>
> -void do_interrupt(CPUState *env)
> +void moxie_cpu_do_interrupt(CPUState *env)
>  {
>      env->exception_index = -1;
>  }
> @@ -147,8 +147,11 @@ int cpu_moxie_handle_mmu_fault(CPUMoxieState *env, target_ulong address,
>  }
>
>
> -void do_interrupt(CPUMoxieState *env)
> +void moxie_cpu_do_interrupt(CPUState *cs)
>  {
> +    MoxieCPU *cpu = MOXIE_CPU(cs);
> +    CPUMoxieState *env = &cpu->env;
> +
>      switch (env->exception_index) {
>      case MOXIE_EX_BREAK:
>          break;
> --
> 1.8.1.5
>
Dunrong Huang - March 31, 2013, 1:43 p.m.
Hi Anthony, thanks for your reply.

Below is the backtrace from core dump file, it may help.

$ moxie-softmmu/qemu-system-moxie  -M moxiesim
Segmentation fault (core dumped)
$ gdb moxie-softmmu/qemu-system-moxie core
GNU gdb (Gentoo) 7.4.1
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from
/home/mathslinux/Develop/QEMU/qemu/moxie-softmmu/qemu-system-moxie...done.

warning: core file may not match specified executable file.
[New LWP 1016]
[New LWP 1015]

warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `moxie-softmmu/qemu-system-moxie -M moxiesim'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007fc256f31691 in cpu_moxie_exec (env=0x7fc2589c5ee0) at
/home/mathslinux/Develop/QEMU/qemu/cpu-exec.c:278
#2  0x00007fc256f34833 in tcg_cpu_exec (env=0x7fc2589c5ee0) at
/home/mathslinux/Develop/QEMU/qemu/cpus.c:1117
#3  0x00007fc256f3496a in tcg_exec_all () at
/home/mathslinux/Develop/QEMU/qemu/cpus.c:1150
#4  0x00007fc256f33c60 in qemu_tcg_cpu_thread_fn (arg=0x7fc2589c5dd0) at
/home/mathslinux/Develop/QEMU/qemu/cpus.c:843
#5  0x00007fc2533f1ea7 in start_thread () from /lib64/libpthread.so.0
#6  0x00007fc24f6fa06d in clone () from /lib64/libc.so.6
(gdb) l cpu-exec.c:278
273                    cc->do_interrupt(cpu);
274 #endif
275                    ret = env->exception_index;
276                    break;
277 #else
278                    cc->do_interrupt(cpu);
279                    env->exception_index = -1;
280 #endif
281                }
282            }


On Sun, Mar 31, 2013 at 8:33 PM, Anthony Green <green@moxielogic.com> wrote:

> Hi Dunrong,
>
>   I can't reproduce the segfault, but your patch still looks right to
> me.  Thanks!
>
> Signed-of-by: Anthony Green <green@moxielogic.com>
>
> AG
>
>
> On Sat, Mar 30, 2013 at 9:35 PM, Dunrong Huang <huangdr@cloud-times.com>
> wrote:
> > The value of "do_interrupt" member of CPUClass shoule be set to a
> > target-specific function, or it will lead to a segfault like below:
> >
> > $ moxie-softmmu/qemu-system-moxie -M moxiesim
> > Segmentation fault
> >
> > Cc: Anthony Green <green@moxielogic.com>
> > Cc: Blue Swirl <blauwirbel@gmail.com>
> > Cc: Andreas Färber <afaerber@suse.de>
> > Signed-off-by: Dunrong Huang <huangdr@cloud-times.com>
> > ---
> >  target-moxie/cpu.c    | 1 +
> >  target-moxie/cpu.h    | 2 +-
> >  target-moxie/helper.c | 7 +++++--
> >  3 files changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
> > index c17d3f0..c0855f0 100644
> > --- a/target-moxie/cpu.c
> > +++ b/target-moxie/cpu.c
> > @@ -98,6 +98,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void
> *data)
> >      cc->class_by_name = moxie_cpu_class_by_name;
> >
> >      dc->vmsd = &vmstate_moxie_cpu;
> > +    cc->do_interrupt = moxie_cpu_do_interrupt;
> >  }
> >
> >  static void moxielite_initfn(Object *obj)
> > diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
> > index b96236f..988729a 100644
> > --- a/target-moxie/cpu.h
> > +++ b/target-moxie/cpu.h
> > @@ -117,7 +117,7 @@ static inline MoxieCPU
> *moxie_env_get_cpu(CPUMoxieState *env)
> >
> >  MoxieCPU *cpu_moxie_init(const char *cpu_model);
> >  int cpu_moxie_exec(CPUMoxieState *s);
> > -void do_interrupt(CPUMoxieState *env);
> > +void moxie_cpu_do_interrupt(CPUState *cs);
> >  void moxie_translate_init(void);
> >  int cpu_moxie_signal_handler(int host_signum, void *pinfo,
> >                               void *puc);
> > diff --git a/target-moxie/helper.c b/target-moxie/helper.c
> > index 8604ce8..6e0ac2a 100644
> > --- a/target-moxie/helper.c
> > +++ b/target-moxie/helper.c
> > @@ -102,7 +102,7 @@ void helper_debug(CPUMoxieState *env)
> >
> >  #if defined(CONFIG_USER_ONLY)
> >
> > -void do_interrupt(CPUState *env)
> > +void moxie_cpu_do_interrupt(CPUState *env)
> >  {
> >      env->exception_index = -1;
> >  }
> > @@ -147,8 +147,11 @@ int cpu_moxie_handle_mmu_fault(CPUMoxieState *env,
> target_ulong address,
> >  }
> >
> >
> > -void do_interrupt(CPUMoxieState *env)
> > +void moxie_cpu_do_interrupt(CPUState *cs)
> >  {
> > +    MoxieCPU *cpu = MOXIE_CPU(cs);
> > +    CPUMoxieState *env = &cpu->env;
> > +
> >      switch (env->exception_index) {
> >      case MOXIE_EX_BREAK:
> >          break;
> > --
> > 1.8.1.5
> >
>
>
Andreas Färber - March 31, 2013, 5:01 p.m.
Am 31.03.2013 03:35, schrieb Dunrong Huang:
> The value of "do_interrupt" member of CPUClass shoule be set to a
> target-specific function, or it will lead to a segfault like below:
> 
> $ moxie-softmmu/qemu-system-moxie -M moxiesim
> Segmentation fault
> 
> Cc: Anthony Green <green@moxielogic.com>
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Dunrong Huang <huangdr@cloud-times.com>
> ---
>  target-moxie/cpu.c    | 1 +
>  target-moxie/cpu.h    | 2 +-
>  target-moxie/helper.c | 7 +++++--
>  3 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
> index c17d3f0..c0855f0 100644
> --- a/target-moxie/cpu.c
> +++ b/target-moxie/cpu.c
> @@ -98,6 +98,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data)
>      cc->class_by_name = moxie_cpu_class_by_name;
>  
>      dc->vmsd = &vmstate_moxie_cpu;
> +    cc->do_interrupt = moxie_cpu_do_interrupt;
>  }
>  
>  static void moxielite_initfn(Object *obj)
> diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
> index b96236f..988729a 100644
> --- a/target-moxie/cpu.h
> +++ b/target-moxie/cpu.h
> @@ -117,7 +117,7 @@ static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
>  
>  MoxieCPU *cpu_moxie_init(const char *cpu_model);
>  int cpu_moxie_exec(CPUMoxieState *s);
> -void do_interrupt(CPUMoxieState *env);
> +void moxie_cpu_do_interrupt(CPUState *cs);
>  void moxie_translate_init(void);
>  int cpu_moxie_signal_handler(int host_signum, void *pinfo,
>                               void *puc);
> diff --git a/target-moxie/helper.c b/target-moxie/helper.c
> index 8604ce8..6e0ac2a 100644
> --- a/target-moxie/helper.c
> +++ b/target-moxie/helper.c
> @@ -102,7 +102,7 @@ void helper_debug(CPUMoxieState *env)
>  
>  #if defined(CONFIG_USER_ONLY)
>  
> -void do_interrupt(CPUState *env)
> +void moxie_cpu_do_interrupt(CPUState *env)
>  {
>      env->exception_index = -1;
>  }

Anthony, CPUState should not be named "env" but rather "cs" (to reserve
"cpu" for MoxieCPU). That's unrelated to this patch though.

> @@ -147,8 +147,11 @@ int cpu_moxie_handle_mmu_fault(CPUMoxieState *env, target_ulong address,
>  }
>  
>  
> -void do_interrupt(CPUMoxieState *env)
> +void moxie_cpu_do_interrupt(CPUState *cs)
>  {
> +    MoxieCPU *cpu = MOXIE_CPU(cs);
> +    CPUMoxieState *env = &cpu->env;
> +
>      switch (env->exception_index) {
>      case MOXIE_EX_BREAK:
>          break;

That exception_index is used once from CPUMoxieState and once from
CPUState is telling me something is fishy here...

Are any test images available?

Hooking up cc->do_interrupt is the correct thing to do though, so that
could be sorted out later,

Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas
Blue Swirl - March 31, 2013, 6:54 p.m.
Thanks, applied.

On Sun, Mar 31, 2013 at 1:35 AM, Dunrong Huang <huangdr@cloud-times.com> wrote:
> The value of "do_interrupt" member of CPUClass shoule be set to a
> target-specific function, or it will lead to a segfault like below:
>
> $ moxie-softmmu/qemu-system-moxie -M moxiesim
> Segmentation fault
>
> Cc: Anthony Green <green@moxielogic.com>
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Dunrong Huang <huangdr@cloud-times.com>
> ---
>  target-moxie/cpu.c    | 1 +
>  target-moxie/cpu.h    | 2 +-
>  target-moxie/helper.c | 7 +++++--
>  3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
> index c17d3f0..c0855f0 100644
> --- a/target-moxie/cpu.c
> +++ b/target-moxie/cpu.c
> @@ -98,6 +98,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data)
>      cc->class_by_name = moxie_cpu_class_by_name;
>
>      dc->vmsd = &vmstate_moxie_cpu;
> +    cc->do_interrupt = moxie_cpu_do_interrupt;
>  }
>
>  static void moxielite_initfn(Object *obj)
> diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
> index b96236f..988729a 100644
> --- a/target-moxie/cpu.h
> +++ b/target-moxie/cpu.h
> @@ -117,7 +117,7 @@ static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
>
>  MoxieCPU *cpu_moxie_init(const char *cpu_model);
>  int cpu_moxie_exec(CPUMoxieState *s);
> -void do_interrupt(CPUMoxieState *env);
> +void moxie_cpu_do_interrupt(CPUState *cs);
>  void moxie_translate_init(void);
>  int cpu_moxie_signal_handler(int host_signum, void *pinfo,
>                               void *puc);
> diff --git a/target-moxie/helper.c b/target-moxie/helper.c
> index 8604ce8..6e0ac2a 100644
> --- a/target-moxie/helper.c
> +++ b/target-moxie/helper.c
> @@ -102,7 +102,7 @@ void helper_debug(CPUMoxieState *env)
>
>  #if defined(CONFIG_USER_ONLY)
>
> -void do_interrupt(CPUState *env)
> +void moxie_cpu_do_interrupt(CPUState *env)
>  {
>      env->exception_index = -1;
>  }
> @@ -147,8 +147,11 @@ int cpu_moxie_handle_mmu_fault(CPUMoxieState *env, target_ulong address,
>  }
>
>
> -void do_interrupt(CPUMoxieState *env)
> +void moxie_cpu_do_interrupt(CPUState *cs)
>  {
> +    MoxieCPU *cpu = MOXIE_CPU(cs);
> +    CPUMoxieState *env = &cpu->env;
> +
>      switch (env->exception_index) {
>      case MOXIE_EX_BREAK:
>          break;
> --
> 1.8.1.5
>
Anthony Green - March 31, 2013, 11:18 p.m.
Hi Andreas,

On Sun, Mar 31, 2013 at 1:01 PM, Andreas Färber <afaerber@suse.de> wrote:
> That exception_index is used once from CPUMoxieState and once from
> CPUState is telling me something is fishy here...
>
> Are any test images available?

I have some basic RTEMS based test apps, but nothing that generates an
interrupt (just exceptions).  That's because....

>
> Hooking up cc->do_interrupt is the correct thing to do though, so that
> could be sorted out later,

...I just implemented a basic interrupt controller and timer interrupt
device in an FPGA-based SoC last week (
http://moxielogic.org/blog/?p=734 ).  Let me implement this platform
support in QEMU, and maybe these issues will sort themselves out as I
do the work.

Thanks,

AG

>
> Reviewed-by: Andreas Färber <afaerber@suse.de>
>
> Andreas
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Patch

diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
index c17d3f0..c0855f0 100644
--- a/target-moxie/cpu.c
+++ b/target-moxie/cpu.c
@@ -98,6 +98,7 @@  static void moxie_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = moxie_cpu_class_by_name;
 
     dc->vmsd = &vmstate_moxie_cpu;
+    cc->do_interrupt = moxie_cpu_do_interrupt;
 }
 
 static void moxielite_initfn(Object *obj)
diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h
index b96236f..988729a 100644
--- a/target-moxie/cpu.h
+++ b/target-moxie/cpu.h
@@ -117,7 +117,7 @@  static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
 
 MoxieCPU *cpu_moxie_init(const char *cpu_model);
 int cpu_moxie_exec(CPUMoxieState *s);
-void do_interrupt(CPUMoxieState *env);
+void moxie_cpu_do_interrupt(CPUState *cs);
 void moxie_translate_init(void);
 int cpu_moxie_signal_handler(int host_signum, void *pinfo,
                              void *puc);
diff --git a/target-moxie/helper.c b/target-moxie/helper.c
index 8604ce8..6e0ac2a 100644
--- a/target-moxie/helper.c
+++ b/target-moxie/helper.c
@@ -102,7 +102,7 @@  void helper_debug(CPUMoxieState *env)
 
 #if defined(CONFIG_USER_ONLY)
 
-void do_interrupt(CPUState *env)
+void moxie_cpu_do_interrupt(CPUState *env)
 {
     env->exception_index = -1;
 }
@@ -147,8 +147,11 @@  int cpu_moxie_handle_mmu_fault(CPUMoxieState *env, target_ulong address,
 }
 
 
-void do_interrupt(CPUMoxieState *env)
+void moxie_cpu_do_interrupt(CPUState *cs)
 {
+    MoxieCPU *cpu = MOXIE_CPU(cs);
+    CPUMoxieState *env = &cpu->env;
+
     switch (env->exception_index) {
     case MOXIE_EX_BREAK:
         break;