From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQ19m-0004NX-Bs for qemu-devel@nongnu.org; Thu, 13 Aug 2015 18:39:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQ19k-0001km-67 for qemu-devel@nongnu.org; Thu, 13 Aug 2015 18:39:30 -0400 Date: Fri, 14 Aug 2015 08:39:35 +1000 From: David Gibson Message-ID: <20150813223935.GA2598@voom.fritz.box> References: <20150812012110.GD19634@voom.fritz.box> <1439481138-24141-1-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline In-Reply-To: <1439481138-24141-1-git-send-email-aik@ozlabs.ru> Subject: Re: [Qemu-devel] [PATCH qemu v2] target-ppc: Define get_monitor_def List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 14, 2015 at 01:52:18AM +1000, Alexey Kardashevskiy wrote: > At the moment get_monitor_def() prints only registers from monitor_defs. > However there is a lot of BOOK3S SPRs which are not in the list and > cannot be printed. >=20 > This makes use of the new get_monitor_def() callback and prints all > registered SPRs and fails on unregistered ones proving the user > information on what is actually supported in the running CPU. >=20 > Signed-off-by: Alexey Kardashevskiy > --- > Changes: > v2: > * handles r**, f**, sr** if their numbers were parsed completely and cor= rectly > * added "cr" as synonym of "ccr" [snip] > +static bool ppc_cpu_get_reg(target_ulong *regs, const char *numstr, int = maxnum, > + uint64_t *pval) > +{ > + char *endptr =3D NULL; > + int regnum =3D strtoul(numstr, &endptr, 10); > + > + if ((endptr && *endptr) || (regnum >=3D maxnum)) { Sorry I didn't pick this up in v1, but I think these conditiojns aren't quite right. *endptr is ok (fail if there were invalid characters). But AFAICT from strtoul(3), endptr will *always* be non-NULL (somewhere between numstr and the end of the string). You also need to check if *numstr =3D=3D '\0' to catch the case of no number at all. > + return false; > + } > + *pval =3D regs[regnum]; > + > + return true; > +} > + > +int ppc_cpu_get_monitor_def(CPUState *cs, const char *name, uint64_t *pv= al) > +{ > + int i; > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + CPUPPCState *env =3D &cpu->env; > + > +#define MONREG(s, f) \ > + if ((strcasecmp((s), name) =3D=3D 0)) { \ > + *pval =3D (f); \ > + return 0; \ > + } > + MONREG("pc", env->nip) > + MONREG("nip", env->nip) > + MONREG("lr", env->lr) > + MONREG("ctr", env->ctr) > + MONREG("xer", env->xer) > + MONREG("decr", cpu_ppc_load_decr(env)) > + MONREG("msr", env->msr) > + MONREG("tbu", cpu_ppc_load_tbu(env)) > + MONREG("tbl", cpu_ppc_load_tbl(env)) > + > + if ((strcasecmp("ccr", name) =3D=3D 0) || (strcasecmp("cr", name) = =3D=3D 0)) { > + unsigned int u =3D 0; > + > + for (i =3D 0; i < 8; i++) > + u |=3D env->crf[i] << (32 - (4 * (i + 1))); > + > + return u; > + } > + > + /* General purpose registers */ > + if ((name[0] =3D=3D 'r') && These cases will catch "r3" but not "R3", whereas for sprs it will handle any case. > + ppc_cpu_get_reg(env->gpr, name + 1, ARRAY_SIZE(env->gpr), pval))= { > + return 0; > + } > + > + /* Floating point registers */ > + if ((name[0] =3D=3D 'f') && > + ppc_cpu_get_reg(env->fpr, name + 1, ARRAY_SIZE(env->fpr), pval))= { > + return 0; > + } > + > + /* Segment registers */ > + if ((strncmp(name, "sr", 2) =3D=3D 0) && > + ppc_cpu_get_reg(env->sr, name + 2, ARRAY_SIZE(env->sr), pval)) { > + return 0; > + } > + > + /* Special purpose registers */ > + for (i =3D 0; i < ARRAY_SIZE(env->spr_cb); ++i) { > + ppc_spr_t *spr =3D &env->spr_cb[i]; > + > + if (spr->name && (strcasecmp(name, spr->name) =3D=3D 0)) { > + *pval =3D env->spr[i]; > + return 0; > + } > + } > + > + return -EINVAL; > +} > + > /***********************************************************************= ******/ > static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, > TranslationBlock *tb, > diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c > index 16d7b16..038674a 100644 > --- a/target-ppc/translate_init.c > +++ b/target-ppc/translate_init.c > @@ -9706,6 +9706,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, voi= d *data) > cc->cpu_exec_interrupt =3D ppc_cpu_exec_interrupt; > cc->dump_state =3D ppc_cpu_dump_state; > cc->dump_statistics =3D ppc_cpu_dump_statistics; > + cc->get_monitor_def =3D ppc_cpu_get_monitor_def; > cc->set_pc =3D ppc_cpu_set_pc; > cc->gdb_read_register =3D ppc_cpu_gdb_read_register; > cc->gdb_write_register =3D ppc_cpu_gdb_write_register; --=20 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 --Kj7319i9nmIyA2yE Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVzRynAAoJEGw4ysog2bOSvRsQAMMSXuBkjlvU5B3ArYFQsT4+ jrxWgNnMZeP2LCLvS2+CfrJhU9dX7xsatAcgfYqZXyYKM6vnGxKhq6JKr5UrwUzC iX+E/+azwR9iQxkNNRRM8ylB5wbaaq/yqKuQWeECxNcFbadk4g5+OlIkdb9l3TCb i3wQlJ/YpuC+I2oQtzDkzNpH9Z/FogUVMwpI7ZstUbwTYOsH54dR4MtrbI35SWA5 VroXRSbYP/ybtZed42YMLM/bym7ytXqAPHQpq9rxxtNQpJd+ntr3/on6msypDfWT KoqodSfh6ALO9Jmf+yWTE7+JPf25nVqgRY+PZI/wv3FdGXg8hHdt4DwZ7NkvYK+c CEeooKtlnZhgeMrQRGN9gYD3XRNhEVwBQK3MP6QxLOCZaPiliQTGBU0/YEj+Lg+d nx9ZnaPa/yVGnSO/TGafm9wdM1VlCn2LKIUK3MVKSTaSmco+S5rkRIBUQxA4eATG bvqIbhegOahH/UEFKWlaKrRLFrUMGFD7rUJG5AkPqOFwgKdnob5a+yYLNyri9WKb /8YFUkfFVU7AQMEyftNLfZDZW8hzU4O2Tn9G5Morxo7G8JsMupC9L8feNy52217p QVrA64oWWJaQ2pzxGssNTrLlXPAJmd6qjuvB7eCxQ+9b6rh6ktHQoEgzVIL53IH9 NawnNoWrP+J1H1ChPERV =FFUl -----END PGP SIGNATURE----- --Kj7319i9nmIyA2yE--