monitor/hmp: Reduce target-specific definitions
v6 cover monitor/hmp: Reduce target-specific definitions
v6: Keep signed (Pierrick)
v5: Fixed mis-rebase (Zoltan)
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é (6):
target/sparc/monitor: Dump all registers as 32-bit
monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32
monitor: Have MonitorDef::get_value() always return int64_t type
monitor: Remove last target_long use in get_monitor_def()
monitor: Reduce target-specific methods further
monitor: Remove 'monitor/hmp-target.h' header
MAINTAINERS | 2 +- include/monitor/hmp-target.h | 50 ----------------------------------- include/monitor/hmp.h | 12 +++++++++ monitor/monitor-internal.h | 1 - hw/i386/sgx-stub.c | 1 - hw/i386/sgx.c | 1 - monitor/hmp-cmds.c | 1 - monitor/hmp-target.c | 48 --------------------------------- monitor/hmp.c | 41 +++++++++++++++++++++++++++- stubs/target-monitor-defs.c | 2 +- target/i386/cpu-apic.c | 1 - target/i386/monitor.c | 7 +++-- target/i386/sev-system-stub.c | 1 - target/i386/sev.c | 1 - target/m68k/monitor.c | 25 +++++++++--------- 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 - 20 files changed, 69 insertions(+), 131 deletions(-) delete mode 100644 include/monitor/hmp-target.h
Signature · 1 line
2.53.0
PATCH v6 1/6 target/sparc/monitor: Dump all registers as 32-bit
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.
--- target/sparc/monitor.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
target/sparc/monitor.c +7 -7
@@ -41,13 +41,13 @@ 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 }, };
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 v6 1/6] target/sparc/monitor: Dump all registers as 32-bit
Quoted 10 lines · Philippe Mathieu-Daudé
All these SPARC64 registers are 32-bit since their introduction in commit
3475187dd81("sparc64 merge"), seetarget/sparc/cpu.h:511 #if defined(TARGET_SPARC64) ... 515 uint32_t asi; 516 uint32_t pstate; ... 519 uint32_t cansave, canrestore, otherwin, wstate, cleanwin;
Quoted 7 lines
Set
MonitorDef::typetoMD_I32to dump them as 32-bit.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/sparc/monitor.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Re: [PATCH-for-11.1 v6 1/6] target/sparc/monitor: Dump all registers as 32-bit
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
All these SPARC64 registers are 32-bit since their introduction in commit
3475187dd81("sparc64 merge"), seetarget/sparc/cpu.h:511 #if
defined(TARGET_SPARC64)
...
515uint32_tasi;
516uint32_tpstate;
...
519uint32_tcansave, canrestore, otherwin, wstate, cleanwin;Set
MonitorDef::typetoMD_I32to dump them as 32-bit.
What are they dumped as before this patch?
Quoted 30 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/sparc/monitor.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)target/sparc/monitor.c +7
-7@@ -41,13 +41,13 @@ 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 }, };
Re: [PATCH-for-11.1 v6 1/6] target/sparc/monitor: Dump all registers as 32-bit
Quoted 12 lines · Markus Armbruster
Quoted 10 lines · Philippe Mathieu-Daudé
All these SPARC64 registers are 32-bit since their introduction in commit
3475187dd81("sparc64 merge"), seetarget/sparc/cpu.h:511 #if defined(TARGET_SPARC64) ... 515 uint32_t asi; 516 uint32_t pstate; ... 519 uint32_t cansave, canrestore, otherwin, wstate, cleanwin;
Quoted 3 lines
Quoted 1 line
Set
MonitorDef::typetoMD_I32to dump them as 32-bit.What are they dumped as before this patch?
target_long, so pointlessly unsigned sign-extended. I'll mention.
Quoted 32 lines
Quoted 31 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/sparc/monitor.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)target/sparc/monitor.c +7
-7@@ -41,13 +41,13 @@ 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 }, };
PATCH v6 2/6 monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32
In reply to Philippe Mathieu-Daudé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.
--- 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(-)
include/monitor/hmp-target.h +0 -4
@@ -34,13 +34,9 @@ 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);
monitor/hmp-target.c +1 -11
@@ -82,17 +82,7 @@ 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 ; }
target/i386/monitor.c +1 -1
@@ -602,7 +602,7 @@ 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 )
target/m68k/monitor.c +12 -12
@@ -24,18 +24,18 @@ 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 }, };
target/sparc/monitor.c +7 -7
@@ -41,13 +41,13 @@ 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 }, };
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 v6 2/6] monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32
Quoted 5 lines · Philippe Mathieu-Daudé
None of the few targets still using MonitorDef use
MD_TLONG, they either useMD_I32or the %get_value handler. Remove theMonitorDef::typeand its definitions altogether: simply check for the %get_value handler, if NULL then consider 32-bit.
Quoted 9 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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(-)
Re: [PATCH-for-11.1 v6 2/6] monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32
In reply to Philippe Mathieu-DaudéQuoted 118 lines · Philippe Mathieu-Daudé
None of the few targets still using MonitorDef use
MD_TLONG, they either useMD_I32or the %get_value handler. Remove theMonitorDef::typeand its definitions altogether: simply check for the %get_value handler, if NULL then consider 32-bit.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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(-)include/monitor/hmp-target.h +0
-4@@ -34,13 +34,9 @@ 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);monitor/hmp-target.c +1
-11@@ -82,17 +82,7 @@ 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 ; }target/i386/monitor.c +1
-1@@ -602,7 +602,7 @@ 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 )target/m68k/monitor.c +12
-12@@ -24,18 +24,18 @@ 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 }, };target/sparc/monitor.c +0
-7@@ -41,13 +41,13 @@ 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 },
target/sparc/monitor.c void hmp_info_tlb(Monitor *mon, const QDict *qdict) · line 53
Quoted 10 lines
target/sparc/monitor.c +7
-0+ { "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 }, };
Doesn't this completely revert patch 1?
r~
Re: [PATCH-for-11.1 v6 2/6] monitor: Remove MonitorDef::type field and MD_TLONG / MD_I32
Quoted 34 lines · Richard Henderson
Quoted 33 lines · Philippe Mathieu-Daudé
None of the few targets still using MonitorDef use
MD_TLONG, they either useMD_I32or the %get_value handler. Remove theMonitorDef::typeand its definitions altogether: simply check for the %get_value handler, if NULL then consider 32-bit.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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(-)target/sparc/monitor.c +4
-7@@ -41,13 +41,13 @@ 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) },
Quoted 8 lines
target/sparc/monitor.c void hmp_info_tlb(Monitor *mon, const QDict *qdict) · line 53
Quoted 6 lines
target/sparc/monitor.c +3
-0+ { "otherwin", offsetof(CPUSPARCState, otherwin) }, + { "wstate", offsetof(CPUSPARCState, wstate) }, + { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, #endif { NULL }, };Doesn't this completely revert patch 1?
Indeed. While being a revert, the previous patch makes this removal trivial (no need to justify the 64-bit path).
PATCH v6 3/6 monitor: Have MonitorDef::get_value() always return int64_t type
In reply to Philippe Mathieu-DaudéSimplify MonitorDef::get_value() handler by having it always return a int64_t type. Truncate to 32-bit in the single caller.
Note, this handler is only implemented once for the x86 targets.
--- include/monitor/hmp-target.h | 6 +----- monitor/hmp-target.c | 5 ++++- target/i386/monitor.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-)
include/monitor/hmp-target.h +1 -5
@@ -27,15 +27,11 @@typedef struct MonitorDef MonitorDef ; -#ifdef COMPILING_PER_TARGET -#include "cpu.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 struct MonitorDef *md,int offset); }; -#endif const MonitorDef *target_monitor_defs (void );int target_get_monitor_def (CPUState *cs,const char *name,uint64_t *pval);
monitor/hmp-target.c +4 -1
@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" +#include "qemu/target-info.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h"
@@ -33,6 +34,7 @@#include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" +#include "exec/target_long.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val; }else {CPUArchState *env =mon_get_cpu_env (mon); ptr = (uint8_t *)env + md->offset;
target/i386/monitor.c +2 -2
@@ -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 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;
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/monitor/hmp-target.h | 6 +----- monitor/hmp-target.c | 5 ++++- target/i386/monitor.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-)
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
In reply to Philippe Mathieu-DaudéQuoted 54 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/monitor/hmp-target.h | 6 +----- monitor/hmp-target.c | 5 ++++- target/i386/monitor.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-)include/monitor/hmp-target.h +1
-5@@ -27,15 +27,11 @@typedef struct MonitorDef MonitorDef ; -#ifdef COMPILING_PER_TARGET -#include "cpu.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 struct MonitorDef *md,int offset); }; -#endif const MonitorDef *target_monitor_defs (void );int target_get_monitor_def (CPUState *cs,const char *name,uint64_t *pval);monitor/hmp-target.c +2
-0@@ -23,6 +23,7 @@*/ #include "qemu/osdep.h" +#include "qemu/target-info.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h" @@ -33,6 +34,7 @@#include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" +#include "exec/target_long.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 6 lines
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;
This assumes target_long_bits() returns either 32 or 64, doesn't it?
Is this true today?
Will it remain true?
Could we use something like
val & ((1 << target_long_bits()) - 1)
to truncate to target_long_bits() bits?
Quoted 18 lines
monitor/hmp-target.c +0
-0}else {CPUArchState *env =mon_get_cpu_env (mon); ptr = (uint8_t *)env + md->offset;target/i386/monitor.c +2
-2@@ -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 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;
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 18 lines · Markus Armbruster
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;This assumes
target_long_bits()returns either 32 or 64, doesn't it?
Quoted 1 line
Is this true today?
It's certainly true today, and we insist on that: exec/target_long.h handles TARGET_LONG_SIZE being 4 or 8 and will #error on anything else.
What other values do you expect it could have ?
Quoted 7 lines
Will it remain true?
Could we use something like
val & ((1 << target_long_bits()) - 1)to truncate to
target_long_bits()bits?
This is UB for the case where target_long_bits returns 64, and isn't what the code currently does because it zero extends rather than sign extending.
If we wanted to programmatically sign extend from target_long_bits() to the int64_t, that would be
*pval = sextract64(val, 0, target_long_bits());
(Whether sign extension is what we actually want for your average register is questionable, but it's what the code does now both for the get_value functions and also for the generic cases handled by the switch on md->type.)
Incidentally, we currently behave differently here for qemu-system-i386 and qemu-system-x86_64:
$ ./build/all/qemu-system-x86_64 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffff0 (qemu) q $ ./build/all/qemu-system-i386 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffffffffffff0
For qemu-system-x86_64 we have a 64-bit target_long, so the unsigned addition of env->eip and env->segs[R_CS].base in monitor_get_pc() is done at 64 bits, and that width is then carried through get_monitor_def() and to the caller. For qemu-system-i386 we have a 32-bit target_long, so we do an unsigned 32-bit addition in monitor_get_pc(), return a signed 32-bit result, and then sign extend that to 64 bits in get_monitor_def().
thanks
-- PMM
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Markus Armbruster
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;This assumes
target_long_bits()returns either 32 or 64, doesn't it?
Quoted 4 lines
Quoted 1 line
Is this true today?
It's certainly true today, and we insist on that:
exec/target_long.hhandlesTARGET_LONG_SIZEbeing 4 or 8 and will #error on anything else.
Good.
Quoted 1 line
What other values do you expect it could have ?
There might be a need for 128 in the future. Not an easy change to make.
Quoted 11 lines
Quoted 7 lines
Will it remain true?
Could we use something like
val & ((1 << target_long_bits()) - 1)to truncate to
target_long_bits()bits?This is UB for the case where
target_long_bitsreturns 64, and isn't what the code currently does because it zero extends rather than sign extending.
I signalled my cavalier neglect for these details by writing "something like" ;)
Quoted 23 lines
If we wanted to programmatically sign extend from
target_long_bits()to theint64_t, that would be*pval =
sextract64(val, 0, target_long_bits());(Whether sign extension is what we actually want for your average register is questionable, but it's what the code does now both for the
get_valuefunctions and also for the generic cases handled by the switch onmd->type.)Incidentally, we currently behave differently here for qemu-system-i386 and qemu-system-x86_64:
$ ./build/all/qemu-system-x86_64 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffff0 (qemu) q $ ./build/all/qemu-system-i386 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffffffffffff0
Quoted 8 lines
For qemu-system-x86_64 we have a 64-bit
target_long, so the unsigned addition ofenv->eipand env->segs[R_CS].base inmonitor_get_pc()is done at 64 bits, and that width is then carried throughget_monitor_def()and to the caller. For qemu-system-i386 we have a 32-bittarget_long, so we do an unsigned 32-bit addition inmonitor_get_pc(), return a signed 32-bit result, and then sign extend that to 64 bits inget_monitor_def().
I'm carefully retracing my steps out of this swamp.
Thanks!
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 26 lines · Markus Armbruster
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Markus Armbruster
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;This assumes
target_long_bits()returns either 32 or 64, doesn't it?Quoted 4 lines
Quoted 1 line
Is this true today?
It's certainly true today, and we insist on that:
exec/target_long.hhandlesTARGET_LONG_SIZEbeing 4 or 8 and will #error on anything else.
Quoted 7 lines
Good.
Quoted 1 line
What other values do you expect it could have ?
There might be a need for 128 in the future. Not an easy change to make.
The day this will happen, there will be more places to fix than the current patch, as it's assumed everywhere else that target_long_bits or TARGET_LONG_BITS is 32 or 64 only. So I would not worry too much about it at the moment.
Quoted 51 lines
Quoted 11 lines
Quoted 7 lines
Will it remain true?
Could we use something like
val & ((1 << target_long_bits()) - 1)to truncate to
target_long_bits()bits?This is UB for the case where
target_long_bitsreturns 64, and isn't what the code currently does because it zero extends rather than sign extending.I signalled my cavalier neglect for these details by writing "something like" ;)
Quoted 23 lines
If we wanted to programmatically sign extend from
target_long_bits()to theint64_t, that would be*pval = sextract64(val, 0, target_long_bits());(Whether sign extension is what we actually want for your average register is questionable, but it's what the code does now both for the
get_valuefunctions and also for the generic cases handled by the switch onmd->type.)Incidentally, we currently behave differently here for qemu-system-i386 and qemu-system-x86_64:
$ ./build/all/qemu-system-x86_64 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffff0 (qemu) q $ ./build/all/qemu-system-i386 -S -monitor stdio -display none QEMU 10.2.50 monitor - type 'help' for more information (qemu) print $pc 0xfffffffffffffff0Quoted 8 lines
For qemu-system-x86_64 we have a 64-bit
target_long, so the unsigned addition ofenv->eipand env->segs[R_CS].base inmonitor_get_pc()is done at 64 bits, and that width is then carried throughget_monitor_def()and to the caller. For qemu-system-i386 we have a 32-bittarget_long, so we do an unsigned 32-bit addition inmonitor_get_pc(), return a signed 32-bit result, and then sign extend that to 64 bits inget_monitor_def().I'm carefully retracing my steps out of this swamp.
Thanks!
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 31 lines · Pierrick Bouvier
Quoted 30 lines · Markus Armbruster
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Markus Armbruster
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;This assumes
target_long_bits()returns either 32 or 64, doesn't it?Quoted 4 lines
Quoted 1 line
Is this true today?
It's certainly true today, and we insist on that:
exec/target_long.hhandlesTARGET_LONG_SIZEbeing 4 or 8 and will #error on anything else.Good.
Quoted 1 line
What other values do you expect it could have ?
Quoted 8 lines
Quoted 3 lines
There might be a need for 128 in the future. Not an easy change to make.
The day this will happen, there will be more places to fix than the current patch, as it's assumed everywhere else that
target_long_bitsorTARGET_LONG_BITSis 32 or 64 only. So I would not worry too much about it at the moment.
Yes, not an easy change to make.
I guess my comment came out of a feeling of unease about
target_long_bits() == 32 ? [32 bit code] : [64 bit code]
I feel there's a bit of friction between abstract requirements and the concrete software interface. In the abstract, we need to ask a yes/no question here. The concrete interface provides a function that returns 32/64, which works, but isn't obvious from the type. I guess it's obvious enough for anybody working in this area of the code.
If truncating to the target's actual width is common, consider providing function for that.
Feel free to ignore me :)
[...]
Re: [PATCH-for-11.1 v6 3/6] monitor: Have MonitorDef::get_value() always return int64_t type
Quoted 48 lines · Markus Armbruster
Quoted 31 lines · Pierrick Bouvier
Quoted 30 lines · Markus Armbruster
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Markus Armbruster
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 84
Quoted 12 lines · Philippe Mathieu-Daudé
Simplify
MonitorDef::get_value()handler by having it always return aint64_ttype. Truncate to 32-bit in the single caller.Note, this handler is only implemented once for the x86 targets.
monitor/hmp-target.c +2
-1@@ -78,7 +80,8 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)for (; md->name !=NULL ; md++) {if (hmp_compare_cmd (name, md->name)) {if (md->get_value) { - *pval = md->get_value (mon, md, md->offset); +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val;This assumes
target_long_bits()returns either 32 or 64, doesn't it?Quoted 4 lines
Quoted 1 line
Is this true today?
It's certainly true today, and we insist on that:
exec/target_long.hhandlesTARGET_LONG_SIZEbeing 4 or 8 and will #error on anything else.Good.
Quoted 1 line
What other values do you expect it could have ?
Quoted 8 lines
Quoted 3 lines
There might be a need for 128 in the future. Not an easy change to make.
The day this will happen, there will be more places to fix than the current patch, as it's assumed everywhere else that
target_long_bitsorTARGET_LONG_BITSis 32 or 64 only. So I would not worry too much about it at the moment.Yes, not an easy change to make.
I guess my comment came out of a feeling of unease about
target_long_bits() == 32 ? [32 bit code] : [64 bit code]
Quoted 9 lines
I feel there's a bit of friction between abstract requirements and the concrete software interface. In the abstract, we need to ask a yes/no question here. The concrete interface provides a function that returns 32/64, which works, but isn't obvious from the type. I guess it's obvious enough for anybody working in this area of the code.
If truncating to the target's actual width is common, consider providing function for that.
I think the initial reason for this to be written this way was to allow arithmetic expressions (and masks) with this value directly, instead of having ternary expression everywhere:TARGET_IS_64_BITS ? _ : _
Quoted 4 lines
Feel free to ignore me :)
[...]
PATCH v6 4/6 monitor: Remove last target_long use in get_monitor_def()
In reply to Philippe Mathieu-DaudéTruncate manually, removing the need of target-specific code in get_monitor_def().
--- monitor/hmp-target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
monitor/hmp-target.c +1 -2
@@ -34,7 +34,6 @@#include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" -#include "exec/target_long.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
@@ -93,7 +92,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_long_bits () ==32 ? (int32_t )tmp : tmp; }return ret;
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 v6 4/6] monitor: Remove last target_long use in get_monitor_def()
Quoted 8 lines · Philippe Mathieu-Daudé
Truncate manually, removing the need of target-specific code in
get_monitor_def().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- monitor/hmp-target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH-for-11.1 v6 4/6] monitor: Remove last target_long use in get_monitor_def()
In reply to Philippe Mathieu-DaudéQuoted 21 lines · Philippe Mathieu-Daudé
Truncate manually, removing the need of target-specific code in
get_monitor_def().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- monitor/hmp-target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)monitor/hmp-target.c +0
-1@@ -34,7 +34,6 @@#include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" -#include "exec/target_long.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 98
Quoted 8 lines
monitor/hmp-target.c +1
-1@@ -93,7 +92,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_long_bits () ==32 ? (int32_t )tmp : tmp; }return ret;
Looking a second time at it, I don't think you need it. Same in previous commit.
Since pval is a pointer to a (signed) int64, sign will be extended from 32 bit value automatically. So either, it's a positive value, and will be treated as it is. Or it's a negative value, and all upper bits will be set to 1.
So the casting in int32_t has no effect, since it will be extended again automatically.
Regards,
Pierrick
Re: [PATCH-for-11.1 v6 4/6] monitor: Remove last target_long use in get_monitor_def()
Quoted 30 lines · Pierrick Bouvier
Quoted 20 lines · Philippe Mathieu-Daudé
Truncate manually, removing the need of target-specific code in
get_monitor_def().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
monitor/hmp-target.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)monitor/hmp-target.c +0
-1@@ -34,7 +34,6 @@ #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-commands-machine.h" -#include "exec/target_long.h" #if defined(TARGET_S390X) #include "hw/s390x/storage-keys.h"monitor/hmp-target.c int get_monitor_def(Monitor *mon, int64_t *pval, const char *name) · line 96
Quoted 6 lines
monitor/hmp-target.c +1
-1@@ -93,7 +92,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_long_bits() == 32 ? (int32_t)tmp : tmp; } return ret;Looking a second time at it, I don't think you need it. Same in previous commit.
Quoted 3 lines
Since pval is a pointer to a (signed) int64, sign will be extended from 32 bit value automatically. So either, it's a positive value, and will be treated as it is. Or it's a negative value, and all upper bits will be set to 1.
So the casting in
int32_thas no effect, since it will be extended again automatically.
No, tmp is uint64_t.
Presumably we're trying to discard the high half of tmp. This will not be a nop.
r~
PATCH v6 5/6 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 | 39 ------------------------------------- monitor/hmp.c | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 40 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,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);
monitor/hmp-target.c +0 -39
@@ -23,7 +23,6 @@*/ #include "qemu/osdep.h" -#include "qemu/target-info.h" #include "monitor-internal.h" #include "monitor/qdev.h" #include "net/slirp.h"
@@ -60,44 +59,6 @@ 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; -uint64_t tmp =0 ; -int ret; - -if (cs ==NULL || md ==NULL ) { -return -1 ; - } - -for (; md->name !=NULL ; md++) { -if (hmp_compare_cmd (name, md->name)) { -if (md->get_value) { -int64_t val = md->get_value (mon, md, md->offset); - *pval =target_long_bits () ==32 ? (int32_t )val : val; - }else { -CPUArchState *env =mon_get_cpu_env (mon); - ptr = (uint8_t *)env + md->offset; - *pval = *(int32_t *)ptr; - } -return 0 ; - } - } - - ret =target_get_monitor_def (cs, name, &tmp); -if (!ret) { - *pval =target_long_bits () ==32 ? (int32_t )tmp : tmp; - } - -return ret; -} -static int compare_mon_cmd (const void *a,const void *b) {
monitor/hmp.c +40 -0
@@ -355,6 +355,8 @@ 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, ...) {
@@ -1595,3 +1597,41 @@ 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 +*/ +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 ; + } + +for (; md->name !=NULL ; md++) { +if (hmp_compare_cmd (name, md->name)) { +if (md->get_value) { +int64_t val = md->get_value (mon, md, md->offset); + *pval =target_long_bits () ==32 ? (int32_t )val : val; + }else { +CPUArchState *env =mon_get_cpu_env (mon); + ptr = (uint8_t *)env + md->offset; + *pval = *(int32_t *)ptr; + } +return 0 ; + } + } + + ret =target_get_monitor_def (cs, name, &tmp); +if (!ret) { + *pval =target_long_bits () ==32 ? (int32_t )tmp : tmp; + } + +return ret; +}
Signature · 1 line
2.53.0
Re: [PATCH-for-11.1 v6 5/6] monitor: Reduce target-specific methods further
Quoted 11 lines · Philippe Mathieu-Daudé
get_monitor_def()doesn't use any target-specific declaration anymore, move it tohmp.cto compile it once.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- monitor/monitor-internal.h | 1 - monitor/hmp-target.c | 39 ------------------------------------- monitor/hmp.c | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 40 deletions(-)
PATCH v6 6/6 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 | 42 ----------------------------------- include/monitor/hmp.h | 12 ++++++++++ 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, 14 insertions(+), 60 deletions(-) delete mode 100644 include/monitor/hmp-target.h
MAINTAINERS +1 -1
@@ -3407,7 +3407,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 -42
42 lines not on this page · raw message
include/monitor/hmp.h +12 -0
@@ -17,6 +17,18 @@#include "qemu/readline.h" #include "qapi/qapi-types-common.h" +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 ); +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
@@ -39,7 +39,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/monitor.c +0 -2
@@ -7,9 +7,7 @@*/ #include "qemu/osdep.h" -#include "qemu/ctype.h" #include "monitor/monitor.h" -#include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "cpu.h"
target/riscv/monitor.c +0 -1
@@ -25,7 +25,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/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.53.0
Re: [PATCH-for-11.1 v6 6/6] monitor: Remove 'monitor/hmp-target.h' header
Quoted 27 lines · 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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- MAINTAINERS | 2 +- include/monitor/hmp-target.h | 42 ----------------------------------- include/monitor/hmp.h | 12 ++++++++++ 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, 14 insertions(+), 60 deletions(-)
Quoted 2 lines
delete mode 100644
include/monitor/hmp-target.h