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 | 6 ++++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index bd9baeaa3ad..713936c4523 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_TLONG 0 #define MD_I32 1 diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index ead195f5616..01be0a0b426 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; @@ -87,7 +89,7 @@ int get_monitor_def(Monitor *mon, uint64_t *pval, const char *name) *pval = *(uint32_t *)ptr; break; case MD_TLONG: - *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
