monitor/hmp: Reduce target-specific definitions
v4 cover monitor/hmp: Reduce target-specific definitions
Missing review: #2 and #7
v4: Remove duplicated hmp_info_via() declaration
v3: Rename MD_I32 -> MD_U32 (Dave)
v2: Change get_value() prototype signature, use ldn_he_p()
Move most of target-agnostic definitions from "monitor/hmp-target.h" to "monitor/hmp.h" to reduce files target-poisoning.
Philippe Mathieu-Daudé (9):
target/i386: Include missing 'svm.h' header in 'sev.h'
monitor: Reduce target-specific declarations
monitor: Add hmp_cmds_for_target() helper
monitor: Reduce target-specific methods
monitor: Have MonitorDef::get_value() return an unsigned type
monitor: Have *get_monitor_def() fill an unsigned value
monitor: Truncate target register using ldn_he_p() API
monitor: Reduce target-specific methods further
monitor: Remove 'monitor/hmp-target.h' header
MAINTAINERS | 2 +- include/hw/misc/mos6522.h | 2 - include/monitor/hmp-target.h | 64 ------------------- include/monitor/hmp.h | 30 +++++++++ monitor/monitor-internal.h | 10 ++- target/i386/sev.h | 2 + hw/i386/sgx-stub.c | 2 +- hw/i386/sgx.c | 2 +- monitor/hmp-cmds.c | 2 +- monitor/hmp-target.c | 108 +------------------------------ monitor/hmp.c | 116 ++++++++++++++++++++++++++++++++-- stubs/target-monitor-defs.c | 2 +- target/i386/cpu-apic.c | 2 +- target/i386/monitor.c | 9 ++- target/i386/sev-system-stub.c | 2 +- target/i386/sev.c | 2 +- target/m68k/monitor.c | 62 +++++++++--------- target/ppc/ppc-qmp-cmds.c | 26 ++++---- target/riscv/monitor.c | 2 +- target/riscv/riscv-qmp-cmds.c | 1 - target/sh4/monitor.c | 1 - target/sparc/monitor.c | 11 ++-- target/xtensa/monitor.c | 1 - 23 files changed, 214 insertions(+), 247 deletions(-) delete mode 100644 include/monitor/hmp-target.h
Signature · 1 line
2.52.0
PATCH v4 1/9 target/i386: Include missing 'svm.h' header in 'sev.h'
"target/i386/sev.h" uses the vmcb_seg structure type, which is defined in "target/i386/svm.h". Current builds succeed because the files including "target/i386/sev.h" also include "monitor/hmp-target.h", itself including "cpu.h" and finally "target/i386/svm.h".
Include the latter, otherwise removing "cpu.h" from "monitor/hmp-target.h" triggers:
../target/i386/sev.h:62:21: error: field has incomplete type 'struct vmcb_seg'
62 | struct vmcb_seg es;
| ^--- target/i386/sev.h | 2 ++ 1 file changed, 2 insertions(+)
target/i386/sev.h +2 -0
@@ -14,6 +14,8 @@#ifndef I386_SEV_H #define I386_SEV_H +#include "target/i386/svm.h" +#ifndef CONFIG_USER_ONLY #include CONFIG_DEVICES /* CONFIG_SEV */ #endif
Signature · 1 line
2.52.0
PATCH v4 2/9 monitor: Reduce target-specific declarations
In reply to Philippe Mathieu-DaudéSome declarations do not depend on target-specific types, move them out of "monitor/hmp-target.h" to "monitor/hmp.h".
Commit 409e9f7131e ("mos6522: add "info via" HMP command for debugging") declared hmp_info_via() is declared twice. Remove the one in "hw/misc/mos6522.h" otherwise we get:
In file included from ../hw/misc/mos6522.c:33:
include/monitor/hmp.h:43:6: error: redundant redeclaration of 'hmp_info_via' [-Werror=redundant-decls]
43 | void hmp_info_via(Monitor *mon, const QDict *qdict);
| ^~~~~~~~~~~~
In file included from ../hw/misc/mos6522.c:29:
include/hw/misc/mos6522.h:175:6: note: previous declaration of 'hmp_info_via' with type 'void(Monitor *, const QDict *)'
175 | void hmp_info_via(Monitor *mon, const QDict *qdict);
| ^~~~~~~~~~~~--- include/hw/misc/mos6522.h | 2 -- include/monitor/hmp-target.h | 14 -------------- include/monitor/hmp.h | 13 +++++++++++++ hw/i386/sgx-stub.c | 1 + hw/i386/sgx.c | 1 + monitor/hmp-cmds.c | 1 + target/i386/cpu-apic.c | 1 + target/i386/sev-system-stub.c | 1 + target/i386/sev.c | 1 + target/m68k/monitor.c | 1 + target/riscv/monitor.c | 1 + 11 files changed, 21 insertions(+), 16 deletions(-)
include/hw/misc/mos6522.h +0 -2
@@ -172,6 +172,4 @@ extern const VMStateDescription vmstate_mos6522;uint64_t mos6522_read (void *opaque,hwaddr addr,unsigned size);void mos6522_write (void *opaque,hwaddr addr,uint64_t val,unsigned size); -void hmp_info_via (Monitor *mon,const QDict *qdict); -#endif /* MOS6522_H */
include/monitor/hmp-target.h +0 -14
@@ -47,18 +47,4 @@ 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); -void hmp_info_mem (Monitor *mon,const QDict *qdict); -void hmp_info_tlb (Monitor *mon,const QDict *qdict); -void hmp_mce (Monitor *mon,const QDict *qdict); -void hmp_info_local_apic (Monitor *mon,const QDict *qdict); -void hmp_info_sev (Monitor *mon,const QDict *qdict); -void hmp_info_sgx (Monitor *mon,const QDict *qdict); -void hmp_info_via (Monitor *mon,const QDict *qdict); -void hmp_memory_dump (Monitor *mon,const QDict *qdict); -void hmp_physical_memory_dump (Monitor *mon,const QDict *qdict); -void hmp_info_registers (Monitor *mon,const QDict *qdict); -void hmp_gva2gpa (Monitor *mon,const QDict *qdict); -void hmp_gpa2hva (Monitor *mon,const QDict *qdict); -void hmp_gpa2hpa (Monitor *mon,const QDict *qdict); -#endif /* MONITOR_HMP_TARGET_H */
include/monitor/hmp.h +13 -0
@@ -180,5 +180,18 @@ void hmp_info_mtree(Monitor *mon, const QDict *qdict);void hmp_info_cryptodev (Monitor *mon,const QDict *qdict);void hmp_dumpdtb (Monitor *mon,const QDict *qdict);void hmp_info_firmware_log (Monitor *mon,const QDict *qdict); +void hmp_info_mem (Monitor *mon,const QDict *qdict); +void hmp_info_tlb (Monitor *mon,const QDict *qdict); +void hmp_mce (Monitor *mon,const QDict *qdict); +void hmp_info_local_apic (Monitor *mon,const QDict *qdict); +void hmp_info_sev (Monitor *mon,const QDict *qdict); +void hmp_info_sgx (Monitor *mon,const QDict *qdict); +void hmp_info_via (Monitor *mon,const QDict *qdict); +void hmp_memory_dump (Monitor *mon,const QDict *qdict); +void hmp_physical_memory_dump (Monitor *mon,const QDict *qdict); +void hmp_info_registers (Monitor *mon,const QDict *qdict); +void hmp_gva2gpa (Monitor *mon,const QDict *qdict); +void hmp_gpa2hva (Monitor *mon,const QDict *qdict); +void hmp_gpa2hpa (Monitor *mon,const QDict *qdict);#endif
hw/i386/sgx-stub.c +1 -0
@@ -1,5 +1,6 @@#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"
hw/i386/sgx.c +1 -0
@@ -16,6 +16,7 @@#include "hw/mem/memory-device.h" #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"
monitor/hmp-cmds.c +1 -0
@@ -21,6 +21,7 @@#include "gdbstub/enums.h" #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"
target/i386/cpu-apic.c +1 -0
@@ -10,6 +10,7 @@#include "qobject/qdict.h" #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"
target/i386/sev-system-stub.c +1 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "monitor/hmp-target.h" #include "qapi/error.h" #include "sev.h"
target/i386/sev.c +1 -0
@@ -36,6 +36,7 @@#include "migration/blocker.h" #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"
target/m68k/monitor.c +1 -0
@@ -7,6 +7,7 @@#include "qemu/osdep.h" #include "cpu.h" +#include "monitor/hmp.h" #include "monitor/hmp-target.h" #include "monitor/monitor.h"
target/riscv/monitor.c +1 -0
@@ -22,6 +22,7 @@#include "cpu.h" #include "cpu_bits.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "monitor/hmp-target.h" #include "system/memory.h"
Signature · 1 line
2.52.0
PATCH v4 3/9 monitor: Add hmp_cmds_for_target() helper
In reply to Philippe Mathieu-DaudéHMPCommand arrays are filled with target-specific commands, so defined in a target-specific unit. Introduce the hmp_cmds_for_target() to allow target-agnostic code to access the arrays.
--- monitor/monitor-internal.h | 9 +++++++-- monitor/hmp-target.c | 13 ++++++++----- monitor/hmp.c | 8 +++++--- 3 files changed, 20 insertions(+), 10 deletions(-)
monitor/monitor-internal.h +7 -2
@@ -169,8 +169,6 @@ extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands;extern QemuMutex monitor_lock;extern MonitorList mon_list; -extern HMPCommand hmp_cmds[]; -void monitor_data_init (Monitor *mon,bool is_qmp,bool skip_flush,bool use_io_thread);void monitor_data_destroy (Monitor *mon);
@@ -187,4 +185,11 @@ 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); +/* +* hmp_cmds_for_target: Return array of HMPCommand entries +* +* If @info_command is true, return the particular 'info foo' commands array. +*/ +HMPCommand *hmp_cmds_for_target (bool info_command); +#endif
monitor/hmp-target.c +8 -5
@@ -44,8 +44,6 @@/* Make devices configuration available for use in hmp-commands*.hx templates */ #include CONFIG_DEVICES -static HMPCommand hmp_info_cmds[]; -/** * Is @name in the '|' separated list of names @list? */
@@ -76,11 +74,16 @@ static HMPCommand hmp_info_cmds[] = { };/* hmp_cmds and hmp_info_cmds would be sorted at runtime */ -HMPCommand hmp_cmds[] = { +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; +} +/* * Set @pval to the value in the register identified by @name. * return 0 if OK, -1 if not found
@@ -148,7 +151,7 @@ static void __attribute__((__constructor__)) sortcmdlist(void)void monitor_register_hmp (const char *name,bool info,void (*cmd)(Monitor *mon,const QDict *qdict)) { -HMPCommand *table = info ? hmp_info_cmds : hmp_cmds; +HMPCommand *table =hmp_cmds_for_target (info);while (table->name !=NULL ) {if (strcmp (table->name, name) ==0 ) {
@@ -164,7 +167,7 @@ void monitor_register_hmp(const char *name, bool info,void monitor_register_hmp_info_hrt (const char *name,HumanReadableText *(*handler)(Error **errp)) { -HMPCommand *table = hmp_info_cmds; +HMPCommand *table =hmp_cmds_for_target (true);while (table->name !=NULL ) {if (strcmp (table->name, name) ==0 ) {
monitor/hmp.c +5 -3
@@ -301,7 +301,7 @@ void hmp_help_cmd(Monitor *mon, const char *name) }/* 2. dump the contents according to parsed args */ -help_cmd_dump (mon, hmp_cmds, args, nb_args,0 ); +help_cmd_dump (mon,hmp_cmds_for_target (false), args, nb_args,0 );free_cmdline_args (args, nb_args); }
@@ -1131,7 +1131,8 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)trace_handle_hmp_command (mon, cmdline); - cmd =monitor_parse_command (mon, cmdline, &cmdline, hmp_cmds); + cmd =monitor_parse_command (mon, cmdline, &cmdline, +hmp_cmds_for_target (false));if (!cmd) {return ; }
@@ -1375,7 +1376,8 @@ static void monitor_find_completion(void *opaque, }/* 2. auto complete according to args */ -monitor_find_completion_by_table (mon, hmp_cmds, args, nb_args); +monitor_find_completion_by_table (mon,hmp_cmds_for_target (false), + args, nb_args); cleanup:free_cmdline_args (args, nb_args);
Signature · 1 line
2.52.0
PATCH v4 4/9 monitor: Reduce target-specific methods
In reply to Philippe Mathieu-DaudéThe following methods don't use target-specific code anymore:
- hmp_compare_cmd()
- monitor_register_hmp()
- monitor_register_hmp_info_hrt()
Move them to hmp.c which is target-agnostic, being built once.
--- monitor/hmp-target.c | 57 -------------------------------------------- monitor/hmp.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 57 deletions(-)
monitor/hmp-target.c +0 -57
@@ -33,8 +33,6 @@#include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" -#include "qapi/error.h" -#include "qemu/cutils.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
@@ -44,29 +42,6 @@/* Make devices configuration available for use in hmp-commands*.hx templates */ #include CONFIG_DEVICES -/** -* Is @name in the '|' separated list of names @list? -*/ -int hmp_compare_cmd (const char *name,const char *list) -{ -const char *p, *pstart; -int len; - len =strlen (name); - p = list; -for (;;) { - pstart = p; - p =qemu_strchrnul (p,'|' ); -if ((p - pstart) == len && !memcmp (pstart, name, len)) { -return 1 ; - } -if (*p =='\0' ) { -break ; - } - p++; - } -return 0 ; -} -/* Please update hmp-commands.hx when adding or changing commands */ static HMPCommand hmp_info_cmds[] = { #include "hmp-commands-info.h"
@@ -147,35 +122,3 @@ static void __attribute__((__constructor__)) sortcmdlist(void)sizeof (*hmp_info_cmds), compare_mon_cmd); } - -void monitor_register_hmp (const char *name,bool info, -void (*cmd)(Monitor *mon,const QDict *qdict)) -{ -HMPCommand *table =hmp_cmds_for_target (info); - -while (table->name !=NULL ) { -if (strcmp (table->name, name) ==0 ) { -g_assert (table->cmd ==NULL && table->cmd_info_hrt ==NULL ); - table->cmd = cmd; -return ; - } - table++; - } -g_assert_not_reached (); -} - -void monitor_register_hmp_info_hrt (const char *name, -HumanReadableText *(*handler)(Error **errp)) -{ -HMPCommand *table =hmp_cmds_for_target (true); - -while (table->name !=NULL ) { -if (strcmp (table->name, name) ==0 ) { -g_assert (table->cmd ==NULL && table->cmd_info_hrt ==NULL ); - table->cmd_info_hrt = handler; -return ; - } - table++; - } -g_assert_not_reached (); -}
monitor/hmp.c +55 -0
58 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v4 5/9 monitor: Have MonitorDef::get_value() return an unsigned type
In reply to Philippe Mathieu-DaudéAll implementations of the get_value() handler return an unsigned type:
- target/i386/monitor.c
monitor_get_pc() -> target_ulong eip;
- target/ppc/ppc-qmp-cmds.c
monitor_get_ccr() -> uint64_t ppc_get_cr(const CPUPPCState *env); monitor_get_xer() -> target_ulong cpu_read_xer(const CPUPPCState *env); monitor_get_decr() -> target_ulong cpu_ppc_load_decr(CPUPPCState *env); monitor_get_tbu() -> uint32_t cpu_ppc_load_tbu(CPUPPCState *env); monitor_get_tbl() -> uint64_t cpu_ppc_load_tbl(CPUPPCState *env);
- target/sparc/monitor.c
monitor_get_psr() -> target_ulong cpu_get_psr(CPUSPARCState *env1); monitor_get_reg() -> target_ulong *regwptr;
Convert the MonitorDef::get_value() handler to return unsigned.
Rename the MD_I32/MD_TLONG definitions mechanically doing:
$ sed -i -e s/MD_I32/MD_U32/g $(git grep -lw MD_I32) $ sed -i -e s/MD_TLONG/MD_TULONG/g $(git grep -lw MD_TLONG)
--- include/monitor/hmp-target.h | 7 ++--- monitor/hmp-target.c | 12 ++++---- target/i386/monitor.c | 8 ++--- target/m68k/monitor.c | 60 ++++++++++++++++++------------------ target/ppc/ppc-qmp-cmds.c | 25 +++++++-------- target/sparc/monitor.c | 10 +++--- 6 files changed, 59 insertions(+), 63 deletions(-)
include/monitor/hmp-target.h +3 -4
@@ -32,14 +32,13 @@ typedef struct MonitorDef MonitorDef;struct MonitorDef {const char *name;int offset; -target_long (*get_value)(Monitor *mon,const struct MonitorDef *md, -int val); +uint64_t (*get_value)(Monitor *mon,const struct MonitorDef *md,int val);int type; };#endif -#define MD_TLONG 0 -#define MD_I32 1 +#define MD_TULONG 0 +#define MD_U32 1const MonitorDef *target_monitor_defs (void );int target_get_monitor_def (CPUState *cs,const char *name,uint64_t *pval);
monitor/hmp-target.c +6 -6
@@ -67,7 +67,6 @@ 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;
@@ -81,13 +80,14 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) *pval = md->get_value (mon, md, md->offset); }else {CPUArchState *env =mon_get_cpu_env (mon); - ptr = (uint8_t *)env + md->offset; +void *ptr = (uint8_t *)env + md->offset; +switch (md->type) { -case MD_I32 : - *pval = *(int32_t *)ptr; +case MD_U32 : + *pval = *(uint32_t *)ptr;break ; -case MD_TLONG : - *pval = *(target_long *)ptr; +case MD_TULONG : + *pval = *(target_ulong *)ptr;break ;default : *pval =0 ;
target/i386/monitor.c +4 -4
@@ -593,8 +593,8 @@ void hmp_mce(Monitor *mon, const QDict *qdict) } } -static target_long monitor_get_pc (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_pc (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);return env->eip + env->segs[R_CS ].base;
@@ -602,9 +602,9 @@ static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md,const MonitorDef monitor_defs[] = { #define SEG(name, seg) \ - { name, offsetof(CPUX86State, segs[seg].selector), NULL, MD_I32 },\ + { name, offsetof(CPUX86State, segs[seg].selector), NULL, MD_U32 },\ { name ".base", offsetof(CPUX86State, segs[seg].base) },\ - { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_I32 }, + { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_U32 }, { "eax", offsetof(CPUX86State, regs[0]) }, { "ecx", offsetof(CPUX86State, regs[1]) },
target/m68k/monitor.c +30 -30
66 lines not on this page · raw message
target/ppc/ppc-qmp-cmds.c +11 -14
@@ -33,26 +33,23 @@#include "cpu-models.h" #include "cpu-qom.h" -static target_long monitor_get_ccr (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_ccr (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon); -unsigned int u; - u =ppc_get_cr (env); - -return u; +return ppc_get_cr (env); } -static target_long monitor_get_xer (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_xer (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);return cpu_read_xer (env); } -static target_long monitor_get_decr (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_decr (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);if (!env->tb_env) {
@@ -61,8 +58,8 @@ static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md,return cpu_ppc_load_decr (env); } -static target_long monitor_get_tbu (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_tbu (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);if (!env->tb_env) {
@@ -71,8 +68,8 @@ static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md,return cpu_ppc_load_tbu (env); } -static target_long monitor_get_tbl (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_tbl (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);if (!env->tb_env) {
target/sparc/monitor.c +5 -5
@@ -40,8 +40,8 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) }#ifndef TARGET_SPARC64 -static target_long monitor_get_psr (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_psr (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);
@@ -49,8 +49,8 @@ static target_long monitor_get_psr(Monitor *mon, const struct MonitorDef *md, }#endif -static target_long monitor_get_reg (Monitor *mon,const struct MonitorDef *md, -int val) +static uint64_t monitor_get_reg (Monitor *mon,const struct MonitorDef *md, +int val) {CPUArchState *env =mon_get_cpu_env (mon);return env->regwptr[val];
@@ -154,7 +154,7 @@ const MonitorDef monitor_defs[] = { { "otherwin", offsetof(CPUSPARCState, otherwin) }, { "wstate", offsetof(CPUSPARCState, wstate) }, { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, - { "fprs", offsetof(CPUSPARCState, fprs), NULL, MD_I32 }, + { "fprs", offsetof(CPUSPARCState, fprs), NULL, MD_U32 }, #endif { NULL }, };
Signature · 1 line
2.52.0
PATCH v4 6/9 monitor: Have *get_monitor_def() fill an unsigned value
In reply to Philippe Mathieu-Daudétarget_get_monitor_def() fills an unsigned value. Have get_monitor_def() fill an unsigned value too.
--- monitor/monitor-internal.h | 2 +- monitor/hmp-target.c | 4 ++-- monitor/hmp.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
monitor/monitor-internal.h +1 -1
@@ -181,7 +181,7 @@ 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); +int get_monitor_def (Monitor *mon,uint64_t *pval,const char *name);void handle_hmp_command (MonitorHMP *mon,const char *cmdline);int hmp_compare_cmd (const char *name,const char *list);
monitor/hmp-target.c +2 -2
@@ -63,7 +63,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)* 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) +int get_monitor_def (Monitor *mon,uint64_t *pval,const char *name) {const MonitorDef *md =target_monitor_defs ();CPUState *cs =mon_get_cpu (mon);
@@ -100,7 +100,7 @@ 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; + *pval = (target_ulong )tmp; }return ret;
monitor/hmp.c +1 -1
@@ -376,7 +376,7 @@ static int64_t expr_unary(Monitor *mon)case '$' : {char buf[128 ], *q; -int64_t reg =0 ; +uint64_t reg =0 ; pch++; q = buf;
Signature · 1 line
2.52.0
PATCH v4 7/9 monitor: Truncate target register using ldn_he_p() API
In reply to Philippe Mathieu-DaudéRather than truncating with a target_long cast, use the unaligned load/store API.
--- include/monitor/hmp-target.h | 3 --- monitor/hmp-target.c | 8 +++++--- 2 files changed, 5 insertions(+), 6 deletions(-)
include/monitor/hmp-target.h +0 -3
@@ -27,15 +27,12 @@typedef struct MonitorDef MonitorDef ; -#ifdef COMPILING_PER_TARGET -#include "cpu.h" struct MonitorDef {const char *name;int offset;uint64_t (*get_value)(Monitor *mon,const struct MonitorDef *md,int val);int type; }; -#endif #define MD_TULONG 0#define MD_U32 1
monitor/hmp-target.c +5 -3
@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h"
@@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)*/ int get_monitor_def (Monitor *mon,uint64_t *pval,const char *name) { +const unsigned length =target_long_bits () /8 ;const MonitorDef *md =target_monitor_defs ();CPUState *cs =mon_get_cpu (mon);uint64_t tmp =0 ;
@@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)void *ptr = (uint8_t *)env + md->offset;switch (md->type) { -case MD_U32 : +case MD_I32 : *pval = *(uint32_t *)ptr;break ;case MD_TULONG : - *pval = *(target_ulong *)ptr; + *pval =ldn_he_p (ptr, length);break ;default : *pval =0 ;
@@ -100,7 +102,7 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) ret =target_get_monitor_def (cs, name, &tmp);if (!ret) { - *pval = (target_ulong )tmp; + *pval =ldn_he_p (&tmp, length); }return ret;
Signature · 1 line
2.52.0
Re: [PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API
Quoted 50 lines · Philippe Mathieu-Daudé
Rather than truncating with a
target_longcast, use the unaligned load/store API.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
include/monitor/hmp-target.h| 3 ---monitor/hmp-target.c| 8 +++++---2 files changed, 5 insertions(+), 6 deletions(-)include/monitor/hmp-target.h +0
-3@@ -27,15 +27,12 @@typedef struct MonitorDef MonitorDef ; -#ifdef COMPILING_PER_TARGET -#include "cpu.h" struct MonitorDef {const char *name;int offset;uint64_t (*get_value)(Monitor *mon,const struct MonitorDef *md,int val);int type; }; -#endif #define MD_TULONG 0#define MD_U32 1monitor/hmp-target.c +2
-0@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h" @@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)*/ int get_monitor_def (Monitor *mon,uint64_t *pval,const char *name) { +const unsigned length =target_long_bits () /8 ;const MonitorDef *md =target_monitor_defs ();CPUState *cs =mon_get_cpu (mon);uint64_t tmp =0 ;
monitor/hmp-target.c int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) · line 88
Quoted 5 lines
monitor/hmp-target.c +1
-1@@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name)void *ptr = (uint8_t *)env + md->offset;switch (md->type) { -case MD_U32 : +case MD_I32 :
Why is this changed? Doesn't seem to be realted to what the commit message says.
Regards,
BALATON Zoltan
Quoted 18 lines
monitor/hmp-target.c +2
-2*pval = *(uint32_t *)ptr;break ;case MD_TULONG : - *pval = *(target_ulong *)ptr; + *pval =ldn_he_p (ptr, length);break ;default : *pval =0 ;@@ -100,7 +102,7 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) ret =target_get_monitor_def (cs, name, &tmp);if (!ret) { - *pval = (target_ulong )tmp; + *pval =ldn_he_p (&tmp, length); }return ret;
Re: [PATCH v4 7/9] monitor: Truncate target register using ldn_he_p() API
Quoted 35 lines · BALATON Zoltan
Quoted 34 lines · Philippe Mathieu-Daudé
Rather than truncating with a
target_longcast, use the unaligned load/store API.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
include/monitor/hmp-target.h| 3 ---
monitor/hmp-target.c | 8 +++++---2 files changed, 5 insertions(+), 6 deletions(-)monitor/hmp-target.c +2
-0@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h" @@ -65,6 +66,7 @@ HMPCommand *hmp_cmds_for_target(bool info_command)*/ int get_monitor_def (Monitor *mon,uint64_t *pval,const char *name) { + const unsigned length = target_long_bits() / 8; const MonitorDef *md = target_monitor_defs(); CPUState *cs = mon_get_cpu(mon); uint64_t tmp = 0;@@ -83,11 +85,11 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) void *ptr = (uint8_t *)env + md->offset;
Quoted 5 lines
monitor/hmp-target.c int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) · line 88
Quoted 3 lines
monitor/hmp-target.c +1
-1switch(md->type) { - case MD_U32: + case MD_I32:Why is this changed? Doesn't seem to be realted to what the commit message says.
Good catch! This is due to a broken rebase I suppose. The change is explained in patch #5 "monitor: Have MonitorDef::get_value() return an unsigned type".
I'll clean that up and respin.
PATCH v4 8/9 monitor: Reduce target-specific methods further
In reply to Philippe Mathieu-Daudéget_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once.
--- monitor/monitor-internal.h | 1 - monitor/hmp-target.c | 49 ----------------------------------- monitor/hmp.c | 52 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 50 deletions(-)
monitor/monitor-internal.h +0 -1
@@ -181,7 +181,6 @@ 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,uint64_t *pval,const char *name);void handle_hmp_command (MonitorHMP *mon,const char *cmdline);int hmp_compare_cmd (const char *name,const char *list);
monitor/hmp-target.c +0 -49
61 lines not on this page · raw message
monitor/hmp.c +52 -0
69 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v4 9/9 monitor: Remove 'monitor/hmp-target.h' header
In reply to Philippe Mathieu-DaudéThe "monitor/hmp-target.h" header doesn't contain any target-specific declarations anymore. Merge it with "monitor/hmp.h", its target-agnostic counterpart.
--- MAINTAINERS | 2 +- include/monitor/hmp-target.h | 46 ----------------------------------- include/monitor/hmp.h | 17 +++++++++++++ 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/ppc-qmp-cmds.c | 1 - target/riscv/monitor.c | 1 - target/riscv/riscv-qmp-cmds.c | 1 - target/sh4/monitor.c | 1 - target/sparc/monitor.c | 1 - target/xtensa/monitor.c | 1 - 20 files changed, 19 insertions(+), 64 deletions(-) delete mode 100644 include/monitor/hmp-target.h
MAINTAINERS +1 -1
@@ -3385,7 +3385,7 @@ F: monitor/monitor.c F: monitor/hmp* F: hmp.h F: hmp-commands*.hx -F: include/monitor/hmp-target.h +F: include/monitor/hmp.h F: tests/qtest/test-hmp.c F: include/qemu/qemu-print.h F: util/qemu-print.c
include/monitor/hmp-target.h deleted +0 -46
46 lines not on this page · raw message
include/monitor/hmp.h +17 -0
@@ -17,6 +17,23 @@#include "qemu/readline.h" #include "qapi/qapi-types-common.h" +typedef struct MonitorDef { +const char *name; +int offset; +uint64_t (*get_value)(Monitor *mon,const struct MonitorDef *md,int val); +int type; +}MonitorDef ; + +#define MD_TULONG 0 +#define MD_U32 1 + +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); +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);
hw/i386/sgx-stub.c +0 -1
@@ -1,7 +1,6 @@#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"
hw/i386/sgx.c +0 -1
@@ -17,7 +17,6 @@#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"
monitor/hmp-cmds.c +0 -1
@@ -22,7 +22,6 @@#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"
monitor/hmp-target.c +0 -1
@@ -27,7 +27,6 @@#include "monitor/qdev.h" #include "net/slirp.h" #include "system/device_tree.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "block/block-hmp-cmds.h" #include "qapi/qapi-commands-control.h"
monitor/hmp.c +0 -1
@@ -27,7 +27,6 @@#include "hw/core/qdev.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"
stubs/target-monitor-defs.c +1 -1
@@ -1,5 +1,5 @@#include "qemu/osdep.h" -#include "monitor/hmp-target.h" +#include "monitor/hmp.h" const MonitorDef *target_monitor_defs (void ) {
target/i386/cpu-apic.c +0 -1
@@ -11,7 +11,6 @@#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"
target/i386/monitor.c +0 -1
@@ -25,7 +25,6 @@#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"
target/i386/sev-system-stub.c +0 -1
@@ -14,7 +14,6 @@#include "qemu/osdep.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "qapi/error.h" #include "sev.h"
target/i386/sev.c +0 -1
@@ -37,7 +37,6 @@#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"
target/m68k/monitor.c +0 -1
@@ -8,7 +8,6 @@#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)
target/ppc/ppc-qmp-cmds.c +0 -1
@@ -26,7 +26,6 @@#include "cpu.h" #include "monitor/monitor.h" #include "qemu/ctype.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "qapi/error.h" #include "qapi/qapi-commands-machine.h"
target/riscv/monitor.c +0 -1
@@ -23,7 +23,6 @@#include "cpu_bits.h" #include "monitor/monitor.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "system/memory.h" #ifdef TARGET_RISCV64
target/riscv/riscv-qmp-cmds.c +0 -1
@@ -34,7 +34,6 @@#include "qemu/ctype.h" #include "qemu/qemu-print.h" #include "monitor/hmp.h" -#include "monitor/hmp-target.h" #include "system/kvm.h" #include "system/tcg.h" #include "cpu-qom.h"
target/sh4/monitor.c +0 -1
@@ -24,7 +24,6 @@#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)
target/sparc/monitor.c +0 -1
@@ -24,7 +24,6 @@#include "qemu/osdep.h" #include "cpu.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h"
target/xtensa/monitor.c +0 -1
@@ -24,7 +24,6 @@#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)
Signature · 1 line
2.52.0