Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/07/2013 03:29 PM, Peter Maydell wrote: > On 7 October 2013 22:06, Fabien Chouteau wrote: >> On 10/07/2013 01:45 PM, Peter Maydell wrote: >>> On 7 October 2013 19:11, Fabien Chouteau wrote: On 10/04/2013 07:49 PM, Peter Maydell wrote: > On 5 October 2013 01:57, Fabien Chouteau wrote: >> +extern const MonitorDef i386_monitor_defs[]; > > Declare this in cpu-qom.h, rather than having an > extern declaration in a .c file. > >> Sorry I sent the email too quickly. It looks like a circular dependency >> >> In file included from /home/chouteau/src/qemu-main/target-arm/cpu.h:294:0, >> from >> /home/chouteau/src/qemu-main/include/monitor/monitor_def.h:4, >> from /home/chouteau/src/qemu-main/target-arm/monitor.c:20: >> /home/chouteau/src/qemu-main/target-arm/cpu-qom.h:184:25: error: array type >> has incomplete element type >> make[1]: *** [target-arm/monitor.o] Error 1 > > I think you should be able to declare it as > extern const MonitorDef *i386_monitor_defs; > > then you don't need to include monitor_def.h from cpu-qom.h. > (untested, but the typedef should be sufficient for this) > /home/chouteau/src/qemu-main/target-arm/monitor.c:22:19: error: conflicting types for ‘arm_monitor_defs’ /home/chouteau/src/qemu-main/target-arm/cpu-qom.h:183:26: note: previous declaration of ‘arm_monitor_defs’ was here cpu-qom.h is indirectly included in target-arm/monitor.c -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 7 October 2013 22:06, Fabien Chouteau wrote: > On 10/07/2013 01:45 PM, Peter Maydell wrote: >> On 7 October 2013 19:11, Fabien Chouteau wrote: >>> On 10/04/2013 07:49 PM, Peter Maydell wrote: On 5 October 2013 01:57, Fabien Chouteau wrote: > +extern const MonitorDef i386_monitor_defs[]; Declare this in cpu-qom.h, rather than having an extern declaration in a .c file. > Sorry I sent the email too quickly. It looks like a circular dependency > > In file included from /home/chouteau/src/qemu-main/target-arm/cpu.h:294:0, > from > /home/chouteau/src/qemu-main/include/monitor/monitor_def.h:4, > from /home/chouteau/src/qemu-main/target-arm/monitor.c:20: > /home/chouteau/src/qemu-main/target-arm/cpu-qom.h:184:25: error: array type > has incomplete element type > make[1]: *** [target-arm/monitor.o] Error 1 I think you should be able to declare it as extern const MonitorDef *i386_monitor_defs; then you don't need to include monitor_def.h from cpu-qom.h. (untested, but the typedef should be sufficient for this) -- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/07/2013 01:45 PM, Peter Maydell wrote: > On 7 October 2013 19:11, Fabien Chouteau wrote: >> On 10/04/2013 07:49 PM, Peter Maydell wrote: >>> On 5 October 2013 01:57, Fabien Chouteau wrote: > @@ -47,7 +48,9 @@ #include "hw/xen/xen.h" #include "hw/i386/apic_internal.h" #endif +#include "monitor/monitor_def.h" +extern const MonitorDef i386_monitor_defs[]; >>> >>> Declare this in cpu-qom.h, rather than having an >>> extern declaration in a .c file. >>> >> >> I didn't manage to do that. > > If you just say "I couldn't make that work" with no details, > there isn't much I can say beyond "try harder" :-) > If you say *why* you couldn't get it to work then I'm more > likely to either (a) suggest an approach that will work or > (b) accept that it really does have to be that way... > Sorry I sent the email too quickly. It looks like a circular dependency In file included from /home/chouteau/src/qemu-main/target-arm/cpu.h:294:0, from /home/chouteau/src/qemu-main/include/monitor/monitor_def.h:4, from /home/chouteau/src/qemu-main/target-arm/monitor.c:20: /home/chouteau/src/qemu-main/target-arm/cpu-qom.h:184:25: error: array type has incomplete element type make[1]: *** [target-arm/monitor.o] Error 1 monitor_def.h -> cpu.h -> cpu-qom.h -. ^ | |__/ -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 7 October 2013 19:11, Fabien Chouteau wrote: > On 10/04/2013 07:49 PM, Peter Maydell wrote: >> On 5 October 2013 01:57, Fabien Chouteau wrote: >> >> @@ -47,7 +48,9 @@ >>> #include "hw/xen/xen.h" >>> #include "hw/i386/apic_internal.h" >>> #endif >>> +#include "monitor/monitor_def.h" >>> >>> +extern const MonitorDef i386_monitor_defs[]; >> >> Declare this in cpu-qom.h, rather than having an >> extern declaration in a .c file. >> > > I didn't manage to do that. If you just say "I couldn't make that work" with no details, there isn't much I can say beyond "try harder" :-) If you say *why* you couldn't get it to work then I'm more likely to either (a) suggest an approach that will work or (b) accept that it really does have to be that way... thanks -- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/04/2013 07:49 PM, Peter Maydell wrote: > On 5 October 2013 01:57, Fabien Chouteau wrote: > >> @@ -47,7 +48,9 @@ >> #include "hw/xen/xen.h" >> #include "hw/i386/apic_internal.h" >> #endif >> +#include "monitor/monitor_def.h" >> >> +extern const MonitorDef i386_monitor_defs[]; > > Declare this in cpu-qom.h, rather than having an > extern declaration in a .c file. > I didn't manage to do that. > >> --- a/target-sparc/cpu-qom.h >> +++ b/target-sparc/cpu-qom.h >> @@ -21,7 +21,6 @@ >> #define QEMU_SPARC_CPU_QOM_H >> >> #include "qom/cpu.h" >> -#include "cpu.h" > > ...why have you deleted this #include ? > I thought I added it myself, that's why I removed it. -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Am 04.10.2013 19:49, schrieb Peter Maydell: > On 5 October 2013 01:57, Fabien Chouteau wrote: > >> --- a/target-sparc/cpu-qom.h >> +++ b/target-sparc/cpu-qom.h >> @@ -21,7 +21,6 @@ >> #define QEMU_SPARC_CPU_QOM_H >> >> #include "qom/cpu.h" >> -#include "cpu.h" > > ...why have you deleted this #include ? That's removing a circular include, I guess. If I get it as a separate patch I would apply it immediately ... well, in quotes, sorry... Andreas >> >> #ifdef TARGET_SPARC64 >> #define TYPE_SPARC_CPU "sparc64-cpu" -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 5 October 2013 01:57, Fabien Chouteau wrote: > --- a/target-i386/cpu-qom.h > +++ b/target-i386/cpu-qom.h > @@ -23,6 +23,7 @@ > #include "qom/cpu.h" > #include "cpu.h" > #include "qapi/error.h" > +#include "monitor/monitor_def.h" > #ifdef TARGET_X86_64 > #define TYPE_X86_CPU "x86_64-cpu" > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index b682802..616b7da 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -22,6 +22,7 @@ > #include > > #include "cpu.h" > +#include "cpu-qom.h" > #include "sysemu/kvm.h" > #include "sysemu/cpus.h" > #include "topology.h" > @@ -47,7 +48,9 @@ > #include "hw/xen/xen.h" > #include "hw/i386/apic_internal.h" > #endif > +#include "monitor/monitor_def.h" > > +extern const MonitorDef i386_monitor_defs[]; Declare this in cpu-qom.h, rather than having an extern declaration in a .c file. > --- a/target-sparc/cpu-qom.h > +++ b/target-sparc/cpu-qom.h > @@ -21,7 +21,6 @@ > #define QEMU_SPARC_CPU_QOM_H > > #include "qom/cpu.h" > -#include "cpu.h" ...why have you deleted this #include ? > > #ifdef TARGET_SPARC64 > #define TYPE_SPARC_CPU "sparc64-cpu" thanks -- PMM
[Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Everything has been moved to cpu specific directories (SPARC, PPC, i386). Signed-off-by: Fabien Chouteau --- include/monitor/monitor_def.h | 18 ++ include/qemu/typedefs.h |1 + include/qom/cpu.h |3 + monitor.c | 396 + target-i386/Makefile.objs |2 +- target-i386/cpu-qom.h |1 + target-i386/cpu.c |7 + target-i386/monitor.c | 62 +++ target-ppc/Makefile.objs |2 +- target-ppc/monitor.c | 234 target-ppc/translate_init.c |8 + target-sparc/Makefile.objs|2 +- target-sparc/cpu-qom.h|1 - target-sparc/cpu.c|7 + target-sparc/monitor.c| 138 ++ 15 files changed, 490 insertions(+), 392 deletions(-) create mode 100644 include/monitor/monitor_def.h create mode 100644 target-i386/monitor.c create mode 100644 target-ppc/monitor.c create mode 100644 target-sparc/monitor.c diff --git a/include/monitor/monitor_def.h b/include/monitor/monitor_def.h new file mode 100644 index 000..7d4e3b6 --- /dev/null +++ b/include/monitor/monitor_def.h @@ -0,0 +1,18 @@ +#ifndef _MONITOR_DEF_H_ +#define _MONITOR_DEF_H_ + +#include "cpu.h" + +CPUArchState *mon_get_cpu(void); + +#define MD_TLONG 0 +#define MD_I32 1 + +typedef struct MonitorDef { +const char *name; +int offset; +target_long (*get_value)(const struct MonitorDef *md, int val); +int type; +} MonitorDef; + +#endif /* ! _MONITOR_DEF_H_ */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 3205540..4465fe8 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -13,6 +13,7 @@ typedef struct AioContext AioContext; struct Monitor; typedef struct Monitor Monitor; typedef struct MigrationParams MigrationParams; +typedef struct MonitorDef MonitorDef; typedef struct Property Property; typedef struct PropertyInfo PropertyInfo; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 7739e00..07ad3ee 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -156,6 +156,7 @@ struct kvm_run; * @gdb_num_g_regs: Number of registers in GDB 'g' packets. * @next_cpu: Next CPU sharing TB cache. * @kvm_fd: vCPU file descriptor for KVM. + * @monitor_defs array of register definitions for monitor functions * * State of one CPU core or thread. */ @@ -198,6 +199,8 @@ struct CPUState { struct KVMState *kvm_state; struct kvm_run *kvm_run; +const MonitorDef *monitor_defs; + /* TODO Move common fields from CPUArchState here. */ int cpu_index; /* used by alpha TCG */ uint32_t halted; /* used by alpha, cris, ppc TCG */ diff --git a/monitor.c b/monitor.c index 74f3f1b..ce2c2af 100644 --- a/monitor.c +++ b/monitor.c @@ -37,6 +37,7 @@ #include "ui/qemu-spice.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" +#include "monitor/monitor_def.h" #include "monitor/readline.h" #include "ui/console.h" #include "sysemu/blockdev.h" @@ -1096,7 +1097,7 @@ int monitor_set_cpu(int cpu_index) return 0; } -static CPUArchState *mon_get_cpu(void) +CPUArchState *mon_get_cpu(void) { if (!cur_mon->mon_cpu) { monitor_set_cpu(0); @@ -2969,392 +2970,6 @@ static const mon_cmd_t qmp_cmds[] = { static const char *pch; static sigjmp_buf expr_env; -#define MD_TLONG 0 -#define MD_I32 1 - -typedef struct MonitorDef { -const char *name; -int offset; -target_long (*get_value)(const struct MonitorDef *md, int val); -int type; -} MonitorDef; - -#if defined(TARGET_I386) -static target_long monitor_get_pc (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->eip + env->segs[R_CS].base; -} -#endif - -#if defined(TARGET_PPC) -static target_long monitor_get_ccr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -unsigned int u; -int i; - -u = 0; -for (i = 0; i < 8; i++) -u |= env->crf[i] << (32 - (4 * i)); - -return u; -} - -static target_long monitor_get_msr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->msr; -} - -static target_long monitor_get_xer (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->xer; -} - -static target_long monitor_get_decr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_decr(env); -} - -static target_long monitor_get_tbu (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_tbu(env); -} - -static target_long monitor_get_tbl (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_tbl(env); -} -#endif - -#if defined(TARGET_SPARC) -#ifndef TARGET_SPARC64 -static target_long monitor_get_psr (const struct MonitorDef *md, int val) -{ -CPUArchState *env
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/01/2013 05:21 PM, Peter Maydell wrote: > The declaration should go in cpu-qom.h (again, compare > the gdb stuff), and it should be called "arm_monitor_defs", > "ppc_monitor_defs" etc, not arch_monitor_defs. (This > avoids issues if we ever manage to compile more than one > target CPU into a single qemu binary, and again, it follows > existing conventions). > monitor.h drag a lot of thing... In file included from /home/chouteau/src/qemu-main/include/monitor/monitor.h:7:0, from /home/chouteau/src/qemu-main/target-i386/cpu-qom.h:26, from /home/chouteau/src/qemu-main/target-i386/cpu.h:917, from /home/chouteau/src/qemu-main/include/qemu-common.h:116, from /home/chouteau/src/qemu-main/exec.c:27: /home/chouteau/src/qemu-main/include/block/block.h:187:59: error: unknown type name ‘QEMUIOVector’ Maybe MonitorDef can be in a specific file include/monitor/monitordef.h? included by monitor.c target-*/monitor.c and target-*/cpu.c -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 2 October 2013 00:13, Richard Henderson wrote: > On 10/01/2013 07:28 AM, Fabien Chouteau wrote: >> On 10/01/2013 04:00 AM, Richard Henderson wrote: >>> On 09/30/2013 08:57 AM, Fabien Chouteau wrote: +extern const MonitorDef arch_monitor_defs[]; >>> >>> This is supplied by target-foo/monitor.c, right? >>> Why in the world is it declared in generic code? >>> >> >> Yes, why? >> >>> Especially if it's only ever accessed via the >>> cpu->monitor_defs member? >>> >> >> To begin with, I though I'd put in in each target-*/cpu.c, then having >> it at only one place seemed more clean. I'm open to any suggestion. >> > > If you put it in a global header like that, it looks like the array is > part of the generic interface. But it isn't -- only the monitor_defs > member is. > > If it's declared in any header at all, as opposed to static and local > to cpu.c (why was a new monitor.c file chosen?) Keeps monitor specific stuff in one file for the target and avoids cpu.c gradually bloating into something enormous. Compare use of gdbstub.c for the gdb stub related target specific functions. The declaration should go in cpu-qom.h (again, compare the gdb stuff), and it should be called "arm_monitor_defs", "ppc_monitor_defs" etc, not arch_monitor_defs. (This avoids issues if we ever manage to compile more than one target CPU into a single qemu binary, and again, it follows existing conventions). -- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/01/2013 07:28 AM, Fabien Chouteau wrote: > On 10/01/2013 04:00 AM, Richard Henderson wrote: >> On 09/30/2013 08:57 AM, Fabien Chouteau wrote: >>> +extern const MonitorDef arch_monitor_defs[]; >> >> This is supplied by target-foo/monitor.c, right? >> Why in the world is it declared in generic code? >> > > Yes, why? > >> Especially if it's only ever accessed via the >> cpu->monitor_defs member? >> > > To begin with, I though I'd put in in each target-*/cpu.c, then having > it at only one place seemed more clean. I'm open to any suggestion. > If you put it in a global header like that, it looks like the array is part of the generic interface. But it isn't -- only the monitor_defs member is. If it's declared in any header at all, as opposed to static and local to cpu.c (why was a new monitor.c file chosen?), it should go into target-foo/cpu.h, where most of the other cpu-specific declarations go. r~
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 1 October 2013 23:23, Fabien Chouteau wrote: > On 10/01/2013 03:08 AM, Peter Maydell wrote: >> I like this generally, but this detail is wrong. These changes >> mean that these registers (and many others) are now described >> as being int64_t wide rather than target_long wide, so you'll >> find that on 32 bit x86 they will read/write incorrectly. >> This is why I suggested that you need to have target-i386/monitor.c >> do an >> #if TARGET_LONG_BITS == 32 >> #define MD_TLONG MD_I32 >> #else >> #define MD_TLONG MD_I64 >> #endif >> >> and then specifically mark these fields as MD_TLONG. > > This seems complicated. Is there a way to use target_long in monitor.h? I would prefer it if we didn't, because the monitor should not depend on target-specifics. So the monitor's interface to the CPU dependent parts should expose basic "always the same" types, and if a particular CPU happens to have CPU struct fields which are sometimes 32 bit and sometimes 64 bit then it has to deal with them itself. (Not every CPU has that kind of field.) -- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/01/2013 04:00 AM, Richard Henderson wrote: > On 09/30/2013 08:57 AM, Fabien Chouteau wrote: >> +extern const MonitorDef arch_monitor_defs[]; > > This is supplied by target-foo/monitor.c, right? > Why in the world is it declared in generic code? > Yes, why? > Especially if it's only ever accessed via the > cpu->monitor_defs member? > To begin with, I though I'd put in in each target-*/cpu.c, then having it at only one place seemed more clean. I'm open to any suggestion. -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 10/01/2013 03:08 AM, Peter Maydell wrote: > On 1 October 2013 00:57, Fabien Chouteau wrote: > >> +#define MD_I64 0 >> +#define MD_I32 1 > >> -#define MD_TLONG 0 >> -#define MD_I32 1 > >> -{ "eax", offsetof(CPUX86State, regs[0]) }, >> -{ "ecx", offsetof(CPUX86State, regs[1]) }, > >> +{ "eax", offsetof(CPUX86State, regs[0]) }, >> +{ "ecx", offsetof(CPUX86State, regs[1]) }, > > I like this generally, but this detail is wrong. These changes > mean that these registers (and many others) are now described > as being int64_t wide rather than target_long wide, so you'll > find that on 32 bit x86 they will read/write incorrectly. > This is why I suggested that you need to have target-i386/monitor.c > do an > #if TARGET_LONG_BITS == 32 > #define MD_TLONG MD_I32 > #else > #define MD_TLONG MD_I64 > #endif > > and then specifically mark these fields as MD_TLONG. This seems complicated. Is there a way to use target_long in monitor.h? -- Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 09/30/2013 08:57 AM, Fabien Chouteau wrote: > +extern const MonitorDef arch_monitor_defs[]; This is supplied by target-foo/monitor.c, right? Why in the world is it declared in generic code? Especially if it's only ever accessed via the cpu->monitor_defs member? r~
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
On 1 October 2013 00:57, Fabien Chouteau wrote: > +#define MD_I64 0 > +#define MD_I32 1 > -#define MD_TLONG 0 > -#define MD_I32 1 > -{ "eax", offsetof(CPUX86State, regs[0]) }, > -{ "ecx", offsetof(CPUX86State, regs[1]) }, > +{ "eax", offsetof(CPUX86State, regs[0]) }, > +{ "ecx", offsetof(CPUX86State, regs[1]) }, I like this generally, but this detail is wrong. These changes mean that these registers (and many others) are now described as being int64_t wide rather than target_long wide, so you'll find that on 32 bit x86 they will read/write incorrectly. This is why I suggested that you need to have target-i386/monitor.c do an #if TARGET_LONG_BITS == 32 #define MD_TLONG MD_I32 #else #define MD_TLONG MD_I64 #endif and then specifically mark these fields as MD_TLONG. (We could also get rid of that awkward mon_get_cpu() which is the only thing in monitor.h that has to be guarded by NEED_CPU_H, by having the function prototype for the callback functions just take a CPUState* (nb: not a CPUArchState*) rather than having them all call mon_get_cpu. But we can do that in another patch I guess.) -- PMM
[Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Everything has been moved to cpu specific directories (SPARC, PPC, i386). Signed-off-by: Fabien Chouteau --- include/monitor/monitor.h | 16 ++ include/qemu/typedefs.h |1 + include/qom/cpu.h |3 + monitor.c | 399 +-- target-i386/Makefile.objs |2 +- target-i386/cpu.c |6 +- target-i386/monitor.c | 63 +++ target-ppc/Makefile.objs|2 +- target-ppc/monitor.c| 234 + target-ppc/translate_init.c |5 + target-sparc/Makefile.objs |2 +- target-sparc/cpu.c |5 + target-sparc/monitor.c | 138 +++ 13 files changed, 482 insertions(+), 394 deletions(-) create mode 100644 target-i386/monitor.c create mode 100644 target-ppc/monitor.c create mode 100644 target-sparc/monitor.c diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 10fa0e3..208ed76 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -7,6 +7,22 @@ #include "block/block.h" #include "monitor/readline.h" +#ifdef NEED_CPU_H +CPUArchState *mon_get_cpu(void); +#endif + +#define MD_I64 0 +#define MD_I32 1 + +typedef struct MonitorDef { +const char *name; +int offset; +uint64_t (*get_value)(const struct MonitorDef *md, int val); +int type; +} MonitorDef; + +extern const MonitorDef arch_monitor_defs[]; + extern Monitor *cur_mon; extern Monitor *default_mon; diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 3205540..4465fe8 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -13,6 +13,7 @@ typedef struct AioContext AioContext; struct Monitor; typedef struct Monitor Monitor; typedef struct MigrationParams MigrationParams; +typedef struct MonitorDef MonitorDef; typedef struct Property Property; typedef struct PropertyInfo PropertyInfo; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 7739e00..07ad3ee 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -156,6 +156,7 @@ struct kvm_run; * @gdb_num_g_regs: Number of registers in GDB 'g' packets. * @next_cpu: Next CPU sharing TB cache. * @kvm_fd: vCPU file descriptor for KVM. + * @monitor_defs array of register definitions for monitor functions * * State of one CPU core or thread. */ @@ -198,6 +199,8 @@ struct CPUState { struct KVMState *kvm_state; struct kvm_run *kvm_run; +const MonitorDef *monitor_defs; + /* TODO Move common fields from CPUArchState here. */ int cpu_index; /* used by alpha TCG */ uint32_t halted; /* used by alpha, cris, ppc TCG */ diff --git a/monitor.c b/monitor.c index 74f3f1b..059fc72 100644 --- a/monitor.c +++ b/monitor.c @@ -1096,7 +1096,7 @@ int monitor_set_cpu(int cpu_index) return 0; } -static CPUArchState *mon_get_cpu(void) +CPUArchState *mon_get_cpu(void) { if (!cur_mon->mon_cpu) { monitor_set_cpu(0); @@ -2969,392 +2969,6 @@ static const mon_cmd_t qmp_cmds[] = { static const char *pch; static sigjmp_buf expr_env; -#define MD_TLONG 0 -#define MD_I32 1 - -typedef struct MonitorDef { -const char *name; -int offset; -target_long (*get_value)(const struct MonitorDef *md, int val); -int type; -} MonitorDef; - -#if defined(TARGET_I386) -static target_long monitor_get_pc (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->eip + env->segs[R_CS].base; -} -#endif - -#if defined(TARGET_PPC) -static target_long monitor_get_ccr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -unsigned int u; -int i; - -u = 0; -for (i = 0; i < 8; i++) -u |= env->crf[i] << (32 - (4 * i)); - -return u; -} - -static target_long monitor_get_msr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->msr; -} - -static target_long monitor_get_xer (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->xer; -} - -static target_long monitor_get_decr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_decr(env); -} - -static target_long monitor_get_tbu (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_tbu(env); -} - -static target_long monitor_get_tbl (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return cpu_ppc_load_tbl(env); -} -#endif - -#if defined(TARGET_SPARC) -#ifndef TARGET_SPARC64 -static target_long monitor_get_psr (const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); - -return cpu_get_psr(env); -} -#endif - -static target_long monitor_get_reg(const struct MonitorDef *md, int val) -{ -CPUArchState *env = mon_get_cpu(); -return env->regwptr[val]; -} -#endif - -static const MonitorDef monitor_defs[] = { -#ifdef TARGET_I386 - -#define SEG(