:p
atchew
Login
Convert target_monitor_defs() and target_monitor_defs() to CPUClass fields, adapting the 4 targets using these legacy code. Philippe Mathieu-Daudé (10): monitor: Extract completion declarations to 'monitor/hmp-completion.h' monitor: Forward-declare the MonitorDef type cpus: Introduce CPUClass::legacy_monitor_defs hook target/i386: Replace legacy target_monitor_defs -> legacy_monitor_defs target/m68k: Replace legacy target_monitor_defs -> legacy_monitor_defs target/sparc: Replace legacy target_monitor_defs -> legacy_monitor_defs monitor: Remove target_monitor_defs() cpus: Introduce CPUClass::legacy_monitor_get_register() hook target/riscv: Register target_get_monitor_def in CPUClass monitor: Remove target_get_monitor_def() MAINTAINERS | 1 + include/hw/core/cpu.h | 8 +++++++ include/monitor/hmp-completion.h | 40 ++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 28 ++-------------------- include/qemu/typedefs.h | 1 + target/i386/cpu.h | 2 ++ target/m68k/cpu.h | 2 ++ target/riscv/internals.h | 3 +++ target/sparc/cpu.h | 2 ++ chardev/char-hmp-cmds.c | 1 + migration/migration-hmp-cmds.c | 1 + monitor/hmp-target.c | 1 + monitor/hmp.c | 8 +++++-- net/net-hmp-cmds.c | 1 + qom/qom-hmp-cmds.c | 1 + stubs/target-get-monitor-def.c | 29 ----------------------- stubs/target-monitor-defs.c | 7 ------ system/qdev-monitor.c | 1 + system/runstate-hmp-cmds.c | 1 + target/i386/cpu.c | 1 + target/i386/monitor.c | 7 ++---- target/m68k/cpu.c | 1 + target/m68k/monitor.c | 5 +--- target/riscv/cpu.c | 1 + target/riscv/monitor.c | 4 +++- target/sparc/cpu.c | 3 +++ target/sparc/monitor.c | 9 +++---- trace/trace-hmp-cmds.c | 1 + ui/ui-hmp-cmds.c | 1 + stubs/meson.build | 2 -- 30 files changed, 91 insertions(+), 82 deletions(-) create mode 100644 include/monitor/hmp-completion.h delete mode 100644 stubs/target-get-monitor-def.c delete mode 100644 stubs/target-monitor-defs.c -- 2.53.0
Many files include "monitor/hmp.h", but few of them really need the completion declarations: move them to a distinct header. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- MAINTAINERS | 1 + include/monitor/hmp-completion.h | 40 ++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 21 ----------------- chardev/char-hmp-cmds.c | 1 + migration/migration-hmp-cmds.c | 1 + monitor/hmp-target.c | 1 + net/net-hmp-cmds.c | 1 + qom/qom-hmp-cmds.c | 1 + system/qdev-monitor.c | 1 + system/runstate-hmp-cmds.c | 1 + trace/trace-hmp-cmds.c | 1 + ui/ui-hmp-cmds.c | 1 + 12 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 include/monitor/hmp-completion.h diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: monitor/hmp* F: hmp.h F: hmp-commands*.hx F: include/monitor/hmp.h +F: include/monitor/hmp-completion.h F: tests/qtest/test-hmp.c F: include/qemu/qemu-print.h F: util/qemu-print.c diff --git a/include/monitor/hmp-completion.h b/include/monitor/hmp-completion.h new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/include/monitor/hmp-completion.h @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor Completion handlers + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HMP_COMPLETION_H +#define HMP_COMPLETION_H + +#include "qemu/readline.h" + +void object_add_completion(ReadLineState *rs, int nb_args, const char *str); +void object_del_completion(ReadLineState *rs, int nb_args, const char *str); +void device_add_completion(ReadLineState *rs, int nb_args, const char *str); +void device_del_completion(ReadLineState *rs, int nb_args, const char *str); +void sendkey_completion(ReadLineState *rs, int nb_args, const char *str); +void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str); +void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str); +void set_link_completion(ReadLineState *rs, int nb_args, const char *str); +void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str); +void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str); +void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str); +void info_trace_events_completion(ReadLineState *rs, int nb_args, + const char *str); +void trace_event_completion(ReadLineState *rs, int nb_args, const char *str); +void watchdog_action_completion(ReadLineState *rs, int nb_args, + const char *str); +void migrate_set_capability_completion(ReadLineState *rs, int nb_args, + const char *str); +void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, + const char *str); +void delvm_completion(ReadLineState *rs, int nb_args, const char *str); +void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); + +#endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict); void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict); void hmp_xen_event_inject(Monitor *mon, const QDict *qdict); void hmp_xen_event_list(Monitor *mon, const QDict *qdict); -void object_add_completion(ReadLineState *rs, int nb_args, const char *str); -void object_del_completion(ReadLineState *rs, int nb_args, const char *str); -void device_add_completion(ReadLineState *rs, int nb_args, const char *str); -void device_del_completion(ReadLineState *rs, int nb_args, const char *str); -void sendkey_completion(ReadLineState *rs, int nb_args, const char *str); -void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str); -void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str); -void set_link_completion(ReadLineState *rs, int nb_args, const char *str); -void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str); -void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str); -void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str); -void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str); -void trace_event_completion(ReadLineState *rs, int nb_args, const char *str); -void watchdog_action_completion(ReadLineState *rs, int nb_args, - const char *str); -void migrate_set_capability_completion(ReadLineState *rs, int nb_args, - const char *str); -void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, - const char *str); -void delvm_completion(ReadLineState *rs, int nb_args, const char *str); -void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); void hmp_rocker(Monitor *mon, const QDict *qdict); void hmp_rocker_ports(Monitor *mon, const QDict *qdict); void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict); diff --git a/chardev/char-hmp-cmds.c b/chardev/char-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-hmp-cmds.c +++ b/chardev/char-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "chardev/char.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-char.h" diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "block/qapi.h" #include "migration/snapshot.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ #include "net/slirp.h" #include "system/device_tree.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "block/block-hmp-cmds.h" #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" diff --git a/net/net-hmp-cmds.c b/net/net-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/net/net-hmp-cmds.c +++ b/net/net-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "migration/misc.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "net/net.h" #include "net/hub.h" diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/core/qdev.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-qom.h" diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index XXXXXXX..XXXXXXX 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/core/sysbus.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "monitor/qdev.h" #include "system/arch_init.h" diff --git a/system/runstate-hmp-cmds.c b/system/runstate-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/system/runstate-hmp-cmds.c +++ b/system/runstate-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "exec/cpu-common.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-run-state.h" diff --git a/trace/trace-hmp-cmds.c b/trace/trace-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/trace/trace-hmp-cmds.c +++ b/trace/trace-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-trace.h" diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/ui/ui-hmp-cmds.c +++ b/ui/ui-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include <spice/enums.h> #endif #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-ui.h" -- 2.53.0
Rather than having core header forced to include "monitor/hmp.h" to get the MonitorDef type declaration, forward-declare it in "qemu/typedefs.h". Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/monitor/hmp.h | 4 ++-- include/qemu/typedefs.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ #include "qemu/readline.h" #include "qapi/qapi-types-common.h" -typedef struct MonitorDef { +struct MonitorDef { const char *name; int offset; int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset); -} MonitorDef; +}; const MonitorDef *target_monitor_defs(void); int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -XXX,XX +XXX,XX @@ typedef struct MemoryRegionSection MemoryRegionSection; typedef struct MigrationIncomingState MigrationIncomingState; typedef struct MigrationState MigrationState; typedef struct Monitor Monitor; +typedef struct MonitorDef MonitorDef; typedef struct MSIMessage MSIMessage; typedef struct NetClientState NetClientState; typedef struct NetFilterState NetFilterState; -- 2.53.0
Allow targets to register their legacy target_monitor_defs() in CPUClass; check it first in get_monitor_def() otherwise fall back to previous per-target helper. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/hw/core/cpu.h | 3 +++ monitor/hmp.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -XXX,XX +XXX,XX @@ struct SysemuCPUOps; * @max_as: Maximum valid index used to refer to the address spaces supported by * the architecture, i.e., to refer to CPUAddressSpaces in * CPUState::cpu_ases. + * @legacy_monitor_defs: Array of MonitorDef entries. This field is legacy, + * use @gdb_core_xml_file to dump registers instead. * * Represents a CPU family or model. */ @@ -XXX,XX +XXX,XX @@ struct CPUClass { const char *gdb_core_xml_file; const char * (*gdb_arch_name)(CPUState *cpu); const char * (*gdb_get_core_xml_file)(CPUState *cpu); + const MonitorDef *legacy_monitor_defs; void (*disas_set_info)(const CPUState *cpu, disassemble_info *info); diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <dirent.h> +#include "hw/core/cpu.h" #include "hw/core/qdev.h" #include "monitor-internal.h" #include "monitor/hmp.h" @@ -XXX,XX +XXX,XX @@ void monitor_register_hmp_info_hrt(const char *name, */ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) { - const MonitorDef *md = target_monitor_defs(); CPUState *cs = mon_get_cpu(mon); + const MonitorDef *md = cs->cc->legacy_monitor_defs ?: target_monitor_defs(); void *ptr; uint64_t tmp = 0; int ret; -- 2.53.0
Expose x86_monitor_defs within target/i386/ and register it as CPUClass::legacy_monitor_defs hook. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- target/i386/cpu.h | 2 ++ target/i386/cpu.c | 1 + target/i386/monitor.c | 7 ++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index XXXXXXX..XXXXXXX 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -XXX,XX +XXX,XX @@ #include "qemu/timer.h" #include "standard-headers/asm-x86/kvm_para.h" +extern const MonitorDef *x86_monitor_defs; + #define XEN_NR_VIRQS 24 #ifdef TARGET_X86_64 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -XXX,XX +XXX,XX @@ static void x86_cpu_common_class_init(ObjectClass *oc, const void *data) cc->gdb_core_xml_file = "i386-32bit.xml"; #endif cc->disas_set_info = x86_disas_set_info; + cc->legacy_monitor_defs = x86_monitor_defs; dc->user_creatable = true; diff --git a/target/i386/monitor.c b/target/i386/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -XXX,XX +XXX,XX @@ static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md, return env->eip + env->segs[R_CS].base; } -const MonitorDef monitor_defs[] = { +static const MonitorDef monitor_defs[] = { #define SEG(name, seg) \ { name ".limit", offsetof(CPUX86State, segs[seg].limit) }, SEG("cs", R_CS) @@ -XXX,XX +XXX,XX @@ const MonitorDef monitor_defs[] = { { NULL }, }; -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} +const MonitorDef *x86_monitor_defs = monitor_defs; -- 2.53.0
Expose m68k_monitor_defs within target/m68k/ and register it as CPUClass::legacy_monitor_defs hook. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- target/m68k/cpu.h | 2 ++ target/m68k/cpu.c | 1 + target/m68k/monitor.c | 5 +---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -XXX,XX +XXX,XX @@ #include "qemu/cpu-float.h" #include "cpu-qom.h" +extern const MonitorDef *m68k_monitor_defs; + #define OS_BYTE 0 #define OS_WORD 1 #define OS_LONG 2 diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, const void *data) cc->sysemu_ops = &m68k_sysemu_ops; #endif cc->disas_set_info = m68k_cpu_disas_set_info; + cc->legacy_monitor_defs = m68k_monitor_defs; cc->tcg_ops = &m68k_tcg_ops; } diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/monitor.c +++ b/target/m68k/monitor.c @@ -XXX,XX +XXX,XX @@ static const MonitorDef monitor_defs[] = { { NULL }, }; -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} +const MonitorDef *m68k_monitor_defs = monitor_defs; -- 2.53.0
Expose sparc64_monitor_defs within target/sparc/ and register it as CPUClass::legacy_monitor_defs hook (taking care to not register it on 32-bit SPARC target). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- target/sparc/cpu.h | 2 ++ target/sparc/cpu.c | 3 +++ target/sparc/monitor.c | 9 +++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -XXX,XX +XXX,XX @@ #include "exec/target_long.h" #include "qemu/cpu-float.h" +extern const MonitorDef *sparc64_monitor_defs; + #if !defined(TARGET_SPARC64) #define TARGET_DPREGS 16 #define TARGET_FCCREGS 1 diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, const void *data) cc->gdb_core_xml_file = "sparc64-cpu.xml"; #else cc->gdb_core_xml_file = "sparc32-cpu.xml"; +#endif +#if defined(TARGET_SPARC64) + cc->legacy_monitor_defs = sparc64_monitor_defs; #endif cc->tcg_ops = &sparc_tcg_ops; } diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) dump_mmu(env1); } -const MonitorDef monitor_defs[] = { #ifdef TARGET_SPARC64 +static const MonitorDef monitor_defs[] = { { "asi", offsetof(CPUSPARCState, asi) }, { "pstate", offsetof(CPUSPARCState, pstate) }, { "cansave", offsetof(CPUSPARCState, cansave) }, @@ -XXX,XX +XXX,XX @@ const MonitorDef monitor_defs[] = { { "otherwin", offsetof(CPUSPARCState, otherwin) }, { "wstate", offsetof(CPUSPARCState, wstate) }, { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, -#endif { NULL }, }; -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} +const MonitorDef *sparc64_monitor_defs = monitor_defs; +#endif -- 2.53.0
target_monitor_defs() is now only a stub. Remove as pointless. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/monitor/hmp.h | 1 - monitor/hmp.c | 2 +- stubs/target-monitor-defs.c | 7 ------- stubs/meson.build | 1 - 4 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 stubs/target-monitor-defs.c diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ struct MonitorDef { int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset); }; -const MonitorDef *target_monitor_defs(void); int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); CPUArchState *mon_get_cpu_env(Monitor *mon); diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ void monitor_register_hmp_info_hrt(const char *name, int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) { CPUState *cs = mon_get_cpu(mon); - const MonitorDef *md = cs->cc->legacy_monitor_defs ?: target_monitor_defs(); + const MonitorDef *md = cs->cc->legacy_monitor_defs; void *ptr; uint64_t tmp = 0; int ret; diff --git a/stubs/target-monitor-defs.c b/stubs/target-monitor-defs.c deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/stubs/target-monitor-defs.c +++ /dev/null @@ -XXX,XX +XXX,XX @@ -#include "qemu/osdep.h" -#include "monitor/hmp.h" - -const MonitorDef *target_monitor_defs(void) -{ - return NULL; -} diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system endif stub_ss.add(files('kvm.c')) stub_ss.add(files('target-get-monitor-def.c')) - stub_ss.add(files('target-monitor-defs.c')) stub_ss.add(files('win32-kbd-hook.c')) stub_ss.add(files('xen-hw-stub.c')) stub_ss.add(files('monitor-arm-gic.c')) -- 2.53.0
Allow targets to register their legacy target_get_monitor_def() in CPUClass; check it first in get_monitor_def() otherwise fall back to previous per-target helper. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/hw/core/cpu.h | 5 +++++ monitor/hmp.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -XXX,XX +XXX,XX @@ struct SysemuCPUOps; * CPUState::cpu_ases. * @legacy_monitor_defs: Array of MonitorDef entries. This field is legacy, * use @gdb_core_xml_file to dump registers instead. + * @legacy_monitor_get_register: Callback to fill @pval with register @name. + * This field is legacy, use @gdb_core_xml_file + * to dump registers instead. * * Represents a CPU family or model. */ @@ -XXX,XX +XXX,XX @@ struct CPUClass { const char * (*gdb_arch_name)(CPUState *cpu); const char * (*gdb_get_core_xml_file)(CPUState *cpu); const MonitorDef *legacy_monitor_defs; + int (*legacy_monitor_get_register)(CPUState *cs, const char *name, + uint64_t *pval); void (*disas_set_info)(const CPUState *cpu, disassemble_info *info); diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) } } - ret = target_get_monitor_def(cs, name, &tmp); + if (cs->cc->legacy_monitor_get_register) { + ret = cs->cc->legacy_monitor_get_register(cs, name, &tmp); + } else { + ret = target_get_monitor_def(cs, name, &tmp); + } if (!ret) { *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp; } -- 2.53.0
Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as CPUClass::legacy_monitor_get_register() handler. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- target/riscv/internals.h | 3 +++ target/riscv/cpu.c | 1 + target/riscv/monitor.c | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) return (first_word & 3) == 3 ? 4 : 2; } +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name, + uint64_t *pval); + #endif diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_common_class_init(ObjectClass *c, const void *data) cc->get_arch_id = riscv_get_arch_id; #endif cc->gdb_arch_name = riscv_gdb_arch_name; + cc->legacy_monitor_get_register = riscv_monitor_get_register_legacy; #ifdef CONFIG_TCG cc->tcg_ops = &riscv_tcg_ops; #endif /* CONFIG_TCG */ diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/monitor.c +++ b/target/riscv/monitor.c @@ -XXX,XX +XXX,XX @@ #include "monitor/monitor.h" #include "monitor/hmp.h" #include "system/memory.h" +#include "internals.h" #ifdef TARGET_RISCV64 #define PTE_HEADER_FIELDS "vaddr paddr "\ @@ -XXX,XX +XXX,XX @@ static bool reg_is_vreg(const char *name) return false; } -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name, + uint64_t *pval) { CPURISCVState *env = &RISCV_CPU(cs)->env; target_ulong val = 0; -- 2.53.0
target_get_monitor_def() is now only a stub. Remove as pointless. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/monitor/hmp.h | 2 -- monitor/hmp.c | 7 +++---- stubs/target-get-monitor-def.c | 29 ----------------------------- stubs/meson.build | 1 - 4 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 stubs/target-get-monitor-def.c diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ struct MonitorDef { int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset); }; -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); - CPUArchState *mon_get_cpu_env(Monitor *mon); CPUState *mon_get_cpu(Monitor *mon); diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) } } - if (cs->cc->legacy_monitor_get_register) { - ret = cs->cc->legacy_monitor_get_register(cs, name, &tmp); - } else { - ret = target_get_monitor_def(cs, name, &tmp); + if (!cs->cc->legacy_monitor_get_register) { + return -1; } + ret = cs->cc->legacy_monitor_get_register(cs, name, &tmp); if (!ret) { *pval = target_long_bits() == 32 ? (int32_t)tmp : tmp; } diff --git a/stubs/target-get-monitor-def.c b/stubs/target-get-monitor-def.c deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/stubs/target-get-monitor-def.c +++ /dev/null @@ -XXX,XX +XXX,XX @@ -/* - * Stub for target_get_monitor_def. - * - * Copyright IBM Corp., 2015 - * - * Author: Alexey Kardashevskiy <aik@ozlabs.ru> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "qemu/osdep.h" - -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); - -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) -{ - return -1; -} diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('igvm.c')) endif stub_ss.add(files('kvm.c')) - stub_ss.add(files('target-get-monitor-def.c')) stub_ss.add(files('win32-kbd-hook.c')) stub_ss.add(files('xen-hw-stub.c')) stub_ss.add(files('monitor-arm-gic.c')) -- 2.53.0
Missing review: 32 Since v3: - Rebased Since v2: - Addressed rth review comments Changes needed for the single binary (and heterogeneous emulation). Convert target_monitor_defs() and target_monitor_defs() to SysemuCPUOps fields, adapting the 4 targets using these 'legacy' code. Instead of filtering the commands per target / device at build time, add a new field to HMPCommand to filter them at runtime, allowing to compile the command array once. Philippe Mathieu-Daudé (32): monitor/hmp: : Include missing 'exec/target_long.h' header target/sparc/monitor: Dump all registers as 32-bit monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32 monitor: Extract completion declarations to 'monitor/hmp-completion.h' stubs: Rename monitor* -> qmp* files monitor/meson: Use SPICE with migration HMP commands monitor: Restrict monitor_set_cpu() method scope monitor: Make 'info via' a generic command monitor: Make Xen emulation commands generic ones system: Expose 'arch_init.h' as 'qemu/base-arch-defs.h' monitor: Introduce HMPCommand::arch_bitmask field hw/s390x: Reduce 'monitor/monitor.h' inclusions monitor: Do not check TARGET_S390X to build s390x commands monitor: Do not check TARGET_I386 to build target/i386/ commands monitor: Do not check TARGET_I386 to build 'info sgx' command monitor: Do not check TARGET_I386 to build 'info sev' command monitor: Do not check TARGET_I386/RISCV to build 'info mem' command monitor: Do not check multiple TARGET_* to build 'info tlb' command cpus: Introduce SysemuCPUOps::monitor_get_register() hook target/riscv: Register target_get_monitor_def in SysemuCPUOps monitor: Remove target_get_monitor_def() monitor: Have MonitorDef::get_value() always return int64_t type monitor: Reduce target-specific methods further monitor: Remove 'monitor/hmp-target.h' header monitor: Forward-declare the MonitorDef type cpus: Introduce SysemuCPUOps::monitor_defs hook target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/sparc: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs monitor: Remove target_monitor_defs() monitor: Merge hmp-target.c code within hmp-cmds.c monitor: Remove hmp_info_pic() left-over declaration MAINTAINERS | 16 ++- include/hw/core/sysemu-cpu-ops.h | 14 ++ include/hw/s390x/storage-attributes.h | 4 - include/hw/s390x/storage-keys.h | 3 - include/monitor/hmp-completion.h | 40 ++++++ include/monitor/hmp-target.h | 50 ------- include/monitor/hmp.h | 43 +++--- include/monitor/monitor.h | 1 - .../qemu/base-arch-defs.h | 10 +- include/qemu/typedefs.h | 1 + monitor/monitor-internal.h | 13 +- target/riscv/internals.h | 3 + chardev/char-hmp-cmds.c | 1 + hw/i386/kvm/xen-stubs.c | 12 ++ hw/i386/sgx-hmp-stub.c | 16 +++ hw/i386/sgx-stub.c | 6 - hw/i386/sgx.c | 1 - hw/misc/mos6522-stub.c | 16 +++ hw/pci/pci.c | 2 +- hw/s390x/s390-skeys.c | 2 + hw/s390x/s390-stattrib.c | 2 + migration/migration-hmp-cmds.c | 1 + monitor/hmp-cmds.c | 41 +++++- monitor/hmp-target.c | 124 ------------------ monitor/hmp.c | 45 ++++++- net/net-hmp-cmds.c | 1 + qom/qom-hmp-cmds.c | 1 + stubs/hmp-cmd-info_mem.c | 12 ++ stubs/hmp-cmd-info_sev.c | 16 +++ stubs/hmp-cmd-info_tlb.c | 12 ++ stubs/hmp-cmds-hw-s390x.c | 15 +++ stubs/hmp-cmds-target-i386.c | 13 ++ stubs/{monitor-arm-gic.c => qmp-arm-gic.c} | 0 ...or-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} | 0 .../{monitor-cpu-s390x.c => qmp-cpu-s390x.c} | 0 stubs/{monitor-cpu.c => qmp-cpu.c} | 0 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} | 0 stubs/{monitor-i386-sev.c => qmp-i386-sev.c} | 0 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} | 0 stubs/{monitor-i386-xen.c => qmp-i386-xen.c} | 0 stubs/target-get-monitor-def.c | 29 ---- stubs/target-monitor-defs.c | 7 - system/arch_init.c | 2 +- system/qdev-monitor.c | 3 +- system/runstate-hmp-cmds.c | 1 + system/vl.c | 2 +- target/i386/cpu-apic.c | 1 - target/i386/cpu.c | 29 ++++ target/i386/monitor.c | 26 ---- target/i386/sev-system-stub.c | 6 - target/i386/sev.c | 1 - target/m68k/cpu.c | 18 +++ target/m68k/monitor.c | 22 ---- target/ppc/monitor.c | 2 - target/riscv/cpu.c | 1 + target/riscv/monitor.c | 12 +- target/sh4/monitor.c | 1 - target/sparc/cpu.c | 19 +++ target/sparc/monitor.c | 19 --- target/xtensa/monitor.c | 1 - trace/trace-hmp-cmds.c | 1 + ui/ui-hmp-cmds.c | 1 + hmp-commands-info.hx | 26 ++-- hmp-commands.hx | 13 +- hw/i386/meson.build | 1 + hw/misc/meson.build | 1 + migration/meson.build | 2 +- monitor/meson.build | 5 +- stubs/meson.build | 23 ++-- 69 files changed, 425 insertions(+), 387 deletions(-) create mode 100644 include/monitor/hmp-completion.h delete mode 100644 include/monitor/hmp-target.h rename system/arch_init.h => include/qemu/base-arch-defs.h (92%) create mode 100644 hw/i386/sgx-hmp-stub.c create mode 100644 hw/misc/mos6522-stub.c delete mode 100644 monitor/hmp-target.c create mode 100644 stubs/hmp-cmd-info_mem.c create mode 100644 stubs/hmp-cmd-info_sev.c create mode 100644 stubs/hmp-cmd-info_tlb.c create mode 100644 stubs/hmp-cmds-hw-s390x.c create mode 100644 stubs/hmp-cmds-target-i386.c rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%) rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%) rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%) rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%) rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%) rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%) rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%) rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%) delete mode 100644 stubs/target-get-monitor-def.c delete mode 100644 stubs/target-monitor-defs.c -- 2.53.0
The "exec/target_long.h" header is indirectly included, pulled via "cpu.h" -> "exec/cpu-defs.h". Include it explicitly otherwise we'd get when removing the latter: monitor/hmp-target.h:35:5: error: type name requires a specifier or qualifier 35 | target_long (*get_value)(Monitor *mon, const struct MonitorDef *md, | ^ Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- include/monitor/hmp-target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -XXX,XX +XXX,XX @@ typedef struct MonitorDef MonitorDef; #ifdef COMPILING_PER_TARGET -#include "cpu.h" +#include "exec/target_long.h" struct MonitorDef { const char *name; int offset; -- 2.53.0
All these SPARC64 registers are 32-bit since their introduction in commit 3475187dd81 ("sparc64 merge"), see target/sparc/cpu.h: 511 #if defined(TARGET_SPARC64) ... 515 uint32_t asi; 516 uint32_t pstate; ... 519 uint32_t cansave, canrestore, otherwin, wstate, cleanwin; Set MonitorDef::type to MD_I32 to dump them as 32-bit. This removes a pointless unsigned sign-extension on 64-bit binary. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- target/sparc/monitor.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) const MonitorDef monitor_defs[] = { #ifdef TARGET_SPARC64 - { "asi", offsetof(CPUSPARCState, asi) }, - { "pstate", offsetof(CPUSPARCState, pstate) }, - { "cansave", offsetof(CPUSPARCState, cansave) }, - { "canrestore", offsetof(CPUSPARCState, canrestore) }, - { "otherwin", offsetof(CPUSPARCState, otherwin) }, - { "wstate", offsetof(CPUSPARCState, wstate) }, - { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, + { "asi", offsetof(CPUSPARCState, asi), NULL, MD_I32 }, + { "pstate", offsetof(CPUSPARCState, pstate), NULL, MD_I32 }, + { "cansave", offsetof(CPUSPARCState, cansave), NULL, MD_I32 }, + { "canrestore", offsetof(CPUSPARCState, canrestore), NULL, MD_I32 }, + { "otherwin", offsetof(CPUSPARCState, otherwin), NULL, MD_I32 }, + { "wstate", offsetof(CPUSPARCState, wstate), NULL, MD_I32 }, + { "cleanwin", offsetof(CPUSPARCState, cleanwin), NULL, MD_I32 }, #endif { NULL }, }; -- 2.53.0
None of the few targets still using MonitorDef use MD_TLONG, they either use MD_I32 or the %get_value handler. Remove the MonitorDef::type and its definitions altogether: simply check for the %get_value handler, if NULL then consider 32-bit. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- include/monitor/hmp-target.h | 4 ---- monitor/hmp-target.c | 12 +----------- target/i386/monitor.c | 2 +- target/m68k/monitor.c | 24 ++++++++++++------------ target/sparc/monitor.c | 14 +++++++------- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -XXX,XX +XXX,XX @@ struct MonitorDef { int offset; target_long (*get_value)(Monitor *mon, const struct MonitorDef *md, int val); - int type; }; #endif -#define MD_TLONG 0 -#define MD_I32 1 - const MonitorDef *target_monitor_defs(void); int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) } else { CPUArchState *env = mon_get_cpu_env(mon); ptr = (uint8_t *)env + md->offset; - switch(md->type) { - case MD_I32: - *pval = *(int32_t *)ptr; - break; - case MD_TLONG: - *pval = *(target_long *)ptr; - break; - default: - *pval = 0; - break; - } + *pval = *(int32_t *)ptr; } return 0; } diff --git a/target/i386/monitor.c b/target/i386/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -XXX,XX +XXX,XX @@ static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md, const MonitorDef monitor_defs[] = { #define SEG(name, seg) \ - { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_I32 }, + { name ".limit", offsetof(CPUX86State, segs[seg].limit) }, SEG("cs", R_CS) SEG("ds", R_DS) SEG("es", R_ES) diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/monitor.c +++ b/target/m68k/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) } static const MonitorDef monitor_defs[] = { - { "ssp", offsetof(CPUM68KState, sp[0]), NULL, MD_I32 }, - { "usp", offsetof(CPUM68KState, sp[1]), NULL, MD_I32 }, - { "isp", offsetof(CPUM68KState, sp[2]), NULL, MD_I32 }, - { "sfc", offsetof(CPUM68KState, sfc), NULL, MD_I32 }, - { "dfc", offsetof(CPUM68KState, dfc), NULL, MD_I32 }, - { "urp", offsetof(CPUM68KState, mmu.urp), NULL, MD_I32 }, - { "srp", offsetof(CPUM68KState, mmu.srp), NULL, MD_I32 }, - { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]), NULL, MD_I32 }, - { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]), NULL, MD_I32 }, - { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]), NULL, MD_I32 }, - { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]), NULL, MD_I32 }, - { "mmusr", offsetof(CPUM68KState, mmu.mmusr), NULL, MD_I32 }, + { "ssp", offsetof(CPUM68KState, sp[0]) }, + { "usp", offsetof(CPUM68KState, sp[1]) }, + { "isp", offsetof(CPUM68KState, sp[2]) }, + { "sfc", offsetof(CPUM68KState, sfc) }, + { "dfc", offsetof(CPUM68KState, dfc) }, + { "urp", offsetof(CPUM68KState, mmu.urp) }, + { "srp", offsetof(CPUM68KState, mmu.srp) }, + { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) }, + { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) }, + { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) }, + { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) }, + { "mmusr", offsetof(CPUM68KState, mmu.mmusr) }, { NULL }, }; diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) const MonitorDef monitor_defs[] = { #ifdef TARGET_SPARC64 - { "asi", offsetof(CPUSPARCState, asi), NULL, MD_I32 }, - { "pstate", offsetof(CPUSPARCState, pstate), NULL, MD_I32 }, - { "cansave", offsetof(CPUSPARCState, cansave), NULL, MD_I32 }, - { "canrestore", offsetof(CPUSPARCState, canrestore), NULL, MD_I32 }, - { "otherwin", offsetof(CPUSPARCState, otherwin), NULL, MD_I32 }, - { "wstate", offsetof(CPUSPARCState, wstate), NULL, MD_I32 }, - { "cleanwin", offsetof(CPUSPARCState, cleanwin), NULL, MD_I32 }, + { "asi", offsetof(CPUSPARCState, asi) }, + { "pstate", offsetof(CPUSPARCState, pstate) }, + { "cansave", offsetof(CPUSPARCState, cansave) }, + { "canrestore", offsetof(CPUSPARCState, canrestore) }, + { "otherwin", offsetof(CPUSPARCState, otherwin) }, + { "wstate", offsetof(CPUSPARCState, wstate) }, + { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, #endif { NULL }, }; -- 2.53.0
Many files include "monitor/hmp.h", but few of them really need the completion declarations: move them to a distinct header. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- MAINTAINERS | 2 ++ include/monitor/hmp-completion.h | 40 ++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 21 ----------------- chardev/char-hmp-cmds.c | 1 + migration/migration-hmp-cmds.c | 1 + monitor/hmp-target.c | 1 + net/net-hmp-cmds.c | 1 + qom/qom-hmp-cmds.c | 1 + system/qdev-monitor.c | 1 + system/runstate-hmp-cmds.c | 1 + trace/trace-hmp-cmds.c | 1 + ui/ui-hmp-cmds.c | 1 + 12 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 include/monitor/hmp-completion.h diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: monitor/monitor.c F: monitor/hmp* F: hmp.h F: hmp-commands*.hx +F: include/monitor/hmp.h +F: include/monitor/hmp-completion.h F: include/monitor/hmp-target.h F: tests/qtest/test-hmp.c F: include/qemu/qemu-print.h diff --git a/include/monitor/hmp-completion.h b/include/monitor/hmp-completion.h new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/include/monitor/hmp-completion.h @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor Completion handlers + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HMP_COMPLETION_H +#define HMP_COMPLETION_H + +#include "qemu/readline.h" + +void object_add_completion(ReadLineState *rs, int nb_args, const char *str); +void object_del_completion(ReadLineState *rs, int nb_args, const char *str); +void device_add_completion(ReadLineState *rs, int nb_args, const char *str); +void device_del_completion(ReadLineState *rs, int nb_args, const char *str); +void sendkey_completion(ReadLineState *rs, int nb_args, const char *str); +void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str); +void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str); +void set_link_completion(ReadLineState *rs, int nb_args, const char *str); +void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str); +void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str); +void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str); +void info_trace_events_completion(ReadLineState *rs, int nb_args, + const char *str); +void trace_event_completion(ReadLineState *rs, int nb_args, const char *str); +void watchdog_action_completion(ReadLineState *rs, int nb_args, + const char *str); +void migrate_set_capability_completion(ReadLineState *rs, int nb_args, + const char *str); +void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, + const char *str); +void delvm_completion(ReadLineState *rs, int nb_args, const char *str); +void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); + +#endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict); void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict); void hmp_xen_event_inject(Monitor *mon, const QDict *qdict); void hmp_xen_event_list(Monitor *mon, const QDict *qdict); -void object_add_completion(ReadLineState *rs, int nb_args, const char *str); -void object_del_completion(ReadLineState *rs, int nb_args, const char *str); -void device_add_completion(ReadLineState *rs, int nb_args, const char *str); -void device_del_completion(ReadLineState *rs, int nb_args, const char *str); -void sendkey_completion(ReadLineState *rs, int nb_args, const char *str); -void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str); -void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str); -void set_link_completion(ReadLineState *rs, int nb_args, const char *str); -void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str); -void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str); -void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str); -void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str); -void trace_event_completion(ReadLineState *rs, int nb_args, const char *str); -void watchdog_action_completion(ReadLineState *rs, int nb_args, - const char *str); -void migrate_set_capability_completion(ReadLineState *rs, int nb_args, - const char *str); -void migrate_set_parameter_completion(ReadLineState *rs, int nb_args, - const char *str); -void delvm_completion(ReadLineState *rs, int nb_args, const char *str); -void loadvm_completion(ReadLineState *rs, int nb_args, const char *str); void hmp_rocker(Monitor *mon, const QDict *qdict); void hmp_rocker_ports(Monitor *mon, const QDict *qdict); void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict); diff --git a/chardev/char-hmp-cmds.c b/chardev/char-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-hmp-cmds.c +++ b/chardev/char-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "chardev/char.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-char.h" diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "block/qapi.h" #include "migration/snapshot.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ #include "system/device_tree.h" #include "monitor/hmp-target.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "block/block-hmp-cmds.h" #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" diff --git a/net/net-hmp-cmds.c b/net/net-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/net/net-hmp-cmds.c +++ b/net/net-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "migration/misc.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "net/net.h" #include "net/hub.h" diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/core/qdev.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-qom.h" diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index XXXXXXX..XXXXXXX 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/core/sysbus.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "monitor/qdev.h" #include "system/arch_init.h" diff --git a/system/runstate-hmp-cmds.c b/system/runstate-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/system/runstate-hmp-cmds.c +++ b/system/runstate-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "exec/cpu-common.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-run-state.h" diff --git a/trace/trace-hmp-cmds.c b/trace/trace-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/trace/trace-hmp-cmds.c +++ b/trace/trace-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "qapi/error.h" #include "qapi/qapi-commands-trace.h" diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/ui/ui-hmp-cmds.c +++ b/ui/ui-hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include <spice/enums.h> #endif #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-ui.h" -- 2.53.0
We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Eric Farman <farman@linux.ibm.com> --- MAINTAINERS | 6 ++++++ stubs/{monitor-arm-gic.c => qmp-arm-gic.c} | 0 ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} | 0 stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} | 0 stubs/{monitor-cpu.c => qmp-cpu.c} | 0 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} | 0 stubs/{monitor-i386-sev.c => qmp-i386-sev.c} | 0 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} | 0 stubs/{monitor-i386-xen.c => qmp-i386-xen.c} | 0 stubs/meson.build | 16 ++++++++-------- 10 files changed, 14 insertions(+), 8 deletions(-) rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%) rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%) rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%) rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%) rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%) rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%) rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%) rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%) diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: include/hw/s390x/ F: include/hw/watchdog/wdt_diag288.h F: pc-bios/s390-ccw/ F: pc-bios/s390-ccw.img +F: stubs/qmp-cpu-s390x.c F: target/s390x/ F: docs/system/target-s390x.rst F: docs/system/s390x/ @@ -XXX,XX +XXX,XX @@ M: Christian Borntraeger <borntraeger@linux.ibm.com> R: Eric Farman <farman@linux.ibm.com> R: Matthew Rosato <mjrosato@linux.ibm.com> S: Supported +F: stubs/qmp-cpu-s390x-kvm.c F: target/s390x/kvm/ F: target/s390x/machine.c F: target/s390x/sigp.c @@ -XXX,XX +XXX,XX @@ L: kvm@vger.kernel.org S: Supported F: docs/system/i386/amd-memory-encryption.rst F: docs/system/i386/sgx.rst +F: stubs/qmp-i386-sev.c +F: stubs/qmp-i386-sgx.c F: target/i386/kvm/ F: target/i386/sev* F: scripts/kvm/vmxcap @@ -XXX,XX +XXX,XX @@ S: Supported F: include/system/kvm_xen.h F: target/i386/kvm/xen* F: hw/i386/kvm/xen* +F: stubs/qmp-i386-xen.c F: tests/functional/x86_64/test_kvm_xen.py Guest CPU Cores (other accelerators) @@ -XXX,XX +XXX,XX @@ F: include/hw/timer/a9gtimer.h F: include/hw/timer/arm_mptimer.h F: include/hw/timer/armv7m_systick.h F: include/hw/misc/armv7m_ras.h +F: stubs/qmp-arm-gic.c F: tests/qtest/test-arm-mptimer.c Bananapi M2U diff --git a/stubs/monitor-arm-gic.c b/stubs/qmp-arm-gic.c similarity index 100% rename from stubs/monitor-arm-gic.c rename to stubs/qmp-arm-gic.c diff --git a/stubs/monitor-cpu-s390x-kvm.c b/stubs/qmp-cpu-s390x-kvm.c similarity index 100% rename from stubs/monitor-cpu-s390x-kvm.c rename to stubs/qmp-cpu-s390x-kvm.c diff --git a/stubs/monitor-cpu-s390x.c b/stubs/qmp-cpu-s390x.c similarity index 100% rename from stubs/monitor-cpu-s390x.c rename to stubs/qmp-cpu-s390x.c diff --git a/stubs/monitor-cpu.c b/stubs/qmp-cpu.c similarity index 100% rename from stubs/monitor-cpu.c rename to stubs/qmp-cpu.c diff --git a/stubs/monitor-i386-rtc.c b/stubs/qmp-i386-rtc.c similarity index 100% rename from stubs/monitor-i386-rtc.c rename to stubs/qmp-i386-rtc.c diff --git a/stubs/monitor-i386-sev.c b/stubs/qmp-i386-sev.c similarity index 100% rename from stubs/monitor-i386-sev.c rename to stubs/qmp-i386-sev.c diff --git a/stubs/monitor-i386-sgx.c b/stubs/qmp-i386-sgx.c similarity index 100% rename from stubs/monitor-i386-sgx.c rename to stubs/qmp-i386-sgx.c diff --git a/stubs/monitor-i386-xen.c b/stubs/qmp-i386-xen.c similarity index 100% rename from stubs/monitor-i386-xen.c rename to stubs/qmp-i386-xen.c diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('target-monitor-defs.c')) stub_ss.add(files('win32-kbd-hook.c')) stub_ss.add(files('xen-hw-stub.c')) - stub_ss.add(files('monitor-arm-gic.c')) - stub_ss.add(files('monitor-i386-rtc.c')) - stub_ss.add(files('monitor-i386-sev.c')) - stub_ss.add(files('monitor-i386-sgx.c')) - stub_ss.add(files('monitor-i386-xen.c')) - stub_ss.add(files('monitor-cpu.c')) - stub_ss.add(files('monitor-cpu-s390x.c')) - stub_ss.add(files('monitor-cpu-s390x-kvm.c')) + stub_ss.add(files('qmp-arm-gic.c')) + stub_ss.add(files('qmp-i386-rtc.c')) + stub_ss.add(files('qmp-i386-sev.c')) + stub_ss.add(files('qmp-i386-sgx.c')) + stub_ss.add(files('qmp-i386-xen.c')) + stub_ss.add(files('qmp-cpu.c')) + stub_ss.add(files('qmp-cpu-s390x.c')) + stub_ss.add(files('qmp-cpu-s390x-kvm.c')) endif if have_system or have_user -- 2.53.0
When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- migration/meson.build | 2 +- monitor/meson.build | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/meson.build b/migration/meson.build index XXXXXXX..XXXXXXX 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -XXX,XX +XXX,XX @@ system_ss.add(files( 'fd.c', 'file.c', 'global_state.c', - 'migration-hmp-cmds.c', 'migration.c', 'multifd.c', 'multifd-device-state.c', @@ -XXX,XX +XXX,XX @@ system_ss.add(files( 'socket.c', 'tls.c', ), gnutls, zlib) +system_ss.add([spice_headers, files('migration-hmp-cmds.c'), spice]) if get_option('replication').allowed() system_ss.add(files('colo-failover.c', 'colo.c', 'multifd-colo.c')) diff --git a/monitor/meson.build b/monitor/meson.build index XXXXXXX..XXXXXXX 100644 --- a/monitor/meson.build +++ b/monitor/meson.build @@ -XXX,XX +XXX,XX @@ system_ss.add(files( 'hmp-cmds.c', 'hmp.c', 'qemu-config-qmp.c', + 'qmp-cmds.c', )) -system_ss.add([spice_headers, files('qmp-cmds.c')]) specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', - if_true: [files('hmp-target.c'), spice]) + if_true: [files('hmp-target.c')]) -- 2.53.0
As mentioned in commit 755f196898e ("qapi: Convert the cpu command") 15 years ago, the monitor_set_cpu() method is a temporary bridge between QMP -> HMP and shouldn't be used elsewhere. Make its scope internal to monitor/. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/monitor/monitor.h | 1 - monitor/monitor-internal.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -XXX,XX +XXX,XX @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3); void monitor_printc(Monitor *mon, int ch); void monitor_flush(Monitor *mon); -int monitor_set_cpu(Monitor *mon, int cpu_index); int monitor_get_cpu_index(Monitor *mon); int monitor_puts_locked(Monitor *mon, const char *str); diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index XXXXXXX..XXXXXXX 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -XXX,XX +XXX,XX @@ void monitor_data_destroy(Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); void monitor_fdsets_cleanup(void); +int monitor_set_cpu(Monitor *mon, int cpu_index); void qmp_send_response(MonitorQMP *mon, const QDict *rsp); void monitor_data_destroy_qmp(MonitorQMP *mon); -- 2.53.0
In order to build hmp-commands-info.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the device is not available. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- MAINTAINERS | 2 +- hw/misc/mos6522-stub.c | 16 ++++++++++++++++ hmp-commands-info.hx | 2 -- hw/misc/meson.build | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 hw/misc/mos6522-stub.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: hw/ppc/mac_newworld.c F: hw/pci-host/uninorth.c F: hw/pci-bridge/dec.[hc] F: hw/misc/macio/ -F: hw/misc/mos6522.c +F: hw/misc/mos6522*.c F: hw/nvram/mac_nvram.c F: hw/ppc/fw_cfg.c F: hw/input/adb* diff --git a/hw/misc/mos6522-stub.c b/hw/misc/mos6522-stub.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/hw/misc/mos6522-stub.c @@ -XXX,XX +XXX,XX @@ +/* + * QEMU MOS6522 VIA stubs + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/monitor.h" +#include "monitor/hmp.h" + +void hmp_info_via(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "MOS6522 VIA is not available in this QEMU\n"); +} diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Show intel SGX information. ERST -#if defined(CONFIG_MOS6522) { .name = "via", .args_type = "", @@ -XXX,XX +XXX,XX @@ ERST .help = "show guest mos6522 VIA devices", .cmd = hmp_info_via, }, -#endif SRST ``info via`` diff --git a/hw/misc/meson.build b/hw/misc/meson.build index XXXXXXX..XXXXXXX 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c')) # Mac devices system_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) +stub_ss.add(files('mos6522-stub.c')) system_ss.add(when: 'CONFIG_DJMEMC', if_true: files('djmemc.c')) system_ss.add(when: 'CONFIG_IOSB', if_true: files('iosb.c')) -- 2.53.0
In order to build hmp-commands.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the feature is not available. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- hw/i386/kvm/xen-stubs.c | 12 ++++++++++++ hmp-commands.hx | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/i386/kvm/xen-stubs.c b/hw/i386/kvm/xen-stubs.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/kvm/xen-stubs.c +++ b/hw/i386/kvm/xen-stubs.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "monitor/monitor.h" +#include "monitor/hmp.h" #include "xen_evtchn.h" #include "xen_primary_console.h" @@ -XXX,XX +XXX,XX @@ void xen_primary_console_create(void) void xen_primary_console_set_be_port(uint16_t port) { } + +void hmp_xen_event_list(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "XEN emulation is not available in this QEMU\n"); +} + +void hmp_xen_event_inject(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "XEN emulation is not available in this QEMU\n"); +} diff --git a/hmp-commands.hx b/hmp-commands.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -XXX,XX +XXX,XX @@ SRST ERST #endif -#if defined(CONFIG_XEN_EMU) { .name = "xen-event-inject", .args_type = "port:i", @@ -XXX,XX +XXX,XX @@ SRST ``xen-event-list`` List event channels in the guest ERST -#endif -- 2.53.0
We already have a file unit outside of the local system' folder which include "system/arch_init.h". We want more files to use it, so make it official it is a generic header by moving it under include. Rename as "qemu/base-arch-defs.h" which is more descriptive. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- system/arch_init.h => include/qemu/base-arch-defs.h | 10 ++++++++-- hw/pci/pci.c | 2 +- system/arch_init.c | 2 +- system/qdev-monitor.c | 2 +- system/vl.c | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) rename system/arch_init.h => include/qemu/base-arch-defs.h (92%) diff --git a/system/arch_init.h b/include/qemu/base-arch-defs.h similarity index 92% rename from system/arch_init.h rename to include/qemu/base-arch-defs.h index XXXXXXX..XXXXXXX 100644 --- a/system/arch_init.h +++ b/include/qemu/base-arch-defs.h @@ -XXX,XX +XXX,XX @@ -#ifndef QEMU_ARCH_INIT_H -#define QEMU_ARCH_INIT_H +/* + * QEMU base architecture bit definitions + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_BASE_ARCH_DEFS_H +#define QEMU_BASE_ARCH_DEFS_H #include "qapi/qapi-types-machine.h" diff --git a/hw/pci/pci.c b/hw/pci/pci.c index XXXXXXX..XXXXXXX 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -XXX,XX +XXX,XX @@ #include "migration/qemu-file-types.h" #include "migration/vmstate.h" #include "net/net.h" -#include "system/arch_init.h" +#include "qemu/base-arch-defs.h" #include "system/numa.h" #include "system/runstate.h" #include "system/system.h" diff --git a/system/arch_init.c b/system/arch_init.c index XXXXXXX..XXXXXXX 100644 --- a/system/arch_init.c +++ b/system/arch_init.c @@ -XXX,XX +XXX,XX @@ * THE SOFTWARE. */ #include "qemu/osdep.h" -#include "system/arch_init.h" +#include "qemu/base-arch-defs.h" #include "qemu/bitops.h" #include "qemu/target-info-qapi.h" diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index XXXXXXX..XXXXXXX 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -XXX,XX +XXX,XX @@ #include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "monitor/qdev.h" -#include "system/arch_init.h" +#include "qemu/base-arch-defs.h" #include "system/runstate.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" diff --git a/system/vl.c b/system/vl.c index XXXXXXX..XXXXXXX 100644 --- a/system/vl.c +++ b/system/vl.c @@ -XXX,XX +XXX,XX @@ #include "trace/control.h" #include "qemu/plugin.h" #include "qemu/queue.h" -#include "system/arch_init.h" +#include "qemu/base-arch-defs.h" #include "system/confidential-guest-support.h" #include "ui/qemu-spice.h" -- 2.53.0
Add the @arch_bitmask field to the HMPCommand structure, allowing to restrict a command to a set of target architectures (represented by the QEMU_ARCH_* enum constants). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- monitor/monitor-internal.h | 11 ++++++++++- monitor/hmp-target.c | 1 + monitor/hmp.c | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index XXXXXXX..XXXXXXX 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -XXX,XX +XXX,XX @@ typedef struct HMPCommand { * the formatted text. */ HumanReadableText *(*cmd_info_hrt)(Error **errp); - bool coroutine; /* * @sub_table is a list of 2nd level of commands. If it does not exist, * cmd should be used. If it exists, sub_table[?].cmd should be @@ -XXX,XX +XXX,XX @@ typedef struct HMPCommand { */ struct HMPCommand *sub_table; void (*command_completion)(ReadLineState *rs, int nb_args, const char *str); + + /* Keep non-pointer data at the end to minimize holes. */ + + /** + * @arch_bitmask: bitmask of QEMU_ARCH_* constants + * Allow to restrict the command for a particular set of + * target architectures. + */ + uint32_t arch_bitmask; + bool coroutine; } HMPCommand; struct Monitor { diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h" diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ #include "qemu/cutils.h" #include "qemu/log.h" #include "qemu/option.h" +#include "qemu/base-arch-defs.h" #include "qemu/target-info.h" #include "qemu/units.h" #include "exec/gdbstub.h" @@ -XXX,XX +XXX,XX @@ static bool cmd_can_preconfig(const HMPCommand *cmd) static bool cmd_available(const HMPCommand *cmd) { + if (cmd->arch_bitmask && !qemu_arch_available(cmd->arch_bitmask)) { + return false; + } return phase_check(PHASE_MACHINE_READY) || cmd_can_preconfig(cmd); } -- 2.53.0
We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> --- include/hw/s390x/storage-attributes.h | 4 ---- include/hw/s390x/storage-keys.h | 3 --- include/monitor/hmp.h | 5 +++++ hw/s390x/s390-skeys.c | 2 ++ hw/s390x/s390-stattrib.c | 2 ++ 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/hw/s390x/storage-attributes.h b/include/hw/s390x/storage-attributes.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/s390x/storage-attributes.h +++ b/include/hw/s390x/storage-attributes.h @@ -XXX,XX +XXX,XX @@ #define S390_STORAGE_ATTRIBUTES_H #include "hw/core/qdev.h" -#include "monitor/monitor.h" #include "qom/object.h" #define TYPE_S390_STATTRIB "s390-storage_attributes" @@ -XXX,XX +XXX,XX @@ static inline Object *kvm_s390_stattrib_create(void) } #endif -void hmp_info_cmma(Monitor *mon, const QDict *qdict); -void hmp_migrationmode(Monitor *mon, const QDict *qdict); - #endif /* S390_STORAGE_ATTRIBUTES_H */ diff --git a/include/hw/s390x/storage-keys.h b/include/hw/s390x/storage-keys.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/s390x/storage-keys.h +++ b/include/hw/s390x/storage-keys.h @@ -XXX,XX +XXX,XX @@ #define S390_STORAGE_KEYS_H #include "hw/core/qdev.h" -#include "monitor/monitor.h" #include "qom/object.h" #define TYPE_S390_SKEYS "s390-skeys" @@ -XXX,XX +XXX,XX @@ int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn, S390SKeysState *s390_get_skeys_device(void); void s390_qmp_dump_skeys(const char *filename, Error **errp); -void hmp_dump_skeys(Monitor *mon, const QDict *qdict); -void hmp_info_skeys(Monitor *mon, const QDict *qdict); #define TYPE_DUMP_SKEYS_INTERFACE "dump-skeys-interface" diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ void hmp_gva2gpa(Monitor *mon, const QDict *qdict); void hmp_gpa2hva(Monitor *mon, const QDict *qdict); void hmp_gpa2hpa(Monitor *mon, const QDict *qdict); +void hmp_dump_skeys(Monitor *mon, const QDict *qdict); +void hmp_info_skeys(Monitor *mon, const QDict *qdict); +void hmp_info_cmma(Monitor *mon, const QDict *qdict); +void hmp_migrationmode(Monitor *mon, const QDict *qdict); + #endif diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index XXXXXXX..XXXXXXX 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -XXX,XX +XXX,XX @@ #include "system/kvm.h" #include "migration/qemu-file-types.h" #include "migration/register.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" #include "trace.h" #define S390_SKEYS_BUFFER_SIZE (128 * KiB) /* Room for 128k storage keys */ diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index XXXXXXX..XXXXXXX 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -XXX,XX +XXX,XX @@ #include "system/ram_addr.h" #include "migration/qemu-file.h" #include "migration/register.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" #include "hw/core/qdev-properties.h" #include "hw/s390x/storage-attributes.h" #include "qemu/error-report.h" -- 2.53.0
These commands are filtered at build-time for s390x binary. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once. Since the methods are used unconditionally within hw/s390x/, define them in the same stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> --- MAINTAINERS | 1 + include/monitor/hmp.h | 7 +++++++ monitor/hmp-target.c | 5 ----- stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++ hmp-commands-info.hx | 6 ++---- hmp-commands.hx | 6 ++---- stubs/meson.build | 1 + 7 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 stubs/hmp-cmds-hw-s390x.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: include/hw/watchdog/wdt_diag288.h F: pc-bios/s390-ccw/ F: pc-bios/s390-ccw.img F: stubs/qmp-cpu-s390x.c +F: stubs/hmp-cmds-hw-s390x.c F: target/s390x/ F: docs/system/target-s390x.rst F: docs/system/s390x/ diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ #include "qemu/readline.h" #include "qapi/qapi-types-common.h" +#include "monitor/monitor.h" + +#define HMP_STUB(cmd) \ + void hmp_##cmd(Monitor *mon, const QDict *qdict) \ + { \ + g_assert_not_reached(); \ + } bool hmp_handle_error(Monitor *mon, Error *err); void hmp_help_cmd(Monitor *mon, const char *name); diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" -#if defined(TARGET_S390X) -#include "hw/s390x/storage-keys.h" -#include "hw/s390x/storage-attributes.h" -#endif - /* Make devices configuration available for use in hmp-commands*.hx templates */ #include CONFIG_DEVICES diff --git a/stubs/hmp-cmds-hw-s390x.c b/stubs/hmp-cmds-hw-s390x.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/stubs/hmp-cmds-hw-s390x.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor hw/s390x stubs + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" + +HMP_STUB(dump_skeys) +HMP_STUB(info_cmma) +HMP_STUB(info_skeys) +HMP_STUB(migrationmode) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Show rocker OF-DPA groups. ERST -#if defined(TARGET_S390X) { .name = "skeys", .args_type = "addr:l", .params = "address", .help = "Display the value of a storage key", .cmd = hmp_info_skeys, + .arch_bitmask = QEMU_ARCH_S390X, }, -#endif SRST ``info skeys`` *address* Display the value of a storage key (s390 only) ERST -#if defined(TARGET_S390X) { .name = "cmma", .args_type = "addr:l,count:l?", .params = "address [count]", .help = "Display the values of the CMMA storage attributes for a range of pages", .cmd = hmp_info_cmma, + .arch_bitmask = QEMU_ARCH_S390X, }, -#endif SRST ``info cmma`` *address* diff --git a/hmp-commands.hx b/hmp-commands.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -XXX,XX +XXX,XX @@ SRST ERST -#if defined(TARGET_S390X) { .name = "dump-skeys", .args_type = "filename:F", .params = "", .help = "Save guest storage keys into file 'filename'.\n", .cmd = hmp_dump_skeys, + .arch_bitmask = QEMU_ARCH_S390X, }, -#endif SRST ``dump-skeys`` *filename* Save guest storage keys to a file. ERST -#if defined(TARGET_S390X) { .name = "migration_mode", .args_type = "mode:i", .params = "mode", .help = "Enables or disables migration mode\n", .cmd = hmp_migrationmode, + .arch_bitmask = QEMU_ARCH_S390X, }, -#endif SRST ``migration_mode`` *mode* diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('qmp-cpu.c')) stub_ss.add(files('qmp-cpu-s390x.c')) stub_ss.add(files('qmp-cpu-s390x-kvm.c')) + stub_ss.add(files('hmp-cmds-hw-s390x.c')) endif if have_system or have_user -- 2.53.0
These commands are filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once. Since these methods are used inconditionally within target/i386/, define them in the same stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- MAINTAINERS | 1 + stubs/hmp-cmds-target-i386.c | 13 +++++++++++++ hmp-commands-info.hx | 4 +--- hmp-commands.hx | 5 +---- stubs/meson.build | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 stubs/hmp-cmds-target-i386.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: configs/targets/i386-softmmu.mak F: configs/targets/x86_64-softmmu.mak F: docs/system/i386/ F: docs/system/target-i386* +F: stubs/hmp-cmds-target-i386.c F: target/i386/*.[ch] F: target/i386/Kconfig F: target/i386/meson.build diff --git a/stubs/hmp-cmds-target-i386.c b/stubs/hmp-cmds-target-i386.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/stubs/hmp-cmds-target-i386.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor x86 stubs + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" + +HMP_STUB(info_local_apic) +HMP_STUB(mce) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Show the cpu registers. ERST -#if defined(TARGET_I386) { .name = "lapic", .args_type = "apic-id:i?", .params = "[apic-id]", .help = "show local apic state (apic-id: local apic to read, default is which of current CPU)", - .cmd = hmp_info_local_apic, + .arch_bitmask = QEMU_ARCH_I386, }, -#endif SRST ``info lapic`` diff --git a/hmp-commands.hx b/hmp-commands.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -XXX,XX +XXX,XX @@ SRST Stop the QEMU embedded NBD server. ERST - -#if defined(TARGET_I386) - { .name = "mce", .args_type = "broadcast:-b,cpu_index:i,bank:i,status:l,mcg_status:l,addr:l,misc:l", .params = "[-b] cpu bank status mcgstatus addr misc", .help = "inject a MCE on the given CPU [and broadcast to other CPUs with -b option]", .cmd = hmp_mce, + .arch_bitmask = QEMU_ARCH_I386, }, -#endif SRST ``mce`` *cpu* *bank* *status* *mcgstatus* *addr* *misc* Inject an MCE on the given CPU (x86 only). diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('qmp-cpu-s390x.c')) stub_ss.add(files('qmp-cpu-s390x-kvm.c')) stub_ss.add(files('hmp-cmds-hw-s390x.c')) + stub_ss.add(files('hmp-cmds-target-i386.c')) endif if have_system or have_user -- 2.53.0
This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once. Since the method depends on the CONFIG_SGX definition, define it in its own stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- MAINTAINERS | 1 + hw/i386/sgx-hmp-stub.c | 16 ++++++++++++++++ hw/i386/sgx-stub.c | 5 ----- hmp-commands-info.hx | 3 +-- hw/i386/meson.build | 1 + 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 hw/i386/sgx-hmp-stub.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ L: kvm@vger.kernel.org S: Supported F: docs/system/i386/amd-memory-encryption.rst F: docs/system/i386/sgx.rst +F: hw/i386/sgx* F: stubs/qmp-i386-sev.c F: stubs/qmp-i386-sgx.c F: target/i386/kvm/ diff --git a/hw/i386/sgx-hmp-stub.c b/hw/i386/sgx-hmp-stub.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/hw/i386/sgx-hmp-stub.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor 'info sgx' stub (CONFIG_SGX) + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" + +void hmp_info_sgx(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "SGX is not available in this QEMU\n"); +} diff --git a/hw/i386/sgx-stub.c b/hw/i386/sgx-stub.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/sgx-stub.c +++ b/hw/i386/sgx-stub.c @@ -XXX,XX +XXX,XX @@ SgxInfo *qmp_query_sgx_capabilities(Error **errp) return NULL; } -void hmp_info_sgx(Monitor *mon, const QDict *qdict) -{ - monitor_printf(mon, "SGX is not available in this QEMU\n"); -} - void pc_machine_init_sgx_epc(PCMachineState *pcms) { memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState)); diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Display the vcpu dirty page limit information. ERST -#if defined(TARGET_I386) { .name = "sgx", .args_type = "", .params = "", .help = "show intel SGX information", .cmd = hmp_info_sgx, + .arch_bitmask = QEMU_ARCH_I386, }, -#endif SRST ``info sgx`` diff --git a/hw/i386/meson.build b/hw/i386/meson.build index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -XXX,XX +XXX,XX @@ i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c')) i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c')) i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), if_false: files('sgx-stub.c')) +stub_ss.add(files('sgx-hmp-stub.c')) i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c')) i386_ss.add(when: 'CONFIG_PC', if_true: files( -- 2.53.0
This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once. Since the method depends on the CONFIG_SEV definition, define it in its own stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- MAINTAINERS | 1 + stubs/hmp-cmd-info_sev.c | 16 ++++++++++++++++ target/i386/sev-system-stub.c | 5 ----- hmp-commands-info.hx | 3 +-- stubs/meson.build | 1 + 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 stubs/hmp-cmd-info_sev.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ S: Supported F: docs/system/i386/amd-memory-encryption.rst F: docs/system/i386/sgx.rst F: hw/i386/sgx* +F: stubs/hmp-cmd-info_sev.c F: stubs/qmp-i386-sev.c F: stubs/qmp-i386-sgx.c F: target/i386/kvm/ diff --git a/stubs/hmp-cmd-info_sev.c b/stubs/hmp-cmd-info_sev.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/stubs/hmp-cmd-info_sev.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor 'info sev' stub (CONFIG_SEV) + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" + +void hmp_info_sev(Monitor *mon, const QDict *qdict) +{ + monitor_printf(mon, "SEV is not available in this QEMU\n"); +} diff --git a/target/i386/sev-system-stub.c b/target/i386/sev-system-stub.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/sev-system-stub.c +++ b/target/i386/sev-system-stub.c @@ -XXX,XX +XXX,XX @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size) g_assert_not_reached(); } -void hmp_info_sev(Monitor *mon, const QDict *qdict) -{ - monitor_printf(mon, "SEV is not available in this QEMU\n"); -} - void pc_system_parse_sev_metadata(uint8_t *flash_ptr, size_t flash_size) { } diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST enabled) memory in bytes. ERST -#if defined(TARGET_I386) { .name = "sev", .args_type = "", .params = "", .help = "show SEV information", .cmd = hmp_info_sev, + .arch_bitmask = QEMU_ARCH_I386, }, -#endif SRST ``info sev`` diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('qmp-cpu.c')) stub_ss.add(files('qmp-cpu-s390x.c')) stub_ss.add(files('qmp-cpu-s390x-kvm.c')) + stub_ss.add(files('hmp-cmd-info_sev.c')) stub_ss.add(files('hmp-cmds-hw-s390x.c')) stub_ss.add(files('hmp-cmds-target-i386.c')) endif -- 2.53.0
This command is filtered at build-time for i386/x86_64 and riscv32/riscv64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once. Since the method depends on a pair of distinct targets, define it in its own stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- stubs/hmp-cmd-info_mem.c | 12 ++++++++++++ hmp-commands-info.hx | 3 +-- stubs/meson.build | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 stubs/hmp-cmd-info_mem.c diff --git a/stubs/hmp-cmd-info_mem.c b/stubs/hmp-cmd-info_mem.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/stubs/hmp-cmd-info_mem.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor 'info mem' stub + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" + +HMP_STUB(info_mem) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Show virtual to physical memory mappings. ERST -#if defined(TARGET_I386) || defined(TARGET_RISCV) { .name = "mem", .args_type = "", .params = "", .help = "show the active virtual memory mappings", .cmd = hmp_info_mem, + .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_RISCV, }, -#endif SRST ``info mem`` diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('qmp-cpu.c')) stub_ss.add(files('qmp-cpu-s390x.c')) stub_ss.add(files('qmp-cpu-s390x-kvm.c')) + stub_ss.add(files('hmp-cmd-info_mem.c')) stub_ss.add(files('hmp-cmd-info_sev.c')) stub_ss.add(files('hmp-cmds-hw-s390x.c')) stub_ss.add(files('hmp-cmds-target-i386.c')) -- 2.53.0
This command is filtered at build-time for a selection of binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands-info.hx once. Since the method depends on a pair of distinct targets, define it in its own stub file. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- stubs/hmp-cmd-info_tlb.c | 12 ++++++++++++ hmp-commands-info.hx | 5 ++--- stubs/meson.build | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 stubs/hmp-cmd-info_tlb.c diff --git a/stubs/hmp-cmd-info_tlb.c b/stubs/hmp-cmd-info_tlb.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/stubs/hmp-cmd-info_tlb.c @@ -XXX,XX +XXX,XX @@ +/* + * Human Monitor 'info tlb' stub + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" + +HMP_STUB(info_tlb) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index XXXXXXX..XXXXXXX 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -XXX,XX +XXX,XX @@ SRST Show PCI information. ERST -#if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \ - defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K) { .name = "tlb", .args_type = "", .params = "", .help = "show virtual to physical memory mappings", .cmd = hmp_info_tlb, + .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \ + | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K, }, -#endif SRST ``info tlb`` diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('qmp-cpu-s390x-kvm.c')) stub_ss.add(files('hmp-cmd-info_mem.c')) stub_ss.add(files('hmp-cmd-info_sev.c')) + stub_ss.add(files('hmp-cmd-info_tlb.c')) stub_ss.add(files('hmp-cmds-hw-s390x.c')) stub_ss.add(files('hmp-cmds-target-i386.c')) endif -- 2.53.0
Allow targets to register their legacy target_get_monitor_def() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/hw/core/sysemu-cpu-ops.h | 8 ++++++++ monitor/hmp-target.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/core/sysemu-cpu-ops.h +++ b/include/hw/core/sysemu-cpu-ops.h @@ -XXX,XX +XXX,XX @@ typedef struct SysemuCPUOps { */ bool (*internal_is_big_endian)(CPUState *cpu); + /** + * @monitor_get_register: Callback to fill @pval with register @name value. + * This field is legacy, use @gdb_core_xml_file + * to dump registers instead. + * Returns: 0 on success or negative errno on failure. + */ + int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval); + /** * @legacy_vmsd: Legacy state for migration. * Do not use in new targets, use #DeviceClass::vmsd instead. diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" +#include "hw/core/sysemu-cpu-ops.h" /* Make devices configuration available for use in hmp-commands*.hx templates */ #include CONFIG_DEVICES @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) } } - ret = target_get_monitor_def(cs, name, &tmp); - if (!ret) { - *pval = (target_long) tmp; + if (cs->cc->sysemu_ops->monitor_get_register) { + ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); + } else { + ret = target_get_monitor_def(cs, name, &tmp); + if (!ret) { + *pval = (target_long) tmp; + } } return ret; -- 2.53.0
Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as SysemuCPUOps::monitor_get_register() handler. Take care to sign-extend values for 32-bit HARTs. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/riscv/internals.h | 3 +++ target/riscv/cpu.c | 1 + target/riscv/monitor.c | 11 +++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) return (first_word & 3) == 3 ? 4 : 2; } +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name, + int64_t *pval); + #endif diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { .get_phys_page_debug = riscv_cpu_get_phys_page_debug, .write_elf64_note = riscv_cpu_write_elf64_note, .write_elf32_note = riscv_cpu_write_elf32_note, + .monitor_get_register = riscv_monitor_get_register_legacy, .legacy_vmsd = &vmstate_riscv_cpu, }; #endif diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/monitor.c +++ b/target/riscv/monitor.c @@ -XXX,XX +XXX,XX @@ #include "monitor/hmp.h" #include "monitor/hmp-target.h" #include "system/memory.h" +#include "internals.h" #ifdef TARGET_RISCV64 #define PTE_HEADER_FIELDS "vaddr paddr "\ @@ -XXX,XX +XXX,XX @@ static bool reg_is_vreg(const char *name) return false; } -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name, + int64_t *pval) { - CPURISCVState *env = &RISCV_CPU(cs)->env; + RISCVCPU *hart = RISCV_CPU(cs); + CPURISCVState *env = cpu_env(cs); target_ulong val = 0; uint64_t val64 = 0; int i; if (reg_is_ulong_integer(env, name, &val, false) || reg_is_ulong_integer(env, name, &val, true)) { - *pval = val; + *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val; return 0; } @@ -XXX,XX +XXX,XX @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) * to do the filtering of the registers that are present. */ if (res == RISCV_EXCP_NONE) { - *pval = val; + *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val; return 0; } } -- 2.53.0
target_get_monitor_def() is now only a dead stub. Remove as pointless. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/monitor/hmp-target.h | 1 - monitor/hmp-target.c | 14 +++----------- stubs/target-get-monitor-def.c | 29 ----------------------------- stubs/meson.build | 1 - 4 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 stubs/target-get-monitor-def.c diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -XXX,XX +XXX,XX @@ struct MonitorDef { #endif const MonitorDef *target_monitor_defs(void); -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); CPUArchState *mon_get_cpu_env(Monitor *mon); CPUState *mon_get_cpu(Monitor *mon); diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) const MonitorDef *md = target_monitor_defs(); CPUState *cs = mon_get_cpu(mon); void *ptr; - uint64_t tmp = 0; - int ret; if (cs == NULL || md == NULL) { return -1; @@ -XXX,XX +XXX,XX @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) } } - if (cs->cc->sysemu_ops->monitor_get_register) { - ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); - } else { - ret = target_get_monitor_def(cs, name, &tmp); - if (!ret) { - *pval = (target_long) tmp; - } + if (!cs->cc->sysemu_ops->monitor_get_register) { + return -1; } - - return ret; + return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); } static int diff --git a/stubs/target-get-monitor-def.c b/stubs/target-get-monitor-def.c deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/stubs/target-get-monitor-def.c +++ /dev/null @@ -XXX,XX +XXX,XX @@ -/* - * Stub for target_get_monitor_def. - * - * Copyright IBM Corp., 2015 - * - * Author: Alexey Kardashevskiy <aik@ozlabs.ru> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "qemu/osdep.h" - -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval); - -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval) -{ - return -1; -} diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('igvm.c')) endif stub_ss.add(files('kvm.c')) - stub_ss.add(files('target-get-monitor-def.c')) stub_ss.add(files('target-monitor-defs.c')) stub_ss.add(files('win32-kbd-hook.c')) stub_ss.add(files('xen-hw-stub.c')) -- 2.53.0
Simplify MonitorDef::get_value() handler by having it always return a int64_t type. Let the single caller (x86 targets) sign-extend the returned value, directly handling 64-bit CPUs in 32-bit or 16-bit mode. Suggested-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- include/monitor/hmp-target.h | 6 +----- target/i386/monitor.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -XXX,XX +XXX,XX @@ typedef struct MonitorDef MonitorDef; -#ifdef COMPILING_PER_TARGET -#include "exec/target_long.h" struct MonitorDef { const char *name; int offset; - target_long (*get_value)(Monitor *mon, const struct MonitorDef *md, - int val); + int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset); }; -#endif const MonitorDef *target_monitor_defs(void); diff --git a/target/i386/monitor.c b/target/i386/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_mce(Monitor *mon, const QDict *qdict) } } -static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md, + int offset) { CPUArchState *env = mon_get_cpu_env(mon); - return env->eip + env->segs[R_CS].base; + int64_t ret = env->eip + env->segs[R_CS].base; + + if (!(env->hflags & HF_CS64_MASK)) { + ret = (int32_t)ret; + } + return ret; } const MonitorDef monitor_defs[] = { -- 2.53.0
get_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- monitor/monitor-internal.h | 1 - monitor/hmp-target.c | 33 --------------------------------- monitor/hmp.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index XXXXXXX..XXXXXXX 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -XXX,XX +XXX,XX @@ void monitor_data_destroy_qmp(MonitorQMP *mon); void coroutine_fn monitor_qmp_dispatcher_co(void *data); void qmp_dispatcher_co_wake(void); -int get_monitor_def(Monitor *mon, int64_t *pval, const char *name); void handle_hmp_command(MonitorHMP *mon, const char *cmdline); int hmp_compare_cmd(const char *name, const char *list); diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ HMPCommand *hmp_cmds_for_target(bool info_command) return info_command ? hmp_info_cmds : hmp_cmds; } -/* - * Set @pval to the value in the register identified by @name. - * return 0 if OK, -1 if not found - */ -int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) -{ - const MonitorDef *md = target_monitor_defs(); - CPUState *cs = mon_get_cpu(mon); - void *ptr; - - if (cs == NULL || md == NULL) { - return -1; - } - - for(; md->name != NULL; md++) { - if (hmp_compare_cmd(name, md->name)) { - if (md->get_value) { - *pval = md->get_value(mon, md, md->offset); - } else { - CPUArchState *env = mon_get_cpu_env(mon); - ptr = (uint8_t *)env + md->offset; - *pval = *(int32_t *)ptr; - } - return 0; - } - } - - if (!cs->cc->sysemu_ops->monitor_get_register) { - return -1; - } - return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); -} - static int compare_mon_cmd(const void *a, const void *b) { diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <dirent.h> #include "hw/core/qdev.h" +#include "hw/core/sysemu-cpu-ops.h" #include "monitor-internal.h" #include "monitor/hmp.h" #include "monitor/hmp-target.h" @@ -XXX,XX +XXX,XX @@ static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name) static const char *pch; static sigjmp_buf expr_env; +static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name); + static G_NORETURN G_GNUC_PRINTF(2, 3) void expr_error(Monitor *mon, const char *fmt, ...) { @@ -XXX,XX +XXX,XX @@ void monitor_register_hmp_info_hrt(const char *name, } g_assert_not_reached(); } + +/* + * Set @pval to the value in the register identified by @name. + * return 0 if OK, -1 if not found + */ +static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) +{ + const MonitorDef *md = target_monitor_defs(); + CPUState *cs = mon_get_cpu(mon); + void *ptr; + + if (cs == NULL || md == NULL) { + return -1; + } + + for(; md->name != NULL; md++) { + if (hmp_compare_cmd(name, md->name)) { + if (md->get_value) { + *pval = md->get_value(mon, md, md->offset); + } else { + CPUArchState *env = mon_get_cpu_env(mon); + ptr = (uint8_t *)env + md->offset; + *pval = *(int32_t *)ptr; + } + return 0; + } + } + + if (!cs->cc->sysemu_ops->monitor_get_register) { + return -1; + } + return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval); +} -- 2.53.0
The "monitor/hmp-target.h" header doesn't contain any target-specific declarations anymore. Merge it with "monitor/hmp.h", its target-agnostic counterpart. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> --- MAINTAINERS | 1 - include/monitor/hmp-target.h | 41 ----------------------------------- include/monitor/hmp.h | 11 ++++++++++ hw/i386/sgx-stub.c | 1 - hw/i386/sgx.c | 1 - monitor/hmp-cmds.c | 1 - monitor/hmp-target.c | 1 - monitor/hmp.c | 1 - stubs/target-monitor-defs.c | 2 +- target/i386/cpu-apic.c | 1 - target/i386/monitor.c | 1 - target/i386/sev-system-stub.c | 1 - target/i386/sev.c | 1 - target/m68k/monitor.c | 1 - target/ppc/monitor.c | 2 -- target/riscv/monitor.c | 1 - target/sh4/monitor.c | 1 - target/sparc/monitor.c | 1 - target/xtensa/monitor.c | 1 - 19 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 include/monitor/hmp-target.h diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ F: hmp.h F: hmp-commands*.hx F: include/monitor/hmp.h F: include/monitor/hmp-completion.h -F: include/monitor/hmp-target.h F: tests/qtest/test-hmp.c F: include/qemu/qemu-print.h F: util/qemu-print.c diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/include/monitor/hmp-target.h +++ /dev/null @@ -XXX,XX +XXX,XX @@ -/* - * QEMU monitor - * - * Copyright (c) 2003-2004 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MONITOR_HMP_TARGET_H -#define MONITOR_HMP_TARGET_H - -typedef struct MonitorDef MonitorDef; - -struct MonitorDef { - const char *name; - int offset; - int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset); -}; - -const MonitorDef *target_monitor_defs(void); - -CPUArchState *mon_get_cpu_env(Monitor *mon); -CPUState *mon_get_cpu(Monitor *mon); - -#endif /* MONITOR_HMP_TARGET_H */ diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ g_assert_not_reached(); \ } +typedef struct MonitorDef { + const char *name; + int offset; + int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset); +} MonitorDef; + +const MonitorDef *target_monitor_defs(void); + +CPUArchState *mon_get_cpu_env(Monitor *mon); +CPUState *mon_get_cpu(Monitor *mon); + bool hmp_handle_error(Monitor *mon, Error *err); void hmp_help_cmd(Monitor *mon, const char *name); strList *hmp_split_at_comma(const char *str); diff --git a/hw/i386/sgx-stub.c b/hw/i386/sgx-stub.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/sgx-stub.c +++ b/hw/i386/sgx-stub.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "hw/i386/pc.h" #include "hw/i386/sgx-epc.h" #include "qapi/qapi-commands-misc-i386.h" diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -XXX,XX +XXX,XX @@ #include "monitor/qdev.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qapi/qapi-commands-misc-i386.h" diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -XXX,XX +XXX,XX @@ #include "monitor/hmp.h" #include "qemu/help_option.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -XXX,XX +XXX,XX @@ #include "monitor/qdev.h" #include "net/slirp.h" #include "system/device_tree.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "monitor/hmp-completion.h" #include "block/block-hmp-cmds.h" diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ #include "hw/core/sysemu-cpu-ops.h" #include "monitor-internal.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "qobject/qdict.h" #include "qobject/qnum.h" #include "qemu/bswap.h" diff --git a/stubs/target-monitor-defs.c b/stubs/target-monitor-defs.c index XXXXXXX..XXXXXXX 100644 --- a/stubs/target-monitor-defs.c +++ b/stubs/target-monitor-defs.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "monitor/hmp-target.h" +#include "monitor/hmp.h" const MonitorDef *target_monitor_defs(void) { diff --git a/target/i386/cpu-apic.c b/target/i386/cpu-apic.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/cpu-apic.c +++ b/target/i386/cpu-apic.c @@ -XXX,XX +XXX,XX @@ #include "qapi/error.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "system/hw_accel.h" #include "system/kvm.h" #include "system/xen.h" diff --git a/target/i386/monitor.c b/target/i386/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "cpu.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "qobject/qdict.h" #include "qapi/error.h" diff --git a/target/i386/sev-system-stub.c b/target/i386/sev-system-stub.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/sev-system-stub.c +++ b/target/i386/sev-system-stub.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "qapi/error.h" #include "sev.h" diff --git a/target/i386/sev.c b/target/i386/sev.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -XXX,XX +XXX,XX @@ #include "qom/object.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "qapi/qapi-commands-misc-i386.h" #include "confidential-guest.h" #include "hw/i386/pc.h" diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/monitor.c +++ b/target/m68k/monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "cpu.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "monitor/monitor.h" void hmp_info_tlb(Monitor *mon, const QDict *qdict) diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/ppc/monitor.c +++ b/target/ppc/monitor.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "qemu/ctype.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "cpu.h" diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/riscv/monitor.c +++ b/target/riscv/monitor.c @@ -XXX,XX +XXX,XX @@ #include "cpu_bits.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "system/memory.h" #include "internals.h" diff --git a/target/sh4/monitor.c b/target/sh4/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sh4/monitor.c +++ b/target/sh4/monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "cpu.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" static void print_tlb(Monitor *mon, int idx, tlb_t *tlb) diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "cpu.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" diff --git a/target/xtensa/monitor.c b/target/xtensa/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/xtensa/monitor.c +++ b/target/xtensa/monitor.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "cpu.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" void hmp_info_tlb(Monitor *mon, const QDict *qdict) -- 2.53.0
Rather than having core header forced to include "monitor/hmp.h" to get the MonitorDef type declaration, forward-declare it in "qemu/typedefs.h". Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/monitor/hmp.h | 6 +++--- include/qemu/typedefs.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ g_assert_not_reached(); \ } -typedef struct MonitorDef { +struct MonitorDef { const char *name; int offset; - int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset); -} MonitorDef; + int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset); +}; const MonitorDef *target_monitor_defs(void); diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -XXX,XX +XXX,XX @@ typedef struct MemoryRegionSection MemoryRegionSection; typedef struct MigrationIncomingState MigrationIncomingState; typedef struct MigrationState MigrationState; typedef struct Monitor Monitor; +typedef struct MonitorDef MonitorDef; typedef struct MSIMessage MSIMessage; typedef struct NetClientState NetClientState; typedef struct NetFilterState NetFilterState; -- 2.53.0
Allow targets to register their legacy target_monitor_defs() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/hw/core/sysemu-cpu-ops.h | 6 ++++++ monitor/hmp.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/core/sysemu-cpu-ops.h +++ b/include/hw/core/sysemu-cpu-ops.h @@ -XXX,XX +XXX,XX @@ typedef struct SysemuCPUOps { */ int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval); + /** + * @monitor_defs: Array of MonitorDef entries. This field is legacy, + * use @gdb_core_xml_file to dump registers instead. + */ + const MonitorDef *monitor_defs; + /** * @legacy_vmsd: Legacy state for migration. * Do not use in new targets, use #DeviceClass::vmsd instead. diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ void monitor_register_hmp_info_hrt(const char *name, */ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) { - const MonitorDef *md = target_monitor_defs(); CPUState *cs = mon_get_cpu(mon); + const MonitorDef *md; void *ptr; - if (cs == NULL || md == NULL) { + if (cs == NULL) { + return -1; + } + md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs(); + if (md == NULL) { return -1; } -- 2.53.0
Restrict x86_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/i386/cpu.c | 29 +++++++++++++++++++++++++++++ target/i386/monitor.c | 30 ------------------------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -XXX,XX +XXX,XX @@ #include "exec/watchpoint.h" #ifndef CONFIG_USER_ONLY #include "confidential-guest.h" +#include "monitor/hmp.h" #include "system/reset.h" #include "qapi/qapi-commands-machine.h" #include "system/address-spaces.h" @@ -XXX,XX +XXX,XX @@ static const Property x86_cpu_properties[] = { }; #ifndef CONFIG_USER_ONLY + +static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md, + int offset) +{ + CPUArchState *env = mon_get_cpu_env(mon); + int64_t ret = env->eip + env->segs[R_CS].base; + + if (!(env->hflags & HF_CS64_MASK)) { + ret = (int32_t)ret; + } + return ret; +} + +static const MonitorDef x86_monitor_defs[] = { +#define SEG(name, seg) \ + { name ".limit", offsetof(CPUX86State, segs[seg].limit) }, + SEG("cs", R_CS) + SEG("ds", R_DS) + SEG("es", R_ES) + SEG("ss", R_SS) + SEG("fs", R_FS) + SEG("gs", R_GS) + { "pc", 0, monitor_get_pc, }, + { NULL }, +#undef SEG +}; + #include "hw/core/sysemu-cpu-ops.h" static const struct SysemuCPUOps i386_sysemu_ops = { @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps i386_sysemu_ops = { .write_elf64_note = x86_cpu_write_elf64_note, .write_elf32_qemunote = x86_cpu_write_elf32_qemunote, .write_elf64_qemunote = x86_cpu_write_elf64_qemunote, + .monitor_defs = x86_monitor_defs, .legacy_vmsd = &vmstate_x86_cpu, }; #endif diff --git a/target/i386/monitor.c b/target/i386/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_mce(Monitor *mon, const QDict *qdict) flags); } } - -static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md, - int offset) -{ - CPUArchState *env = mon_get_cpu_env(mon); - int64_t ret = env->eip + env->segs[R_CS].base; - - if (!(env->hflags & HF_CS64_MASK)) { - ret = (int32_t)ret; - } - return ret; -} - -const MonitorDef monitor_defs[] = { -#define SEG(name, seg) \ - { name ".limit", offsetof(CPUX86State, segs[seg].limit) }, - SEG("cs", R_CS) - SEG("ds", R_DS) - SEG("es", R_ES) - SEG("ss", R_SS) - SEG("fs", R_FS) - SEG("gs", R_GS) - { "pc", 0, monitor_get_pc, }, - { NULL }, -}; - -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} -- 2.53.0
Restrict m68k_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/m68k/cpu.c | 18 ++++++++++++++++++ target/m68k/monitor.c | 21 --------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -XXX,XX +XXX,XX @@ #ifndef CONFIG_USER_ONLY #include "migration/vmstate.h" +#include "monitor/hmp.h" #endif #include "cpu.h" @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m68k_cpu = { }, }; +static const MonitorDef m68k_monitor_defs[] = { + { "ssp", offsetof(CPUM68KState, sp[0]) }, + { "usp", offsetof(CPUM68KState, sp[1]) }, + { "isp", offsetof(CPUM68KState, sp[2]) }, + { "sfc", offsetof(CPUM68KState, sfc) }, + { "dfc", offsetof(CPUM68KState, dfc) }, + { "urp", offsetof(CPUM68KState, mmu.urp) }, + { "srp", offsetof(CPUM68KState, mmu.srp) }, + { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) }, + { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) }, + { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) }, + { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) }, + { "mmusr", offsetof(CPUM68KState, mmu.mmusr) }, + { NULL }, +}; + #include "hw/core/sysemu-cpu-ops.h" static const struct SysemuCPUOps m68k_sysemu_ops = { .has_work = m68k_cpu_has_work, .get_phys_page_debug = m68k_cpu_get_phys_page_debug, + .monitor_defs = m68k_monitor_defs, }; #endif /* !CONFIG_USER_ONLY */ diff --git a/target/m68k/monitor.c b/target/m68k/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/m68k/monitor.c +++ b/target/m68k/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) dump_mmu(env1); } - -static const MonitorDef monitor_defs[] = { - { "ssp", offsetof(CPUM68KState, sp[0]) }, - { "usp", offsetof(CPUM68KState, sp[1]) }, - { "isp", offsetof(CPUM68KState, sp[2]) }, - { "sfc", offsetof(CPUM68KState, sfc) }, - { "dfc", offsetof(CPUM68KState, dfc) }, - { "urp", offsetof(CPUM68KState, mmu.urp) }, - { "srp", offsetof(CPUM68KState, mmu.srp) }, - { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) }, - { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) }, - { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) }, - { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) }, - { "mmusr", offsetof(CPUM68KState, mmu.mmusr) }, - { NULL }, -}; - -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} -- 2.53.0
Restrict sparc64_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook (taking care to not register it on 32-bit SPARC target), allowing to remove the target_monitor_defs() method. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/sparc/cpu.c | 19 +++++++++++++++++++ target/sparc/monitor.c | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -XXX,XX +XXX,XX @@ static const Property sparc_cpu_properties[] = { }; #ifndef CONFIG_USER_ONLY + +#ifdef TARGET_SPARC64 +#include "monitor/hmp.h" + +static const MonitorDef sparc64_monitor_defs[] = { + { "asi", offsetof(CPUSPARCState, asi) }, + { "pstate", offsetof(CPUSPARCState, pstate) }, + { "cansave", offsetof(CPUSPARCState, cansave) }, + { "canrestore", offsetof(CPUSPARCState, canrestore) }, + { "otherwin", offsetof(CPUSPARCState, otherwin) }, + { "wstate", offsetof(CPUSPARCState, wstate) }, + { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, + { NULL }, +}; +#endif + #include "hw/core/sysemu-cpu-ops.h" static const struct SysemuCPUOps sparc_sysemu_ops = { .has_work = sparc_cpu_has_work, .get_phys_page_debug = sparc_cpu_get_phys_page_debug, .legacy_vmsd = &vmstate_sparc_cpu, +#if defined(TARGET_SPARC64) + .monitor_defs = sparc64_monitor_defs, +#endif }; #endif diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index XXXXXXX..XXXXXXX 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -XXX,XX +XXX,XX @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) } dump_mmu(env1); } - -const MonitorDef monitor_defs[] = { -#ifdef TARGET_SPARC64 - { "asi", offsetof(CPUSPARCState, asi) }, - { "pstate", offsetof(CPUSPARCState, pstate) }, - { "cansave", offsetof(CPUSPARCState, cansave) }, - { "canrestore", offsetof(CPUSPARCState, canrestore) }, - { "otherwin", offsetof(CPUSPARCState, otherwin) }, - { "wstate", offsetof(CPUSPARCState, wstate) }, - { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, -#endif - { NULL }, -}; - -const MonitorDef *target_monitor_defs(void) -{ - return monitor_defs; -} -- 2.53.0
target_monitor_defs() is now only a dead stub. Remove as pointless. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- include/monitor/hmp.h | 2 -- monitor/hmp.c | 2 +- stubs/target-monitor-defs.c | 7 ------- stubs/meson.build | 1 - 4 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 stubs/target-monitor-defs.c diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ struct MonitorDef { int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset); }; -const MonitorDef *target_monitor_defs(void); - CPUArchState *mon_get_cpu_env(Monitor *mon); CPUState *mon_get_cpu(Monitor *mon); diff --git a/monitor/hmp.c b/monitor/hmp.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -XXX,XX +XXX,XX @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) if (cs == NULL) { return -1; } - md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs(); + md = cs->cc->sysemu_ops->monitor_defs; if (md == NULL) { return -1; } diff --git a/stubs/target-monitor-defs.c b/stubs/target-monitor-defs.c deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/stubs/target-monitor-defs.c +++ /dev/null @@ -XXX,XX +XXX,XX @@ -#include "qemu/osdep.h" -#include "monitor/hmp.h" - -const MonitorDef *target_monitor_defs(void) -{ - return NULL; -} diff --git a/stubs/meson.build b/stubs/meson.build index XXXXXXX..XXXXXXX 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -XXX,XX +XXX,XX @@ if have_system stub_ss.add(files('igvm.c')) endif stub_ss.add(files('kvm.c')) - stub_ss.add(files('target-monitor-defs.c')) stub_ss.add(files('win32-kbd-hook.c')) stub_ss.add(files('xen-hw-stub.c')) stub_ss.add(files('qmp-arm-gic.c')) -- 2.53.0
hmp-target.c doesn't contain any target-specific code anymore. Merge it within hmp-cmds.c (which is already built once). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- MAINTAINERS | 1 - monitor/hmp-cmds.c | 40 ++++++++++++++++++++++++ monitor/hmp-target.c | 74 -------------------------------------------- monitor/meson.build | 3 -- 4 files changed, 40 insertions(+), 78 deletions(-) delete mode 100644 monitor/hmp-target.c diff --git a/MAINTAINERS b/MAINTAINERS index XXXXXXX..XXXXXXX 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -XXX,XX +XXX,XX @@ Human Monitor (HMP) M: Dr. David Alan Gilbert <dave@treblig.org> S: Maintained F: monitor/monitor-internal.h -F: monitor/hmp-target.c F: monitor/monitor.c F: monitor/hmp* F: hmp.h diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index XXXXXXX..XXXXXXX 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "system/address-spaces.h" #include "system/ioport.h" #include "exec/gdbstub.h" @@ -XXX,XX +XXX,XX @@ #include "monitor/hmp.h" #include "qemu/help_option.h" #include "monitor/hmp.h" +#include "monitor/hmp-completion.h" #include "monitor/monitor-internal.h" +#include "monitor/qdev.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" +#include "block/block-hmp-cmds.h" #include "qobject/qdict.h" #include "qemu/cutils.h" #include "qemu/log.h" +#include "net/slirp.h" +#include "system/device_tree.h" #include "system/hw_accel.h" #include "system/memory.h" #include "system/system.h" #include "disas/disas.h" +/* Please update hmp-commands.hx when adding or changing commands */ +static HMPCommand hmp_info_cmds[] = { +#include "hmp-commands-info.h" + { NULL, NULL, }, +}; + +/* hmp_cmds and hmp_info_cmds would be sorted at runtime */ +static HMPCommand hmp_cmds[] = { +#include "hmp-commands.h" + { NULL, NULL, }, +}; + +HMPCommand *hmp_cmds_for_target(bool info_command) +{ + return info_command ? hmp_info_cmds : hmp_cmds; +} + +static int +compare_mon_cmd(const void *a, const void *b) +{ + return strcmp(((const HMPCommand *)a)->name, + ((const HMPCommand *)b)->name); +} + +static void __attribute__((__constructor__)) sortcmdlist(void) +{ + qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1, + sizeof(*hmp_cmds), + compare_mon_cmd); + qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1, + sizeof(*hmp_info_cmds), + compare_mon_cmd); +} + bool hmp_handle_error(Monitor *mon, Error *err) { if (err) { diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c deleted file mode 100644 index XXXXXXX..XXXXXXX --- a/monitor/hmp-target.c +++ /dev/null @@ -XXX,XX +XXX,XX @@ -/* - * QEMU monitor, target-dependent part - * - * Copyright (c) 2003-2004 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "qemu/osdep.h" -#include "qemu/base-arch-defs.h" -#include "monitor-internal.h" -#include "monitor/qdev.h" -#include "net/slirp.h" -#include "system/device_tree.h" -#include "monitor/hmp.h" -#include "monitor/hmp-completion.h" -#include "block/block-hmp-cmds.h" -#include "qapi/qapi-commands-control.h" -#include "qapi/qapi-commands-misc.h" -#include "qapi/qapi-commands-machine.h" -#include "hw/core/sysemu-cpu-ops.h" - -/* Make devices configuration available for use in hmp-commands*.hx templates */ -#include CONFIG_DEVICES - -/* Please update hmp-commands.hx when adding or changing commands */ -static HMPCommand hmp_info_cmds[] = { -#include "hmp-commands-info.h" - { NULL, NULL, }, -}; - -/* hmp_cmds and hmp_info_cmds would be sorted at runtime */ -static HMPCommand hmp_cmds[] = { -#include "hmp-commands.h" - { NULL, NULL, }, -}; - -HMPCommand *hmp_cmds_for_target(bool info_command) -{ - return info_command ? hmp_info_cmds : hmp_cmds; -} - -static int -compare_mon_cmd(const void *a, const void *b) -{ - return strcmp(((const HMPCommand *)a)->name, - ((const HMPCommand *)b)->name); -} - -static void __attribute__((__constructor__)) sortcmdlist(void) -{ - qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1, - sizeof(*hmp_cmds), - compare_mon_cmd); - qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1, - sizeof(*hmp_info_cmds), - compare_mon_cmd); -} diff --git a/monitor/meson.build b/monitor/meson.build index XXXXXXX..XXXXXXX 100644 --- a/monitor/meson.build +++ b/monitor/meson.build @@ -XXX,XX +XXX,XX @@ system_ss.add(files( 'qemu-config-qmp.c', 'qmp-cmds.c', )) - -specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', - if_true: [files('hmp-target.c')]) -- 2.53.0
When converting 'info pic' to QMP in commit 795eaa62fa6 ("hw/intc: Introduce x-query-interrupt-controllers QMP command"), we forgot to remove the hmp_info_pic() declaration. Do it now. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/monitor/hmp.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index XXXXXXX..XXXXXXX 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -XXX,XX +XXX,XX @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vnc(Monitor *mon, const QDict *qdict); void hmp_info_spice(Monitor *mon, const QDict *qdict); void hmp_info_balloon(Monitor *mon, const QDict *qdict); -void hmp_info_pic(Monitor *mon, const QDict *qdict); void hmp_info_pci(Monitor *mon, const QDict *qdict); void hmp_info_tpm(Monitor *mon, const QDict *qdict); void hmp_info_iothreads(Monitor *mon, const QDict *qdict); -- 2.53.0