@samitouri / QOSamiQemu / commits / 4adb9ebdb1

target/riscv: Simplify riscv_cpu_gdb_write_register()

Use a single ldn() call, sign-extend once. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260318103122.97244-9-philmd@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Philippe Mathieu-Daudé committed Mar 18, 2026 at 11:31 UTC 4adb9ebdb1d910d2ffb9730aaddcc6dc8aa89a41
1 file changed +6 -19
target/riscv/gdbstub.c
+6 -19
@@ -84,33 +84,20 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
84 RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cs);
85 RISCVCPU *cpu = RISCV_CPU(cs);
86 CPURISCVState *env = &cpu->env;
87 - int length = 0;
88 - uint64_t tmp;
87 + const size_t regsize = mcc->def->misa_mxl_max == MXL_RV32 ? 4 : 8;
88 + uint64_t tmp = ldn(env, mem_buf, regsize);
89
90 - switch (mcc->def->misa_mxl_max) {
91 - case MXL_RV32:
92 - tmp = (int32_t)ldn(env, mem_buf, 4);
93 - length = 4;
94 - break;
95 - case MXL_RV64:
96 - case MXL_RV128:
97 - if (env->xl < MXL_RV64) {
98 - tmp = (int32_t)ldn(env, mem_buf, 8);
99 - } else {
100 - tmp = ldn(env, mem_buf, 8);
101 - }
102 - length = 8;
103 - break;
104 - default:
105 - g_assert_not_reached();
90 + if (env->xl < MXL_RV64) {
91 + tmp = (int32_t)tmp;
92 }
93 +
94 if (n > 0 && n < 32) {
95 env->gpr[n] = tmp;
96 } else if (n == 32) {
97 env->pc = tmp;
98 }
99
113 - return length;
100 + return regsize;
101 }
102
103 static int riscv_gdb_get_fpu(CPUState *cs, GByteArray *buf, int n)