@samitouri / QOSamiQemu / commits / 5a70352f83

target/riscv: Factor tiny ldn() helper in gdbstub

In preparation of having this helper handle CPU runtime endianness changes, factor the ldn() helper out. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260318103122.97244-8-philmd@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Philippe Mathieu-Daudé committed Mar 18, 2026 at 11:31 UTC 5a70352f835ab1be5f2fb5af5932da50d1290161
1 file changed +13 -9
target/riscv/gdbstub.c
+13 -9
@@ -47,6 +47,11 @@ static const struct TypeSize vec_lanes[] = {
47 { "uint8", "bytes", 8, 'b' },
48 };
49
50 +static uint64_t ldn(CPURISCVState *env, uint8_t *mem_buf, size_t regsz)
51 +{
52 + return ldn_p(mem_buf, regsz);
53 +}
54 +
55 int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
56 {
57 RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cs);
@@ -84,15 +89,15 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
89
90 switch (mcc->def->misa_mxl_max) {
91 case MXL_RV32:
87 - tmp = (int32_t)ldl_p(mem_buf);
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) {
93 - tmp = (int32_t)ldq_p(mem_buf);
98 + tmp = (int32_t)ldn(env, mem_buf, 8);
99 } else {
95 - tmp = ldq_p(mem_buf);
100 + tmp = ldn(env, mem_buf, 8);
101 }
102 length = 8;
103 break;
@@ -130,7 +135,7 @@ static int riscv_gdb_set_fpu(CPUState *cs, uint8_t *mem_buf, int n)
135 CPURISCVState *env = &cpu->env;
136
137 if (n < 32) {
133 - env->fpr[n] = ldq_p(mem_buf); /* always 64-bit */
138 + env->fpr[n] = ldn(env, mem_buf, 8); /* always 64-bit */
139 return sizeof(uint64_t);
140 }
141 return 0;
@@ -162,7 +167,7 @@ static int riscv_gdb_set_vector(CPUState *cs, uint8_t *mem_buf, int n)
167 if (n < 32) {
168 int i;
169 for (i = 0; i < vlenb; i += 8) {
165 - env->vreg[(n * vlenb + i) / 8] = ldq_p(mem_buf + i);
170 + env->vreg[(n * vlenb + i) / 8] = ldn(env, mem_buf + i, 8);
171 }
172 return vlenb;
173 }
@@ -194,7 +199,7 @@ static int riscv_gdb_set_csr(CPUState *cs, uint8_t *mem_buf, int n)
199 const unsigned regsz = riscv_cpu_is_32bit(cpu) ? 4 : 8;
200
201 if (n < CSR_TABLE_SIZE) {
197 - uint64_t val = ldn_p(mem_buf, regsz);
202 + uint64_t val = ldn(env, mem_buf, regsz);
203 int result;
204
205 result = riscv_csrrw_debug(env, n, NULL, val, -1);
@@ -230,8 +235,7 @@ static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n)
235 const unsigned regsz = riscv_cpu_is_32bit(cpu) ? 4 : 8;
236 #ifndef CONFIG_USER_ONLY
237 CPURISCVState *env = &cpu->env;
233 -
234 - target_ulong new_priv = ldn_p(mem_buf, regsz) & 0x3;
238 + uint64_t new_priv = ldn(env, mem_buf, regsz) & 0x3;
239 bool new_virt = 0;
240
241 if (new_priv == PRV_RESERVED) {
@@ -239,7 +243,7 @@ static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n)
243 }
244
245 if (new_priv != PRV_M) {
242 - new_virt = (ldn_p(mem_buf, regsz) & BIT(2)) >> 2;
246 + new_virt = (ldn(env, mem_buf, regsz) & BIT(2)) >> 2;
247 }
248
249 if (riscv_has_ext(env, RVH) && new_virt != env->virt_enabled) {