Skip to contentSkip to conversation

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

PATCH Applied Dunrong Huang 4 participants 6 messages Mar 31, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-moxie: set do_interrupt to a target-specific helper function

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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Andreas Färber <[email protected]>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
target-moxie/cpu.c +1 -0
index c17d3f0..c0855f0 100644
@@ -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)
target-moxie/cpu.h +1 -1
index b96236f..988729a 100644
@@ -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);
target-moxie/helper.c +5 -2
index 8604ce8..6e0ac2a 100644
@@ -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;
Signature · 1 line
1.8.1.5
#1 lore raw

Hi Dunrong,

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

AG

Quoted 70 lines · 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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Andreas Färber <[email protected]>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
target-moxie/cpu.c +1 -0
index c17d3f0..c0855f0 100644
@@ -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)
target-moxie/cpu.h +1 -1
index b96236f..988729a 100644
@@ -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);
target-moxie/helper.c +5 -3
index 8604ce8..6e0ac2a 100644
@@ -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

author
#2 lore raw

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
Quoted 1 line

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 }

Quoted 87 lines · Anthony Green

Hi Dunrong,

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

AG

target-moxie/cpu.c static void moxie_cpu_class_init(ObjectClass *oc, void

Quoted 21 lines · 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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Andreas Färber <[email protected]>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
target-moxie/cpu.c +0 -0
index c17d3f0..c0855f0 100644
@@ -98,6 +98,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void

*data)

target-moxie/cpu.h static inline MoxieCPU

Quoted 12 lines
target-moxie/cpu.c +1 -0
     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)
target-moxie/cpu.h +0 -0
index b96236f..988729a 100644
@@ -117,7 +117,7 @@ static inline MoxieCPU

*moxie_env_get_cpu(CPUMoxieState *env)

target-moxie/helper.c int cpu_moxie_handle_mmu_fault(CPUMoxieState *env,

Quoted 22 lines
target-moxie/cpu.h +1 -1
 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);
target-moxie/helper.c +1 -1
index 8604ce8..6e0ac2a 100644
@@ -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,

Quoted 15 lines
target-moxie/helper.c +4 -2
 }
 
 
-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

Signature · 28 lines
*
Best Regards,
------------------------------
*
*黄敦荣
Linux **Developer
**北京云端时代科技有限公司 **
  *
*电 话:+86 10 62415355-620*
*传 真:+86 10 62415355-609*
 *手 机:+86 18618450559*
 *邮 箱: [email protected]*
*地址: 北京市海淀区中关村南4街18号紫金数码园3号楼1层(100190)*
*
云基地: 北京亦庄经济技术开发区北工大软件园(100176)
 ------------------------------

北京云端时代科技有限公司邮件法律声明:

本邮件所有信息及附件内容版权、知识产权归我公司所有,未经事先书面许可,禁止复制、转载、传播、储存。

CLOUD TIMES EMAIL NOTICE:

The information and any attachments contained in this email is all
copyright and intellectual property of our company reserved. Without prior
written permission of any copy, reproduce, propagation or storage will be
prohibited.
*
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dunrong Huang

Am 31.03.2013 03:35, schrieb Dunrong Huang:

Quoted 46 lines

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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Andreas Färber <[email protected]>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
target-moxie/cpu.c +1 -0
index c17d3f0..c0855f0 100644
@@ -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)
target-moxie/cpu.h +1 -1
index b96236f..988729a 100644
@@ -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);
target-moxie/helper.c +0 -0
index 8604ce8..6e0ac2a 100644

target-moxie/helper.c void helper_debug(CPUMoxieState *env) · line 108

Quoted 8 lines
target-moxie/helper.c +1 -1
@@ -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.

target-moxie/helper.c int cpu_moxie_handle_mmu_fault(CPUMoxieState *env, target_ulong address, · line 157

Quoted 13 lines
target-moxie/helper.c +4 -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;

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,

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw

Hi Andreas,

Quoted 4 lines · Andreas Färber

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

Quoted 3 lines

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

Quoted 8 lines

Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Applied
#5 lore raw
In reply to Dunrong Huang

Thanks, applied.

Quoted 70 lines · 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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Andreas Färber <[email protected]>
---
 target-moxie/cpu.c    | 1 +
 target-moxie/cpu.h    | 2 +-
 target-moxie/helper.c | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)
target-moxie/cpu.c +1 -0
index c17d3f0..c0855f0 100644
@@ -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)
target-moxie/cpu.h +1 -1
index b96236f..988729a 100644
@@ -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);
target-moxie/helper.c +5 -3
index 8604ce8..6e0ac2a 100644
@@ -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