@samitouri / QOSamiQemu / commits / ec15eda346

target/riscv: Register target_get_monitor_def in SysemuCPUOps

Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as SysemuCPUOps::monitor_get_register() handler. Take care to sign-extend values for 32-bit HARTs. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Alistair Francis <alistair.francis@wdc.com> Message-Id: <20260427080738.77138-21-philmd@linaro.org>

Philippe Mathieu-Daudé committed Mar 20, 2026 at 14:17 UTC ec15eda346ad662e1f03b4b5fe7e5e63bb284745
3 files changed +11 -4
target/riscv/cpu.c
+1
@@ -2733,6 +2733,7 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
2733 .get_phys_page_debug = riscv_cpu_get_phys_page_debug,
2734 .write_elf64_note = riscv_cpu_write_elf64_note,
2735 .write_elf32_note = riscv_cpu_write_elf32_note,
2736 + .monitor_get_register = riscv_monitor_get_register_legacy,
2737 .legacy_vmsd = &vmstate_riscv_cpu,
2738 };
2739 #endif
target/riscv/internals.h
+3
@@ -250,4 +250,7 @@ static inline int insn_len(uint16_t first_word)
250 return (first_word & 3) == 3 ? 4 : 2;
251 }
252
253 +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
254 + int64_t *pval);
255 +
256 #endif
target/riscv/monitor.c
+7 -4
@@ -27,6 +27,7 @@
27 #include "monitor/hmp.h"
28 #include "monitor/hmp-target.h"
29 #include "system/memory.h"
30 +#include "internals.h"
31
32 #ifdef TARGET_RISCV64
33 #define PTE_HEADER_FIELDS "vaddr paddr "\
@@ -311,16 +312,18 @@ static bool reg_is_vreg(const char *name)
312 return false;
313 }
314
314 -int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
315 +int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
316 + int64_t *pval)
317 {
316 - CPURISCVState *env = &RISCV_CPU(cs)->env;
318 + RISCVCPU *hart = RISCV_CPU(cs);
319 + CPURISCVState *env = cpu_env(cs);
320 target_ulong val = 0;
321 uint64_t val64 = 0;
322 int i;
323
324 if (reg_is_ulong_integer(env, name, &val, false) ||
325 reg_is_ulong_integer(env, name, &val, true)) {
323 - *pval = val;
326 + *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val;
327 return 0;
328 }
329
@@ -369,7 +372,7 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
372 * to do the filtering of the registers that are present.
373 */
374 if (res == RISCV_EXCP_NONE) {
372 - *pval = val;
375 + *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val;
376 return 0;
377 }
378 }