From: David Gibson <david@gibson.dropbear.id.au>
To: Fabiano Rosas <farosas@linux.ibm.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/3] target/ppc: Add GDB callbacks for SPRs
Date: Fri, 11 Jan 2019 11:50:01 +1100 [thread overview]
Message-ID: <20190111005001.GR6682@umbus.fritz.box> (raw)
In-Reply-To: <20190104195654.19976-3-farosas@linux.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 2748 bytes --]
On Fri, Jan 04, 2019 at 05:56:53PM -0200, Fabiano Rosas wrote:
> These will be used to let GDB know about PPC's Special Purpose
> Registers (SPR).
>
> They take an index based on the order the registers appear in the XML
> file sent by QEMU to GDB. This index does not match the actual
> location of the registers in the env->spr array so the
> gdb_find_spr_idx function does that conversion.
>
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
> target/ppc/translate_init.inc.c | 50 +++++++++++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
> index 03f1d34a97..f10a3637d9 100644
> --- a/target/ppc/translate_init.inc.c
> +++ b/target/ppc/translate_init.inc.c
> @@ -9483,6 +9483,56 @@ static bool avr_need_swap(CPUPPCState *env)
> #endif
> }
>
> +#if !defined(CONFIG_USER_ONLY)
> +static int gdb_find_spr_idx(CPUPPCState *env, int n)
> +{
> + int idx = -1;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
> + ppc_spr_t *spr = &env->spr_cb[i];
> +
> + if (spr->name && ++idx == n) {
> + break;
> + }
> + }
> + return i;
> +}
This is very subtle - it relies on the fact that you also generate the
XML in sequence, which makes for a very non-obvious dependency between
different parts of the code. At the very least this needs a big fat
comment explaining how the gdb ids are allocated.
I think better would be to explicitly put a gdb_id into the spr_cb
structure - that would be filled in at the same time you generate the
XML, then referenced here.
> +static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
> +{
> + int reg;
> + int len;
> +
> + reg = gdb_find_spr_idx(env, n);
> + if (!reg) {
> + return 0;
> + }
> +
> + len = TARGET_LONG_SIZE;
> + stn_p(mem_buf, len, env->spr[reg]);
> + ppc_maybe_bswap_register(env, mem_buf, len);
> + return len;
> +}
> +
> +static int gdb_set_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
> +{
> + int reg;
> + int len;
> +
> + reg = gdb_find_spr_idx(env, n);
> + if (!reg) {
> + return 0;
> + }
> +
> + len = TARGET_LONG_SIZE;
> + ppc_maybe_bswap_register(env, mem_buf, len);
> + env->spr[reg] = ldn_p(mem_buf, len);
> +
> + return len;
> +}
> +#endif
> +
> static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
> {
> if (n < 32) {
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-01-11 1:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-04 19:56 [Qemu-devel] [PATCH 0/3] ppc/gdbstub: Expose SPRs to GDB Fabiano Rosas
2019-01-04 19:56 ` [Qemu-devel] [PATCH 1/3] target/ppc: Add SPRs XML generation code for gdbstub Fabiano Rosas
2019-01-04 19:56 ` [Qemu-devel] [PATCH 2/3] target/ppc: Add GDB callbacks for SPRs Fabiano Rosas
2019-01-11 0:50 ` David Gibson [this message]
2019-01-04 19:56 ` [Qemu-devel] [PATCH 3/3] target/ppc: Enable reporting of SPRs to GDB Fabiano Rosas
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=20190111005001.GR6682@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=farosas@linux.ibm.com \
--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).