@samitouri / QOSamiQemu / commits / fb16dc9090

monitor: Have MonitorDef::get_value() always return int64_t type

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 <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-Id: <20260427080738.77138-23-philmd@linaro.org>

Philippe Mathieu-Daudé committed Mar 20, 2026 at 09:23 UTC fb16dc9090e90efd05396a067622f0c35e4c7506
2 files changed +9 -8
include/monitor/hmp-target.h
+1 -5
@@ -27,15 +27,11 @@
27
28 typedef struct MonitorDef MonitorDef;
29
30 -#ifdef COMPILING_PER_TARGET
31 -#include "exec/target_long.h"
30 struct MonitorDef {
31 const char *name;
32 int offset;
35 - target_long (*get_value)(Monitor *mon, const struct MonitorDef *md,
36 - int val);
33 + int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
34 };
38 -#endif
35
36 const MonitorDef *target_monitor_defs(void);
37
target/i386/monitor.c
+8 -3
@@ -593,11 +593,16 @@ void hmp_mce(Monitor *mon, const QDict *qdict)
593 }
594 }
595
596 -static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
597 - int val)
596 +static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
597 + int offset)
598 {
599 CPUArchState *env = mon_get_cpu_env(mon);
600 - return env->eip + env->segs[R_CS].base;
600 + int64_t ret = env->eip + env->segs[R_CS].base;
601 +
602 + if (!(env->hflags & HF_CS64_MASK)) {
603 + ret = (int32_t)ret;
604 + }
605 + return ret;
606 }
607
608 const MonitorDef monitor_defs[] = {