Rather than truncating with a target_long cast, 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(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index 97d99f1c747..c56f8df505c 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -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 diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index 5738b47bb03..257605a1c96 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -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; -- 2.52.0
