From patchwork Thu Jul 23 05:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1334421 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 4BC16r0MxXz9sRf for ; Thu, 23 Jul 2020 15:27:16 +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=Gjkx2XeT; 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 4BC16q6nlszDr7l for ; Thu, 23 Jul 2020 15:27:15 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (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 4BC16R2gtCzDr7P for ; Thu, 23 Jul 2020 15:26:55 +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=Gjkx2XeT; 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 4BC16R0Tbdz9sRf; 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=5Nf7+3Im8KP49f6/hR3zezh4+nc+2xSJXwobUeIcVAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gjkx2XeTkMLzpwQnw0HWR6cGjqsLdO4U/WQvIKOPC5IEpFfJI/mpCeGSu4ssZDLr5 c6+ChlcdLQ1sXoBSMSm1wxBCHnXewzyav6JsCy8TOUk/G8QYpezAM/2z9m1p+vcPTq EiNVVqacvJBBkK/o8ozMh3p6gWLVXY/4yJKoUf/I6+RZSqC476YvAAwI1aDDphBhCp 4FTm2e1OS+aElejAAjFDe4+yGvJ62EDzZicNT5HB8KYrE9o/orGVJRHJJH2XRC2shU PUOfAazZUJZ04/BxllkaQuadg/J1HDK6zjj4mY78svafkViMXaoUJ4hwrObF8six4H vxlR1sbsU1KTQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 23 Jul 2020 15:26:39 +1000 Message-Id: <20200723052641.561009-3-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 2/4] libpdbg: Add apis to convert between spr name and id 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" Signed-off-by: Amitay Isaacs --- Makefile.am | 1 + libpdbg/libpdbg.h | 18 +++++ libpdbg/sprs.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 libpdbg/sprs.c diff --git a/Makefile.am b/Makefile.am index dce09ab..4253a0b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -182,6 +182,7 @@ libpdbg_la_SOURCES = \ libpdbg/p9_scom_addr.h \ libpdbg/sbefifo.c \ libpdbg/sprs.h \ + libpdbg/sprs.c \ libpdbg/target.c \ libpdbg/target.h \ libpdbg/thread.c diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 180a609..71d1de4 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -1067,6 +1067,24 @@ int thread_sreset_all(void); */ struct thread_state thread_status(struct pdbg_target *target); +/** + * @brief Get SPR id from name + * + * @param[in] name SPR name + * + * @return spr id or -1 if not found + */ +int pdbg_spr_by_name(const char *name); + +/** + * @brief Get SPR name from id + * + * @param[in] spr SPR id + * + * @return spr name or NULL if not found + */ +const char *pdbg_spr_by_id(int spr); + int getring(struct pdbg_target *chiplet_target, uint64_t ring_addr, uint64_t ring_len, uint32_t result[]); /** diff --git a/libpdbg/sprs.c b/libpdbg/sprs.c new file mode 100644 index 0000000..0d42ef1 --- /dev/null +++ b/libpdbg/sprs.c @@ -0,0 +1,200 @@ +/* Copyright 2020 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "libpdbg.h" +#include "sprs.h" + +static struct { + const char *spr_name; + int spr_id; +} spr_map[] = { + { "XER", SPR_XER }, + { "DSCR_RU", SPR_DSCR_RU }, + { "LR", SPR_LR }, + { "CTR", SPR_CTR }, + { "UAMR", SPR_UAMR }, + { "DSCR", SPR_DSCR }, + { "DSISR", SPR_DSISR }, + { "DAR", SPR_DAR }, + { "DEC", SPR_DEC }, + { "SDR1", SPR_SDR1 }, + { "SRR0", SPR_SRR0 }, + { "SRR1", SPR_SRR1 }, + { "CFAR", SPR_CFAR }, + { "AMR", SPR_AMR }, + { "PIDR", SPR_PIDR }, + { "IAMR", SPR_IAMR }, + { "TFHAR", SPR_TFHAR }, + { "TFIAR", SPR_TFIAR }, + { "TEXASR", SPR_TEXASR }, + { "TEXASRU", SPR_TEXASRU }, + { "CTRL_RU", SPR_CTRL_RU }, + { "TIDR", SPR_TIDR }, + { "CTRL", SPR_CTRL }, + { "FSCR", SPR_FSCR }, + { "UAMOR", SPR_UAMOR }, + { "GSR", SPR_GSR }, + { "PSPB", SPR_PSPB }, + { "DPDES", SPR_DPDES }, + { "DAWR0", SPR_DAWR0 }, + { "RPR", SPR_RPR }, + { "CIABR", SPR_CIABR }, + { "DAWRX0", SPR_DAWRX0 }, + { "HFSCR", SPR_HFSCR }, + { "VRSAVE", SPR_VRSAVE }, + { "SPRG3_RU", SPR_SPRG3_RU }, + { "TB", SPR_TB }, + { "TBU_RU", SPR_TBU_RU }, + { "SPRG0", SPR_SPRG0 }, + { "SPRG1", SPR_SPRG1 }, + { "SPRG2", SPR_SPRG2 }, + { "SPRG3", SPR_SPRG3 }, + { "SPRC", SPR_SPRC }, + { "SPRD", SPR_SPRD }, + { "CIR", SPR_CIR }, + { "TBL", SPR_TBL }, + { "TBU", SPR_TBU }, + { "TBU40", SPR_TBU40 }, + { "PVR", SPR_PVR }, + { "HSPRG0", SPR_HSPRG0 }, + { "HSPRG1", SPR_HSPRG1 }, + { "HDSISR", SPR_HDSISR }, + { "HDAR", SPR_HDAR }, + { "SPURR", SPR_SPURR }, + { "PURR", SPR_PURR }, + { "HDEC", SPR_HDEC }, + { "HRMOR", SPR_HRMOR }, + { "HSRR0", SPR_HSRR0 }, + { "HSRR1", SPR_HSRR1 }, + { "TFMR", SPR_TFMR }, + { "LPCR", SPR_LPCR }, + { "LPIDR", SPR_LPIDR }, + { "HMER", SPR_HMER }, + { "HMEER", SPR_HMEER }, + { "PCR", SPR_PCR }, + { "HEIR", SPR_HEIR }, + { "AMOR", SPR_AMOR }, + { "TIR", SPR_TIR }, + { "PTCR", SPR_PTCR }, + { "USPRG0", SPR_USPRG0 }, + { "USPRG1", SPR_USPRG1 }, + { "UDAR", SPR_UDAR }, + { "SEIDR", SPR_SEIDR }, + { "URMOR", SPR_URMOR }, + { "USRR0", SPR_USRR0 }, + { "USRR1", SPR_USRR1 }, + { "UEIR", SPR_UEIR }, + { "ACMCR", SPR_ACMCR }, + { "SMFCTRL", SPR_SMFCTRL }, + { "SIER_RU", SPR_SIER_RU }, + { "MMCR2_RU", SPR_MMCR2_RU }, + { "MMCRA_RU", SPR_MMCRA_RU }, + { "PMC1_RU", SPR_PMC1_RU }, + { "PMC2_RU", SPR_PMC2_RU }, + { "PMC3_RU", SPR_PMC3_RU }, + { "PMC4_RU", SPR_PMC4_RU }, + { "PMC5_RU", SPR_PMC5_RU }, + { "PMC6_RU", SPR_PMC6_RU }, + { "MMCR0_RU", SPR_MMCR0_RU }, + { "SIAR_RU", SPR_SIAR_RU }, + { "SDAR_RU", SPR_SDAR_RU }, + { "MMCR1_RU", SPR_MMCR1_RU }, + { "SIER", SPR_SIER }, + { "MMCR2", SPR_MMCR2 }, + { "MMCRA", SPR_MMCRA }, + { "PMC1", SPR_PMC1 }, + { "PMC2", SPR_PMC2 }, + { "PMC3", SPR_PMC3 }, + { "PMC4", SPR_PMC4 }, + { "PMC5", SPR_PMC5 }, + { "PMC6", SPR_PMC6 }, + { "MMCR0", SPR_MMCR0 }, + { "SIAR", SPR_SIAR }, + { "SDAR", SPR_SDAR }, + { "MMCR1", SPR_MMCR1 }, + { "IMC", SPR_IMC }, + { "BESCRS", SPR_BESCRS }, + { "BESCRSU", SPR_BESCRSU }, + { "BESCRR", SPR_BESCRR }, + { "BESCRRU", SPR_BESCRRU }, + { "EBBHR", SPR_EBBHR }, + { "EBBRR", SPR_EBBRR }, + { "BESCR", SPR_BESCR }, + { "LMRR", SPR_LMRR }, + { "LMSER", SPR_LMSER }, + { "TAR", SPR_TAR }, + { "ASDR", SPR_ASDR }, + { "PSSCR_SU", SPR_PSSCR_SU }, + { "IC", SPR_IC }, + { "VTB", SPR_VTB }, + { "LDBAR", SPR_LDBAR }, + { "MMCRC", SPR_MMCRC }, + { "PMSR", SPR_PMSR }, + { "PMMAR", SPR_PMMAR }, + { "PSSCR", SPR_PSSCR }, + { "L2QOSR", SPR_L2QOSR }, + { "WORC", SPR_WORC }, + { "TRIG0", SPR_TRIG0 }, + { "TRIG1", SPR_TRIG1 }, + { "TRIG2", SPR_TRIG2 }, + { "PMCR", SPR_PMCR }, + { "RWMR", SPR_RWMR }, + { "WORT", SPR_WORT }, + { "PPR", SPR_PPR }, + { "PPR32", SPR_PPR32 }, + { "TSCR", SPR_TSCR }, + { "TTR", SPR_TTR }, + { "TRACE", SPR_TRACE }, + { "HID", SPR_HID }, + { "PIR", SPR_PIR }, + { "NIA", SPR_NIA }, + { "MSR", SPR_MSR }, + { "CR", SPR_CR }, + { "FPSCR", SPR_FPSCR }, + { "VSCR", SPR_VSCR }, + { "SLBE", SPR_SLBE }, + { "SLBV", SPR_SLBV }, + { NULL, -1 }, +}; + +int pdbg_spr_by_name(const char *name) +{ + int i; + + for (i = 0; spr_map[i].spr_name != NULL; i++) { + if (!strcasecmp(spr_map[i].spr_name, name)) { + return spr_map[i].spr_id; + } + } + + return -1; +} + +const char *pdbg_spr_by_id(int spr) +{ + int i; + + for (i = 0; spr_map[i].spr_name != NULL; i++) { + if (spr_map[i].spr_id == spr) { + return spr_map[i].spr_name; + } + } + + return NULL; +}