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 <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Pierrick Bouvier <[email protected]> Message-Id: <[email protected]> --- 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 008c1a6570c..ae34ca65ded 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -27,15 +27,11 @@ 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 977f65fe16c..98df5c7fd12 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -593,11 +593,16 @@ 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
