[Pdbg] [PATCH v3 16/16] main: Convert register functions to path based targeting
Alistair Popple
alistair at popple.id.au
Fri Nov 16 12:05:16 AEDT 2018
Yes. Removing more callers of for_each_target() is great, only a few more to
go :-)
Reviewed-by: Alistair Popple <alistair at popple.id.au>
On Thursday, 15 November 2018 6:19:29 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
> src/reg.c | 155 +++++++++++++++++++++++++++++++++---------------------
> 1 file changed, 95 insertions(+), 60 deletions(-)
>
> diff --git a/src/reg.c b/src/reg.c
> index fcf6f4c..8fdb386 100644
> --- a/src/reg.c
> +++ b/src/reg.c
> @@ -18,11 +18,13 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <assert.h>
>
> #include <libpdbg.h>
>
> #include "main.h"
> #include "optcmd.h"
> +#include "path.h"
>
> #define REG_CR -5
> #define REG_XER -4
> @@ -31,14 +33,14 @@
> #define REG_NIA -1
> #define REG_R31 31
>
> -static void print_proc_reg(struct pdbg_target *target, uint64_t reg,
> uint64_t value, int rc) +static void print_proc_reg(struct pdbg_target
> *target, int reg, uint64_t *value, int rc) {
> int proc_index, chip_index, thread_index;
>
> thread_index = pdbg_target_index(target);
> chip_index = pdbg_parent_index(target, "core");
> proc_index = pdbg_parent_index(target, "pib");
> - printf("p%d:c%d:t%d:", proc_index, chip_index, thread_index);
> + printf("p%d:c%d:t%d: ", proc_index, chip_index, thread_index);
>
> if (reg == REG_MSR)
> printf("msr: ");
> @@ -49,145 +51,178 @@ static void print_proc_reg(struct pdbg_target *target,
> uint64_t reg, uint64_t va else if (reg == REG_CR)
> printf("cr: ");
> else if (reg > REG_R31)
> - printf("spr%03" PRIu64 ": ", reg - REG_R31);
> + printf("spr%03d: ", reg - REG_R31);
> else if (reg >= 0 && reg <= 31)
> - printf("gpr%02" PRIu64 ": ", reg);
> + printf("gpr%02d: ", reg);
>
> if (rc == 1) {
> printf("Check threadstatus - not all threads on this chiplet are
> quiesced\n"); } else if (rc == 2)
> printf("Thread in incorrect state\n");
> else
> - printf("0x%016" PRIx64 "\n", value);
> + printf("0x%016" PRIx64 "\n", *value);
> }
>
> -static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t
> *reg, uint64_t *value) +static int putprocreg(struct pdbg_target *target,
> int reg, uint64_t *value) {
> + uint32_t u32;
> int rc;
>
> - if (*reg == REG_MSR)
> + if (reg == REG_MSR)
> rc = ram_putmsr(target, *value);
> - else if (*reg == REG_NIA)
> + else if (reg == REG_NIA)
> rc = ram_putnia(target, *value);
> - else if (*reg == REG_XER)
> + else if (reg == REG_XER)
> rc = ram_putxer(target, *value);
> - else if (*reg == REG_CR)
> - rc = ram_putcr(target, *value);
> - else if (*reg > REG_R31)
> - rc = ram_putspr(target, *reg - REG_R31, *value);
> - else if (*reg >= 0 && *reg <= 31)
> - rc = ram_putgpr(target, *reg, *value);
> -
> - print_proc_reg(target, *reg, *value, rc);
> + else if (reg == REG_CR) {
> + u32 = *value;
> + rc = ram_putcr(target, u32);
> + } else if (reg > REG_R31)
> + rc = ram_putspr(target, reg - REG_R31, *value);
> + else if (reg >= 0 && reg <= 31)
> + rc = ram_putgpr(target, reg, *value);
> + else
> + assert(0);
>
> - return 0;
> + return rc;
> }
>
> -static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t
> *reg, uint64_t *unused) +static int getprocreg(struct pdbg_target *target,
> uint32_t reg, uint64_t *value) {
> + uint32_t u32 = 0;
> int rc;
> - uint64_t value;
>
> - if (*reg == REG_MSR)
> - rc = ram_getmsr(target, &value);
> - else if (*reg == REG_NIA)
> - rc = ram_getnia(target, &value);
> - else if (*reg == REG_XER)
> - rc = ram_getxer(target, &value);
> - else if (*reg == REG_CR)
> - rc = ram_getcr(target, (uint32_t *)&value);
> - else if (*reg > REG_R31)
> - rc = ram_getspr(target, *reg - REG_R31, &value);
> - else if (*reg >= 0 && *reg <= 31)
> - rc = ram_getgpr(target, *reg, &value);
> + if (reg == REG_MSR)
> + rc = ram_getmsr(target, value);
> + else if (reg == REG_NIA)
> + rc = ram_getnia(target, value);
> + else if (reg == REG_XER)
> + rc = ram_getxer(target, value);
> + else if (reg == REG_CR) {
> + rc = ram_getcr(target, &u32);
> + *value = u32;
> + } else if (reg > REG_R31)
> + rc = ram_getspr(target, reg - REG_R31, value);
> + else if (reg >= 0 && reg <= 31)
> + rc = ram_getgpr(target, reg, value);
> + else
> + assert(0);
> +
> + return rc;
> +}
> +
> +static int getreg(int reg)
> +{
> + struct pdbg_target *target;
> + int count = 0;
> +
> + for_each_path_target_class("thread", target) {
> + uint64_t value = 0;
> + int rc;
> +
> + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
> + continue;
> +
> + rc = getprocreg(target, reg, &value);
> + print_proc_reg(target, reg, &value, rc);
> +
> + if (!rc)
> + count++;
> + }
> +
> + return count;
> +}
> +
> +static int putreg(int reg, uint64_t *value)
> +{
> + struct pdbg_target *target;
> + int count = 0;
> +
> + for_each_path_target_class("thread", target) {
> + int rc;
> +
> + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
> + continue;
> +
> + rc = putprocreg(target, reg, value);
> + print_proc_reg(target, reg, value, rc);
>
> - print_proc_reg(target, *reg, value, rc);
> + if (!rc)
> + count++;
> + }
>
> - return !rc;
> + return count;
> }
>
> static int getgpr(int gpr)
> {
> - uint64_t reg = gpr;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(gpr);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(getgpr, getgpr, (GPR));
>
> static int putgpr(int gpr, uint64_t data)
> {
> - uint64_t reg = gpr;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(gpr, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putgpr, putgpr, (GPR, DATA));
>
> static int getnia(void)
> {
> - uint64_t reg = REG_NIA;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_NIA);
> }
> OPTCMD_DEFINE_CMD(getnia, getnia);
>
> static int putnia(uint64_t nia)
> {
> - uint64_t reg = REG_NIA;
> - return for_each_target("thread", putprocreg, ®, &nia);
> + return putreg(REG_NIA, &nia);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putnia, putnia, (DATA));
>
> static int getspr(int spr)
> {
> - uint64_t reg = spr + REG_R31;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(spr + REG_R31);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(getspr, getspr, (SPR));
>
> static int putspr(int spr, uint64_t data)
> {
> - uint64_t reg = spr + REG_R31;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(spr + REG_R31, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putspr, putspr, (SPR, DATA));
>
> static int getmsr(void)
> {
> - uint64_t reg = REG_MSR;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_MSR);
> }
> OPTCMD_DEFINE_CMD(getmsr, getmsr);
>
> static int putmsr(uint64_t data)
> {
> - uint64_t reg = REG_MSR;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(REG_MSR, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putmsr, putmsr, (DATA));
>
> static int getxer(void)
> {
> - uint64_t reg = REG_XER;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_XER);
> }
> OPTCMD_DEFINE_CMD(getxer, getxer);
>
> static int putxer(uint64_t data)
> {
> - uint64_t reg = REG_XER;
> - uint64_t d = data;
> - return for_each_target("thread", putprocreg, ®, &d);
> + return putreg(REG_XER, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA));
>
> static int getcr(void)
> {
> - uint64_t cr = REG_CR;
> - return for_each_target("thread", getprocreg, &cr, NULL);
> + return getreg(REG_CR);
> }
> OPTCMD_DEFINE_CMD(getcr, getcr);
>
> static int putcr(uint32_t data)
> {
> - uint64_t cr = REG_CR;
> - uint64_t d = data;
> - return for_each_target("thread", putprocreg, &cr, &d);
> + uint64_t u64 = data;
> + return putreg(REG_CR, &u64);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putcr, putcr, (DATA32));
More information about the Pdbg
mailing list