From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Juan Quintela" <quintela@redhat.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Thomas Huth" <thuth@redhat.com>,
"Akihiko Odaki" <akihiko.odaki@daynix.com>,
qemu-ppc@nongnu.org, "David Gibson" <david@gibson.dropbear.id.au>,
qemu-s390x@nongnu.org,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Cédric Le Goater" <clg@kaod.org>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Hildenbrand" <david@redhat.com>,
"Yonggang Luo" <luoyonggang@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Beraldo Leal" <bleal@redhat.com>,
qemu-arm@nongnu.org, "Greg Kurz" <groug@kaod.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Subject: [PATCH 07/10] target/ppc: convert gdbstub to new helper (!hacky)
Date: Wed, 19 Mar 2025 18:22:52 +0000 [thread overview]
Message-ID: <20250319182255.3096731-8-alex.bennee@linaro.org> (raw)
In-Reply-To: <20250319182255.3096731-1-alex.bennee@linaro.org>
By passing the explicit state of LE/BE via the memop we can avoid the
messing about we do with ppc_maybe_bswap_register() at least for
supplying register values to gdbstub.
The fact we still need the helper for setting the values probably
indicates we could do with a reverse helper, possibly to setting env
vars directly? This is complicated by aliasing though.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
target/ppc/gdbstub.c | 192 ++++++++++++++++++++++++-------------------
1 file changed, 108 insertions(+), 84 deletions(-)
diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c
index c09e93abaf..663a97d986 100644
--- a/target/ppc/gdbstub.c
+++ b/target/ppc/gdbstub.c
@@ -20,7 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
-#include "gdbstub/helpers.h"
+#include "gdbstub/registers.h"
#include "internal.h"
static int ppc_gdb_register_len_apple(int n)
@@ -74,12 +74,12 @@ static int ppc_gdb_register_len(int n)
}
/*
- * We need to present the registers to gdb in the "current" memory
- * ordering. For user-only mode we get this for free;
- * TARGET_BIG_ENDIAN is set to the proper ordering for the
- * binary, and cannot be changed. For system mode,
- * TARGET_BIG_ENDIAN is always set, and we must check the current
- * mode of the chip to see if we're running in little-endian.
+ * We need to map the target endian registers from gdb in the
+ * "current" memory ordering. For user-only mode we get this for free;
+ * TARGET_BIG_ENDIAN is set to the proper ordering for the binary, and
+ * cannot be changed. For system mode, TARGET_BIG_ENDIAN is always
+ * set, and we must check the current mode of the chip to see if we're
+ * running in little-endian.
*/
static void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len)
{
@@ -98,6 +98,38 @@ static void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len
#endif
}
+/*
+ * We need to present the registers to gdb in the "current" memory
+ * ordering. For user-only mode this is hardwired by TARGET_BIG_ENDIAN
+ * and cannot be changed. For system mode we must check the current
+ * mode of the chip to see if we're running in little-endian.
+ */
+static MemOp ppc_gdb_memop(CPUPPCState *env, int len)
+{
+#ifndef CONFIG_USER_ONLY
+ MemOp end = FIELD_EX64(env->msr, MSR, LE) ? MO_LE : MO_BE;
+#else
+ #ifdef TARGET_BIG_ENDIAN
+ MemOp end = MO_BE;
+ #else
+ MemOp end = MO_LE;
+ #endif
+#endif
+
+ return size_memop(len) | end;
+}
+
+/*
+ * Helpers copied from helpers.h just for loading target_ulong values
+ * from gdbstub's GByteArray
+ */
+
+#if TARGET_LONG_BITS == 64
+#define ldtul_p(addr) ldq_p(addr)
+#else
+#define ldtul_p(addr) ldl_p(addr)
+#endif
+
/*
* Old gdb always expects FP registers. Newer (xml-aware) gdb only
* expects whatever the target description contains. Due to a
@@ -109,51 +141,50 @@ static void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len
int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n)
{
CPUPPCState *env = cpu_env(cs);
- uint8_t *mem_buf;
int r = ppc_gdb_register_len(n);
+ MemOp mo;
if (!r) {
return r;
}
+ mo = ppc_gdb_memop(env, r);
+
if (n < 32) {
/* gprs */
- gdb_get_regl(buf, env->gpr[n]);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->gpr[n]);
} else {
switch (n) {
case 64:
- gdb_get_regl(buf, env->nip);
- break;
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->nip);
case 65:
- gdb_get_regl(buf, env->msr);
- break;
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->msr);
case 66:
{
uint32_t cr = ppc_get_cr(env);
- gdb_get_reg32(buf, cr);
- break;
+ return gdb_get_register_value(ppc_gdb_memop(env, 4), buf, (uint8_t *) &cr);
}
case 67:
- gdb_get_regl(buf, env->lr);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->lr);
break;
case 68:
- gdb_get_regl(buf, env->ctr);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->ctr);
break;
case 69:
- gdb_get_reg32(buf, cpu_read_xer(env));
- break;
+ uint32_t val = cpu_read_xer(env);
+ return gdb_get_register_value(ppc_gdb_memop(env, 4), buf, (uint8_t *) &val);
}
}
- mem_buf = buf->data + buf->len - r;
- ppc_maybe_bswap_register(env, mem_buf, r);
- return r;
+
+ return 0;
}
int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n)
{
CPUPPCState *env = cpu_env(cs);
- uint8_t *mem_buf;
int r = ppc_gdb_register_len_apple(n);
+ MemOp mo = ppc_gdb_memop(env, r);
+ int actual = 0;
if (!r) {
return r;
@@ -161,44 +192,48 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n)
if (n < 32) {
/* gprs */
- gdb_get_reg64(buf, env->gpr[n]);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->gpr[n]);
} else if (n < 64) {
/* fprs */
- gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32));
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) cpu_fpr_ptr(env, n - 32));
} else if (n < 96) {
- /* Altivec */
- gdb_get_reg64(buf, n - 64);
- gdb_get_reg64(buf, 0);
+ /* Altivec - where are they? ppc_vsr_t vsr[64]? */
+ uint64_t empty = 0;
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &empty);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &empty);
} else {
switch (n) {
case 64 + 32:
- gdb_get_reg64(buf, env->nip);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->nip);
break;
case 65 + 32:
- gdb_get_reg64(buf, env->msr);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->msr);
break;
case 66 + 32:
- {
- uint32_t cr = ppc_get_cr(env);
- gdb_get_reg32(buf, cr);
- break;
- }
+ {
+ uint32_t cr = ppc_get_cr(env);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &cr);
+ break;
+ }
case 67 + 32:
- gdb_get_reg64(buf, env->lr);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->lr);
break;
case 68 + 32:
- gdb_get_reg64(buf, env->ctr);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->ctr);
break;
case 69 + 32:
- gdb_get_reg32(buf, cpu_read_xer(env));
+ {
+ uint32_t xer = cpu_read_xer(env);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &xer);
break;
+ }
case 70 + 32:
- gdb_get_reg64(buf, env->fpscr);
+ actual = gdb_get_register_value(mo, buf, (uint8_t *) &env->fpscr);
break;
}
}
- mem_buf = buf->data + buf->len - r;
- ppc_maybe_bswap_register(env, mem_buf, r);
+
+ g_assert(r == actual);
return r;
}
@@ -210,6 +245,9 @@ int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
if (!r) {
return r;
}
+
+ g_assert(r == n);
+
ppc_maybe_bswap_register(env, mem_buf, r);
if (n < 32) {
/* gprs */
@@ -367,18 +405,16 @@ static int gdb_get_spr_reg(CPUState *cs, GByteArray *buf, int n)
{
PowerPCCPU *cpu = POWERPC_CPU(cs);
CPUPPCState *env = &cpu->env;
+ MemOp mo = ppc_gdb_memop(env, TARGET_LONG_SIZE);
+ target_ulong val;
int reg;
- int len;
reg = gdb_find_spr_idx(env, n);
if (reg < 0) {
return 0;
}
- len = TARGET_LONG_SIZE;
-
/* Handle those SPRs that are not part of the env->spr[] array */
- target_ulong val;
switch (reg) {
#if defined(TARGET_PPC64)
case SPR_CFAR:
@@ -400,10 +436,7 @@ static int gdb_get_spr_reg(CPUState *cs, GByteArray *buf, int n)
default:
val = env->spr[reg];
}
- gdb_get_regl(buf, val);
-
- ppc_maybe_bswap_register(env, gdb_get_reg_ptr(buf, len), len);
- return len;
+ return gdb_get_register_value(mo, buf, (uint8_t *) &val);
}
static int gdb_set_spr_reg(CPUState *cs, uint8_t *mem_buf, int n)
@@ -441,18 +474,14 @@ static int gdb_get_float_reg(CPUState *cs, GByteArray *buf, int n)
{
PowerPCCPU *cpu = POWERPC_CPU(cs);
CPUPPCState *env = &cpu->env;
- uint8_t *mem_buf;
+ MemOp mo;
if (n < 32) {
- gdb_get_reg64(buf, *cpu_fpr_ptr(env, n));
- mem_buf = gdb_get_reg_ptr(buf, 8);
- ppc_maybe_bswap_register(env, mem_buf, 8);
- return 8;
+ mo = ppc_gdb_memop(env, 8);
+ return gdb_get_register_value(mo, buf, (uint8_t *)cpu_fpr_ptr(env, n));
}
if (n == 32) {
- gdb_get_reg32(buf, env->fpscr);
- mem_buf = gdb_get_reg_ptr(buf, 4);
- ppc_maybe_bswap_register(env, mem_buf, 4);
- return 4;
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->fpscr);
}
return 0;
}
@@ -479,26 +508,21 @@ static int gdb_get_avr_reg(CPUState *cs, GByteArray *buf, int n)
{
PowerPCCPU *cpu = POWERPC_CPU(cs);
CPUPPCState *env = &cpu->env;
- uint8_t *mem_buf;
+ MemOp mo;
if (n < 32) {
ppc_avr_t *avr = cpu_avr_ptr(env, n);
- gdb_get_reg128(buf, avr->VsrD(0), avr->VsrD(1));
- mem_buf = gdb_get_reg_ptr(buf, 16);
- ppc_maybe_bswap_register(env, mem_buf, 16);
- return 16;
+ mo = ppc_gdb_memop(env, 16);
+ return gdb_get_register_value(mo, buf, (uint8_t *) avr);
}
if (n == 32) {
- gdb_get_reg32(buf, ppc_get_vscr(env));
- mem_buf = gdb_get_reg_ptr(buf, 4);
- ppc_maybe_bswap_register(env, mem_buf, 4);
- return 4;
+ uint32_t vscr = ppc_get_vscr(env);
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &vscr);
}
if (n == 33) {
- gdb_get_reg32(buf, (uint32_t)env->spr[SPR_VRSAVE]);
- mem_buf = gdb_get_reg_ptr(buf, 4);
- ppc_maybe_bswap_register(env, mem_buf, 4);
- return 4;
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->spr[SPR_VRSAVE]);
}
return 0;
}
@@ -532,25 +556,25 @@ static int gdb_get_spe_reg(CPUState *cs, GByteArray *buf, int n)
{
PowerPCCPU *cpu = POWERPC_CPU(cs);
CPUPPCState *env = &cpu->env;
+ MemOp mo;
if (n < 32) {
#if defined(TARGET_PPC64)
- gdb_get_reg32(buf, env->gpr[n] >> 32);
- ppc_maybe_bswap_register(env, gdb_get_reg_ptr(buf, 4), 4);
+ uint32_t low = env->gpr[n] >> 32;
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &low);
#else
- gdb_get_reg32(buf, env->gprh[n]);
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->gprh[n]);
#endif
- return 4;
}
if (n == 32) {
- gdb_get_reg64(buf, env->spe_acc);
- ppc_maybe_bswap_register(env, gdb_get_reg_ptr(buf, 8), 8);
- return 8;
+ mo = ppc_gdb_memop(env, 8);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->spe_acc);
}
if (n == 33) {
- gdb_get_reg32(buf, env->spe_fscr);
- ppc_maybe_bswap_register(env, gdb_get_reg_ptr(buf, 4), 4);
- return 4;
+ mo = ppc_gdb_memop(env, 4);
+ return gdb_get_register_value(mo, buf, (uint8_t *) &env->spe_fscr);
}
return 0;
}
@@ -593,9 +617,9 @@ static int gdb_get_vsx_reg(CPUState *cs, GByteArray *buf, int n)
CPUPPCState *env = &cpu->env;
if (n < 32) {
- gdb_get_reg64(buf, *cpu_vsrl_ptr(env, n));
- ppc_maybe_bswap_register(env, gdb_get_reg_ptr(buf, 8), 8);
- return 8;
+ return gdb_get_register_value(ppc_gdb_memop(env, 8),
+ buf,
+ (uint8_t *)cpu_vsrl_ptr(env, n));
}
return 0;
}
--
2.39.5
next prev parent reply other threads:[~2025-03-19 18:25 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 18:22 [PATCH 00/10] gdbstub: conversion to runtime endianess helpers Alex Bennée
2025-03-19 18:22 ` [PATCH 01/10] include/gdbstub: fix include guard in commands.h Alex Bennée
2025-03-20 7:09 ` Philippe Mathieu-Daudé
2025-03-20 19:37 ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 02/10] gdbstub: introduce target independent gdb register helper Alex Bennée
2025-03-20 6:19 ` Akihiko Odaki
2025-03-20 7:24 ` Philippe Mathieu-Daudé
2025-03-20 7:16 ` Philippe Mathieu-Daudé
2025-03-20 19:30 ` Pierrick Bouvier
2025-03-20 19:36 ` Pierrick Bouvier
2025-03-21 11:36 ` Alex Bennée
2025-03-21 17:24 ` Pierrick Bouvier
2025-03-20 19:37 ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 03/10] target/arm: convert 32 bit gdbstub to new helper Alex Bennée
2025-03-20 6:21 ` Akihiko Odaki
2025-03-20 19:38 ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 04/10] target/arm: convert 64 " Alex Bennée
2025-03-20 7:39 ` Philippe Mathieu-Daudé
2025-03-20 19:42 ` Pierrick Bouvier
2025-03-21 11:38 ` Alex Bennée
2025-03-19 18:22 ` [PATCH 05/10] target/ppc: expand comment on FP/VMX/VSX access functions Alex Bennée
2025-03-20 19:42 ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 06/10] target/ppc: make ppc_maybe_bswap_register static Alex Bennée
2025-03-20 6:55 ` Philippe Mathieu-Daudé
2025-03-20 19:42 ` Pierrick Bouvier
2025-03-19 18:22 ` Alex Bennée [this message]
2025-03-19 18:22 ` [PATCH 08/10] gdbstub: assert earlier in handle_read_all_regs Alex Bennée
2025-03-20 6:57 ` Philippe Mathieu-Daudé
2025-03-19 18:22 ` [PATCH 09/10] include/exec: fix assert in size_memop Alex Bennée
2025-03-20 6:29 ` Akihiko Odaki
2025-03-20 7:30 ` Philippe Mathieu-Daudé
2025-03-19 18:22 ` [PATCH 10/10] target/microblaze: convert gdbstub to new helper Alex Bennée
2025-03-20 7:09 ` Philippe Mathieu-Daudé
2025-03-20 19:52 ` [PATCH 00/10] gdbstub: conversion to runtime endianess helpers Pierrick Bouvier
2025-03-20 20:16 ` Pierrick Bouvier
2025-03-21 13:02 ` Philippe Mathieu-Daudé
2025-03-21 17:27 ` Pierrick Bouvier
2025-03-21 11:46 ` Alex Bennée
2025-03-21 17:31 ` Pierrick Bouvier
2025-03-23 15:41 ` Philippe Mathieu-Daudé
2025-03-23 17:32 ` Pierrick Bouvier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250319182255.3096731-8-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=akihiko.odaki@daynix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=groug@kaod.org \
--cc=iii@linux.ibm.com \
--cc=luoyonggang@gmail.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).