From: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>,
qemu-ppc@nongnu.org, agraf@suse.de
Subject: [Qemu-devel] [PATCH] gdbstub: allow byte swapping for reading/writing registers
Date: Tue, 14 Jan 2014 15:47:53 -0600 [thread overview]
Message-ID: <1389736073-20582-1-git-send-email-tlfalcon@linux.vnet.ibm.com> (raw)
This patch allows registers to be properly read from and written to
when using the gdbstub to debug a ppc guest running in little
endian mode. It accomplishes this goal by byte swapping the values of
any registers only if the MSR:LE value is set and if the host machine
is big endian.
Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
---
target-ppc/gdbstub.c | 50 ++++++++++++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/target-ppc/gdbstub.c b/target-ppc/gdbstub.c
index 1c91090..eba501a 100644
--- a/target-ppc/gdbstub.c
+++ b/target-ppc/gdbstub.c
@@ -21,6 +21,19 @@
#include "qemu-common.h"
#include "exec/gdbstub.h"
+/* The following macros are used to ensure the correct
+ * transfer of registers between a little endian ppc target
+ * and a big endian host by checking the LE bit in the Machine State Register
+ */
+
+#define end_swap64(x) (msr_le && HOST_WORDS_BIGENDIAN) ? bswap64(x) : x
+#define end_swap32(x) (msr_le && HOST_WORDS_BIGENDIAN) ? bswap32(x) : x
+#if TARGET_LONG_BITS == 64
+#define end_swapl(x) end_swap64(x)
+#else
+#define end_swapl(x) end_swap32(x)
+#endif
+
/* Old gdb always expects FP registers. Newer (xml-aware) gdb only
* expects whatever the target description contains. Due to a
* historical mishap the FP registers appear in between core integer
@@ -35,20 +48,20 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
if (n < 32) {
/* gprs */
- return gdb_get_regl(mem_buf, env->gpr[n]);
+ return gdb_get_regl(mem_buf, end_swapl(env->gpr[n]));
} else if (n < 64) {
/* fprs */
if (gdb_has_xml) {
return 0;
}
- stfq_p(mem_buf, env->fpr[n-32]);
+ stfq_p(mem_buf, end_swapl(env->fpr[n-32]));
return 8;
} else {
switch (n) {
case 64:
- return gdb_get_regl(mem_buf, env->nip);
+ return gdb_get_regl(mem_buf, end_swapl(env->nip));
case 65:
- return gdb_get_regl(mem_buf, env->msr);
+ return gdb_get_regl(mem_buf, end_swapl(env->msr));
case 66:
{
uint32_t cr = 0;
@@ -56,20 +69,20 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
for (i = 0; i < 8; i++) {
cr |= env->crf[i] << (32 - ((i + 1) * 4));
}
- return gdb_get_reg32(mem_buf, cr);
+ return gdb_get_reg32(mem_buf, end_swap32(cr));
}
case 67:
- return gdb_get_regl(mem_buf, env->lr);
+ return gdb_get_regl(mem_buf, end_swapl(env->lr));
case 68:
- return gdb_get_regl(mem_buf, env->ctr);
+ return gdb_get_regl(mem_buf, end_swapl(env->ctr));
case 69:
- return gdb_get_regl(mem_buf, env->xer);
+ return gdb_get_regl(mem_buf, end_swapl(env->xer));
case 70:
{
if (gdb_has_xml) {
return 0;
}
- return gdb_get_reg32(mem_buf, env->fpscr);
+ return gdb_get_reg32(mem_buf, end_swap32(env->fpscr));
}
}
}
@@ -83,47 +96,48 @@ int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
if (n < 32) {
/* gprs */
- env->gpr[n] = ldtul_p(mem_buf);
+ env->gpr[n] = end_swapl(ldtul_p(mem_buf));
return sizeof(target_ulong);
} else if (n < 64) {
/* fprs */
if (gdb_has_xml) {
return 0;
}
- env->fpr[n-32] = ldfq_p(mem_buf);
+ env->fpr[n-32] = end_swapl(ldfq_p(mem_buf));
return 8;
} else {
switch (n) {
case 64:
- env->nip = ldtul_p(mem_buf);
+ env->nip = end_swapl(ldtul_p(mem_buf));
return sizeof(target_ulong);
case 65:
- ppc_store_msr(env, ldtul_p(mem_buf));
+ ppc_store_msr(env, end_swapl(ldtul_p(mem_buf)));
return sizeof(target_ulong);
case 66:
{
uint32_t cr = ldl_p(mem_buf);
int i;
for (i = 0; i < 8; i++) {
- env->crf[i] = (cr >> (32 - ((i + 1) * 4))) & 0xF;
+ env->crf[i] = end_swap32((cr >> (32 -
+ ((i + 1) * 4))) & 0xF);
}
return 4;
}
case 67:
- env->lr = ldtul_p(mem_buf);
+ env->lr = end_swapl(ldtul_p(mem_buf));
return sizeof(target_ulong);
case 68:
- env->ctr = ldtul_p(mem_buf);
+ env->ctr = end_swapl(ldtul_p(mem_buf));
return sizeof(target_ulong);
case 69:
- env->xer = ldtul_p(mem_buf);
+ env->xer = end_swapl(ldtul_p(mem_buf));
return sizeof(target_ulong);
case 70:
/* fpscr */
if (gdb_has_xml) {
return 0;
}
- store_fpscr(env, ldtul_p(mem_buf), 0xffffffff);
+ store_fpscr(env, end_swapl(ldtul_p(mem_buf)), 0xffffffff);
return sizeof(target_ulong);
}
}
--
1.8.3.1
next reply other threads:[~2014-01-14 22:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-14 21:47 Thomas Falcon [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-01-14 22:06 [Qemu-devel] [PATCH] gdbstub: allow byte swapping for reading/writing registers Thomas Falcon
2014-01-14 22:20 ` Peter Maydell
2014-01-14 22:40 ` Alexander Graf
2014-01-14 22:55 ` Peter Maydell
2014-01-14 23:01 ` Alexander Graf
2014-01-14 23:06 ` Peter Maydell
2014-01-15 17:29 ` Ulrich Weigand
2014-01-15 17:40 ` Alexander Graf
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=1389736073-20582-1-git-send-email-tlfalcon@linux.vnet.ibm.com \
--to=tlfalcon@linux.vnet.ibm.com \
--cc=agraf@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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).