From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wjd9CotpkmASfQAAWB0awg (envelope-from ) for ; Wed, 05 May 2021 05:46:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 1DC881F11C; Wed, 5 May 2021 05:46:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RDNS_DYNAMIC,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3D3B41E54D for ; Wed, 5 May 2021 05:46:49 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A429A3A1935E; Wed, 5 May 2021 09:46:48 +0000 (GMT) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 86DB039A6070 for ; Wed, 5 May 2021 09:46:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 86DB039A6070 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x429.google.com with SMTP id l14so1105928wrx.5 for ; Wed, 05 May 2021 02:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PxjLeSIXKgGrewVIKsOrEpNduloen9HYeP262mPFqE0=; b=DAsRjYA4/O4SIJV4eBJv5KByNDNYdv4hoy0Cxq80NuBdAXrp4fNPrtAmPrE3jQSCJb YSbSwnVxyUDBVLUP2zDmEOCeD2OMCdMQeoDDA4wrdgO0NdPdrY1teZiKrRlDVrxyMtYI V9Qm9DuKHOrx89NE9FwLIXn02CmiTziKtp/YZ0UxJ71pM97fyQi4XIs8oRoBLy93NBz+ oojS1Bh2RkC/0Wqhqy+Z1P6rkrsI3kOEk9sCIzdF7yzoj7nBNApS1hq2oxjxPKxwUPNb L/8c4FCscyuPUFaYYf4HCyRnoHWVKnkm46pckuD510HxhgSQKpY72kuX0fnQHgFeOwE/ SBlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PxjLeSIXKgGrewVIKsOrEpNduloen9HYeP262mPFqE0=; b=bqjFNLFtUAsZc+b+II/5rbnbgsBTclDSJSfolhaGwGAYNfNHe0Udng1JWEK7DipKXF H9wZsMu9W5+jluRk82OHiOOXyjxCDu00RgKKa6G18pvNj19zKJbbamG4tPZ+N9EgtOau sYwJFXhMHTuTmPHwTlfosEhc2sOgxJI0ALonTnKBTr9ZFvmKgPnqY1BlKP9qdsk23UaZ YnMMRMq7TW+tLXx7S9a8H7v9plqR5jQt/VoAbZhc5r3i2lUtrjH6iV7J/NcwCxjhPgIy roKrXR5BMTQ/w1VXXlIOhDylIjM0tY+xnxLr9JJNBYei3W3aF1xl3x3OxcnnZzeRXrAk yQsQ== X-Gm-Message-State: AOAM532IFaQeNFp+EtlVoPzPtXu3muh/aPoEdUtAmZOjC82yEcE2Tx1m fYdjuXf6Nhj42JUJJv7KkfWE/Tnh3Ov4nQ== X-Google-Smtp-Source: ABdhPJwNXONZUxo3SSAmcfQZQUcKP5sgd9rzbFqd6QM62v7T/WevWYBz/IaaEPkOH5HAkdRFfPP0vg== X-Received: by 2002:a5d:6981:: with SMTP id g1mr36166134wru.426.1620208003272; Wed, 05 May 2021 02:46:43 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id q4sm19210721wrs.21.2021.05.05.02.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 02:46:42 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH] gdb/riscv: add support for vector registers in target descriptions Date: Wed, 5 May 2021 10:46:39 +0100 Message-Id: <20210505094639.1551740-1-andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This commit adds support to RISC-V GDB for vector registers in the incoming target description. The vector registers should be described in a feature called "org.gnu.gdb.riscv.vector", and should contain the register v0 to v31. There's no restriction on the size or type of these registers, so the target description can set these up as it requires. However, if the target feature is present then all of the registers must be present, and they must all be the same size, these requirements are, I believe, inline with the RISC-V vector extension. The DWARF register numbers for the vector registers have been added, and the code to map between GDB's internal numbering and the DWARF numbering has been updated. I have not yet added a feature/riscv/*.xml file for the vector extension, the consequence of this is that we can't, right now, detect vector registers on a native target, this patch is all about supporting vectors on a remote target. It is worth noting that I don't actually have access to a RISC-V target with vectors, so the only testing that this patch has had has been done using 'set tdesc filename ....' to load a target description to which I have manually added the vector feature. This has shown that the vector register feature can be successfully parsed, and that the registers show up in the expected register groups. gdb/ChangeLog: * arch/riscv.c (riscv_create_target_description): GDB doesn't currently create target descriptions containing vector registers. * arch/riscv.h (struct riscv_gdbarch_features) : New member variable. : Also compare vlen. : Also include vlen. * riscv-tdep.c (riscv_feature_name_vector): New static global. (struct riscv_vector_feature): New struct. (riscv_vector_feature): New static global. (riscv_register_reggroup_p): Ensure vector registers are part of the 'all' group, and part of the 'vector' group. (riscv_dwarf_reg_to_regnum): Handle vector registers. (riscv_gdbarch_init): Check vector register feature. * riscv-tdep.h: Add vector registers to GDB's internal register numbers, and to the DWARF register numbers. --- gdb/ChangeLog | 18 +++++++ gdb/arch/riscv.c | 6 +++ gdb/arch/riscv.h | 12 ++++- gdb/riscv-tdep.c | 121 +++++++++++++++++++++++++++++++++++++++++++++-- gdb/riscv-tdep.h | 8 +++- 5 files changed, 159 insertions(+), 6 deletions(-) diff --git a/gdb/arch/riscv.c b/gdb/arch/riscv.c index 8fbcad1a8ea..85d60a3e257 100644 --- a/gdb/arch/riscv.c +++ b/gdb/arch/riscv.c @@ -84,6 +84,12 @@ riscv_create_target_description (const struct riscv_gdbarch_features features) else if (features.flen == 8) regnum = create_feature_riscv_64bit_fpu (tdesc.get (), regnum); + /* Currently GDB only supports vector features coming from remote + targets. We don't support creating vector features on native targets + (yet). */ + if (features.vlen != 0) + error (_("unable to create vector feature")); + return tdesc; } diff --git a/gdb/arch/riscv.h b/gdb/arch/riscv.h index faa038a713e..65a998bb2b9 100644 --- a/gdb/arch/riscv.h +++ b/gdb/arch/riscv.h @@ -46,13 +46,20 @@ struct riscv_gdbarch_features that there are no f-registers. No other value is valid. */ int flen = 0; + /* The size of the v-registers in bytes. The value 0 indicates a target + with no vector registers. The minimum value for a standard compliant + target should be 16, but GDB doesn't currently mind, and will accept + any vector size. */ + int vlen = 0; + /* When true this target is RV32E. */ bool embedded = false; /* Equality operator. */ bool operator== (const struct riscv_gdbarch_features &rhs) const { - return (xlen == rhs.xlen && flen == rhs.flen && embedded == rhs.embedded); + return (xlen == rhs.xlen && flen == rhs.flen + && embedded == rhs.embedded && vlen == rhs.vlen); } /* Inequality operator. */ @@ -66,7 +73,8 @@ struct riscv_gdbarch_features { std::size_t val = ((embedded ? 1 : 0) << 10 | (xlen & 0x1f) << 5 - | (flen & 0x1f) << 0); + | (flen & 0x1f) << 0 + | (vlen & 0xfff) << 11); return val; } }; diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index c1783996846..cbcaa7c9155 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -99,6 +99,7 @@ const char *riscv_feature_name_csr = "org.gnu.gdb.riscv.csr"; static const char *riscv_feature_name_cpu = "org.gnu.gdb.riscv.cpu"; static const char *riscv_feature_name_fpu = "org.gnu.gdb.riscv.fpu"; static const char *riscv_feature_name_virtual = "org.gnu.gdb.riscv.virtual"; +static const char *riscv_feature_name_vector = "org.gnu.gdb.riscv.vector"; /* Cached information about a frame. */ @@ -575,6 +576,115 @@ struct riscv_csr_feature : public riscv_register_feature static const struct riscv_csr_feature riscv_csr_feature; +/* Class representing the f-registers feature set. */ + +struct riscv_vector_feature : public riscv_register_feature +{ + riscv_vector_feature () + : riscv_register_feature (riscv_feature_name_vector) + { + m_registers = { + { RISCV_V0_REGNUM + 0, { "v0" } }, + { RISCV_V0_REGNUM + 1, { "v1" } }, + { RISCV_V0_REGNUM + 2, { "v2" } }, + { RISCV_V0_REGNUM + 3, { "v3" } }, + { RISCV_V0_REGNUM + 4, { "v4" } }, + { RISCV_V0_REGNUM + 5, { "v5" } }, + { RISCV_V0_REGNUM + 6, { "v6" } }, + { RISCV_V0_REGNUM + 7, { "v7" } }, + { RISCV_V0_REGNUM + 8, { "v8" } }, + { RISCV_V0_REGNUM + 9, { "v9" } }, + { RISCV_V0_REGNUM + 10, { "v10" } }, + { RISCV_V0_REGNUM + 11, { "v11" } }, + { RISCV_V0_REGNUM + 12, { "v12" } }, + { RISCV_V0_REGNUM + 13, { "v13" } }, + { RISCV_V0_REGNUM + 14, { "v14" } }, + { RISCV_V0_REGNUM + 15, { "v15" } }, + { RISCV_V0_REGNUM + 16, { "v16" } }, + { RISCV_V0_REGNUM + 17, { "v17" } }, + { RISCV_V0_REGNUM + 18, { "v18" } }, + { RISCV_V0_REGNUM + 19, { "v19" } }, + { RISCV_V0_REGNUM + 20, { "v20" } }, + { RISCV_V0_REGNUM + 21, { "v21" } }, + { RISCV_V0_REGNUM + 22, { "v22" } }, + { RISCV_V0_REGNUM + 23, { "v23" } }, + { RISCV_V0_REGNUM + 24, { "v24" } }, + { RISCV_V0_REGNUM + 25, { "v25" } }, + { RISCV_V0_REGNUM + 26, { "v26" } }, + { RISCV_V0_REGNUM + 27, { "v27" } }, + { RISCV_V0_REGNUM + 28, { "v28" } }, + { RISCV_V0_REGNUM + 29, { "v29" } }, + { RISCV_V0_REGNUM + 30, { "v30" } }, + { RISCV_V0_REGNUM + 31, { "v31" } }, + }; + } + + /* Return the preferred name for the register with gdb register number + REGNUM, which must be in the inclusive range RISCV_V0_REGNUM to + RISCV_V0_REGNUM + 31. */ + const char *register_name (int regnum) const + { + gdb_assert (regnum >= RISCV_V0_REGNUM + && regnum <= RISCV_V0_REGNUM + 31); + regnum -= RISCV_V0_REGNUM; + return m_registers[regnum].names[0]; + } + + /* Check this feature within TDESC, record the registers from this + feature into TDESC_DATA and update ALIASES and FEATURES. */ + bool check (const struct target_desc *tdesc, + struct tdesc_arch_data *tdesc_data, + std::vector *aliases, + struct riscv_gdbarch_features *features) const + { + const struct tdesc_feature *feature_vector = tdesc_feature (tdesc); + + /* It's fine if this feature is missing. Update the architecture + feature set and return. */ + if (feature_vector == nullptr) + { + features->vlen = 0; + return true; + } + + /* Check all of the vector registers are present. */ + for (const auto ® : m_registers) + { + if (!reg.check (tdesc_data, feature_vector, true, aliases)) + return false; + } + + /* Look through all of the vector registers and check they all have the + same bitsize. Use this bitsize to update the feature set for this + gdbarch. */ + int vector_bitsize = -1; + for (const auto ® : m_registers) + { + int reg_bitsize = -1; + for (const char *name : reg.names) + { + if (tdesc_unnumbered_register (feature_vector, name)) + { + reg_bitsize = tdesc_register_bitsize (feature_vector, name); + break; + } + } + gdb_assert (reg_bitsize != -1); + if (vector_bitsize == -1) + vector_bitsize = reg_bitsize; + else if (vector_bitsize != reg_bitsize) + return false; + } + + features->vlen = (vector_bitsize / 8); + return true; + } +}; + +/* An instance of the f-register feature set. */ + +static const struct riscv_vector_feature riscv_vector_feature; + /* Controls whether we place compressed breakpoints or not. When in auto mode GDB tries to determine if the target supports compressed breakpoints, and uses them if it does. */ @@ -1192,7 +1302,7 @@ riscv_register_reggroup_p (struct gdbarch *gdbarch, int regnum, if (reggroup == all_reggroup) { - if (regnum < RISCV_FIRST_CSR_REGNUM || regnum == RISCV_PRIV_REGNUM) + if (regnum < RISCV_FIRST_CSR_REGNUM || regnum >= RISCV_PRIV_REGNUM) return 1; if (riscv_is_regnum_a_named_csr (regnum)) return 1; @@ -1226,7 +1336,7 @@ riscv_register_reggroup_p (struct gdbarch *gdbarch, int regnum, return 0; } else if (reggroup == vector_reggroup) - return 0; + return (regnum >= RISCV_V0_REGNUM && regnum <= RISCV_V31_REGNUM); else return 0; } @@ -3320,6 +3430,9 @@ riscv_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg) else if (reg >= RISCV_DWARF_FIRST_CSR && reg <= RISCV_DWARF_LAST_CSR) return RISCV_FIRST_CSR_REGNUM + (reg - RISCV_DWARF_FIRST_CSR); + else if (reg >= RISCV_DWARF_REGNUM_V0 && reg <= RISCV_DWARF_REGNUM_V31) + return RISCV_V0_REGNUM + (reg - RISCV_DWARF_REGNUM_V0); + return -1; } @@ -3488,7 +3601,9 @@ riscv_gdbarch_init (struct gdbarch_info info, && riscv_virtual_feature.check (tdesc, tdesc_data.get (), &pending_aliases, &features) && riscv_csr_feature.check (tdesc, tdesc_data.get (), - &pending_aliases, &features)); + &pending_aliases, &features) + && riscv_vector_feature.check (tdesc, tdesc_data.get (), + &pending_aliases, &features)); if (!valid_p) { if (riscv_debug_gdbarch) diff --git a/gdb/riscv-tdep.h b/gdb/riscv-tdep.h index 154097df5d0..62bf4797d02 100644 --- a/gdb/riscv-tdep.h +++ b/gdb/riscv-tdep.h @@ -53,7 +53,11 @@ enum RISCV_PRIV_REGNUM = 4161, - RISCV_LAST_REGNUM = RISCV_PRIV_REGNUM + RISCV_V0_REGNUM, + + RISCV_V31_REGNUM = RISCV_V0_REGNUM + 31, + + RISCV_LAST_REGNUM = RISCV_V31_REGNUM }; /* RiscV DWARF register numbers. */ @@ -63,6 +67,8 @@ enum RISCV_DWARF_REGNUM_X31 = 31, RISCV_DWARF_REGNUM_F0 = 32, RISCV_DWARF_REGNUM_F31 = 63, + RISCV_DWARF_REGNUM_V0 = 96, + RISCV_DWARF_REGNUM_V31 = 127, RISCV_DWARF_FIRST_CSR = 4096, RISCV_DWARF_LAST_CSR = 8191, }; -- 2.25.4