From patchwork Thu Jul 23 05:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1334418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BC16k0G2Qz9sRR for ; Thu, 23 Jul 2020 15:27:10 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=nvINFbhg; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BC16j3nJ1zDr7M for ; Thu, 23 Jul 2020 15:27:09 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BC16S0mypzDr7V for ; Thu, 23 Jul 2020 15:26:56 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=nvINFbhg; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BC16R5xd0z9sSJ; Thu, 23 Jul 2020 15:26:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1595482015; bh=Kwyv//rrKKzSjaSIiTEQ2/3AfX/PEiIfwgoo81lES+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nvINFbhgK30qrd8e1qaPMsRRaWKSOas8M575fi7TMUbnXVMyyuvA+va2uvVaE1Vfv T+ft3LZYrNzHxto5ZmZQPdCKEPmkitjNr54+8C/lUC16zeuDDF7FXhB3Qnl5LSVs8m eBQE1pndRJBCfdxzw/UfsCAW50uMkc3Vfs6zpUwl+pwwK2WL0arsIX9GA+325J9E48 7ANcZQQjln086fRDP4tKZuD1R+R5rOFaLqo0qQ26/e7k3KANTG0NKjLZXa9GsDPxjY FmGVxE3AYoTFA4Ie3xvDkyadwIqvOJibOEojdXuIlO+BffgVh322TNOtbfviArQT+a bgGSeaMRE9mOQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 23 Jul 2020 15:26:41 +1000 Message-Id: <20200723052641.561009-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200723052641.561009-1-amitay@ozlabs.org> References: <20200723052641.561009-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 4/4] main: Change (get|put)spr command to use spr names X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Avoid special convention of sprs with -ve ids. Signed-off-by: Amitay Isaacs --- src/parsers.c | 11 +++---- src/reg.c | 91 +++++++++++++++------------------------------------ 2 files changed, 32 insertions(+), 70 deletions(-) diff --git a/src/parsers.c b/src/parsers.c index 8575784..52fa49d 100644 --- a/src/parsers.c +++ b/src/parsers.c @@ -4,6 +4,8 @@ #include #include +#include "libpdbg.h" + uint64_t *parse_number64(const char *argv) { uint64_t *n = malloc(sizeof(*n)); @@ -98,19 +100,16 @@ int *parse_gpr(const char *argv) return gpr; } -/* Parse an SPR. Currently only supports SPR by numbers but could be extended to - * support names (eg. lr) */ +/* Parse an SPR name (eg. lr) */ int *parse_spr(const char *argv) { int *spr = malloc(sizeof(*spr)); - char *endptr; if (!argv) return NULL; - errno = 0; - *spr = strtoul(argv, &endptr, 0); - if (errno || *endptr != '\0' || *spr > 0x3ff) + *spr = pdbg_spr_by_name(argv); + if (*spr == -1) return NULL; return spr; diff --git a/src/reg.c b/src/reg.c index 56f5118..8f7efd8 100644 --- a/src/reg.c +++ b/src/reg.c @@ -26,14 +26,7 @@ #include "optcmd.h" #include "path.h" -#define REG_CR -5 -#define REG_XER -4 -#define REG_MEM -3 -#define REG_MSR -2 -#define REG_NIA -1 -#define REG_R31 31 - -static void print_proc_reg(struct pdbg_target *target, int reg, uint64_t *value, int rc) +static void print_proc_reg(struct pdbg_target *target, bool is_spr, int reg, uint64_t *value, int rc) { int proc_index, chip_index, thread_index; @@ -42,76 +35,46 @@ static void print_proc_reg(struct pdbg_target *target, int reg, uint64_t *value, proc_index = pdbg_parent_index(target, "pib"); printf("p%d:c%d:t%d: ", proc_index, chip_index, thread_index); - if (reg == REG_MSR) - printf("msr: "); - else if (reg == REG_NIA) - printf("nia: "); - else if (reg == REG_XER) - printf("xer: "); - else if (reg == REG_CR) - printf("cr: "); - else if (reg > REG_R31) - printf("spr%03d: ", reg - REG_R31); - else if (reg >= 0 && reg <= 31) + if (is_spr) + printf("%s: ", pdbg_spr_by_id(reg)); + else printf("gpr%02d: ", reg); - if (rc == 1) { + if (rc == 0) + printf("0x%016" PRIx64 "\n", *value); + else if (rc == 1) printf("Check threadstatus - not all threads on this chiplet are quiesced\n"); - } else if (rc == 2) + else if (rc == 2) printf("Thread in incorrect state\n"); else - printf("0x%016" PRIx64 "\n", *value); + printf("Error in thread access\n"); } -static int putprocreg(struct pdbg_target *target, int reg, uint64_t *value) +static int putprocreg(struct pdbg_target *target, bool is_spr, int reg, uint64_t *value) { - uint32_t u32; int rc; - if (reg == REG_MSR) - rc = thread_putmsr(target, *value); - else if (reg == REG_NIA) - rc = thread_putnia(target, *value); - else if (reg == REG_XER) - rc = thread_putxer(target, *value); - else if (reg == REG_CR) { - u32 = *value; - rc = thread_putcr(target, u32); - } else if (reg > REG_R31) - rc = thread_putspr(target, reg - REG_R31, *value); - else if (reg >= 0 && reg <= 31) - rc = thread_putgpr(target, reg, *value); + if (is_spr) + rc = thread_putspr(target, reg, *value); else - assert(0); + rc = thread_putgpr(target, reg, *value); return rc; } -static int getprocreg(struct pdbg_target *target, uint32_t reg, uint64_t *value) +static int getprocreg(struct pdbg_target *target, bool is_spr, uint32_t reg, uint64_t *value) { - uint32_t u32 = 0; int rc; - if (reg == REG_MSR) - rc = thread_getmsr(target, value); - else if (reg == REG_NIA) - rc = thread_getnia(target, value); - else if (reg == REG_XER) - rc = thread_getxer(target, value); - else if (reg == REG_CR) { - rc = thread_getcr(target, &u32); - *value = u32; - } else if (reg > REG_R31) - rc = thread_getspr(target, reg - REG_R31, value); - else if (reg >= 0 && reg <= 31) - rc = thread_getgpr(target, reg, value); + if (is_spr) + rc = thread_getspr(target, reg, value); else - assert(0); + rc = thread_getgpr(target, reg, value); return rc; } -static int getreg(int reg) +static int getreg(bool is_spr, int reg) { struct pdbg_target *target; int count = 0; @@ -123,8 +86,8 @@ static int getreg(int reg) if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - rc = getprocreg(target, reg, &value); - print_proc_reg(target, reg, &value, rc); + rc = getprocreg(target, is_spr, reg, &value); + print_proc_reg(target, is_spr, reg, &value, rc); if (!rc) count++; @@ -133,7 +96,7 @@ static int getreg(int reg) return count; } -static int putreg(int reg, uint64_t *value) +static int putreg(bool is_spr, int reg, uint64_t *value) { struct pdbg_target *target; int count = 0; @@ -144,8 +107,8 @@ static int putreg(int reg, uint64_t *value) if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - rc = putprocreg(target, reg, value); - print_proc_reg(target, reg, value, rc); + rc = putprocreg(target, is_spr, reg, value); + print_proc_reg(target, is_spr, reg, value, rc); if (!rc) count++; @@ -156,24 +119,24 @@ static int putreg(int reg, uint64_t *value) static int getgpr(int gpr) { - return getreg(gpr); + return getreg(false, gpr); } OPTCMD_DEFINE_CMD_WITH_ARGS(getgpr, getgpr, (GPR)); static int putgpr(int gpr, uint64_t data) { - return putreg(gpr, &data); + return putreg(false, gpr, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putgpr, putgpr, (GPR, DATA)); static int getspr(int spr) { - return getreg(spr + REG_R31); + return getreg(true, spr); } OPTCMD_DEFINE_CMD_WITH_ARGS(getspr, getspr, (SPR)); static int putspr(int spr, uint64_t data) { - return putreg(spr + REG_R31, &data); + return putreg(true, spr, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putspr, putspr, (SPR, DATA));