From patchwork Fri Nov 10 07:20:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jin Ma X-Patchwork-Id: 163780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp942208vqs; Thu, 9 Nov 2023 23:21:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqEoC8Pwi5YSU0F+sAWB/0mgv6F4GKOJOCAQu0edX2Ut0J8KeOVqC7vRy+RTGLBTzoeoms X-Received: by 2002:a05:6214:e61:b0:658:41ee:faf2 with SMTP id jz1-20020a0562140e6100b0065841eefaf2mr7035937qvb.23.1699600878734; Thu, 09 Nov 2023 23:21:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699600878; cv=pass; d=google.com; s=arc-20160816; b=kmeUh4tn/f43c7/yuSo+GfTSB8VCtoeUlE9q17+CDc75kGzUscZfdOKqtvYIyhJo4B WB1xNXTh7fpJqycFFy1rGLNVe76+MvvBCvrQoW1iUwq3HHzU6z2GqFTFdRazH8Ti81RS iQMBxgNuvWm0PQXLzjgFcE5qCu9fIFCUtNe46dVJA1CAK877nCUIOpLJ4Re8HxdbJiuL 5peRNZzDsEnfkWxR5/Xj9yezoy8hoMOuQfukdFFF/PSifHJRqx2nL9C37COdG1jo8aMD u5j0J+jGUF88ZxcXzWPFUdG3/mXWOKWPXeCA/Z4PRpIiB1cK/g10Od40lVuIXCyemow5 LFTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=+U+3O4B+lyfaNpc0QumcINhXoXIR1DGgzeGhXcmCjDM=; fh=zn+5wiT9OU3FDcK89PQRhJye+jap/WeWco5fxQ3I7vE=; b=ZkclH8GGtOnKMl8UCYrm18e116J7259HHm4Le+SOVnwq2o3ObLQRqOH+QpPYC3b8Ud mcQQdVkkUrtIRnb0+cK3hPkYnuw+xawQgQD28tyZ9ZA/O9Sr+162SvSH4zLOimZDlz8r 5f7S4vvf/8zm9dSG9RVsbevOTnWHnZFg/pdkjpS8ReWXA3WgdiYNQx5AQ+axUCllSy4P h4Yd+P44suasKXKk9usBTjFLjL5T1E4Ebiz4F0pCZPLQ2HEEFiLUY8CHtqmm6r6Inu0G oeSkHL66IgawywICtP8VpjnbqwVaIgH3TJBXQMkFQaFybP4EirVFxj2sIaKsBDo7VHGh PEkQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f9-20020a0cbec9000000b0066d5b0994c0si3957334qvj.402.2023.11.09.23.21.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 23:21:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EFE7385703F for ; Fri, 10 Nov 2023 07:21:18 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by sourceware.org (Postfix) with ESMTPS id 805853858D38 for ; Fri, 10 Nov 2023 07:21:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 805853858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 805853858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699600874; cv=none; b=ZfTMPeSED3uM9BO1Xry3XSkiGIsakOYAtqnlsj2wLXKUplo0YOY1cC0bAlQoesQmcIIQ6FMeHNMAuqzumgWhx7LJxbUwbQ9oZZIZqVH9kHATtNRusVDFPrZUOiAWKp2sYCOSqI9/L3wwodOodwpAJ1ZFtCPzAq3DTYVnu6U9FBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699600874; c=relaxed/simple; bh=IOPOZFkibu4L49zwq2HtUhEJD55nJ9uo/839IxB66jw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=iZ+3BfEIyiXiw30cPdee1ZXTaQZzwMZJLM0/sB/zhAJ9wRKMBkRgp4TXIfMrFb8CqdG/AAeTcxL6E29pXap/2sXOoTErPDvPC8EN8hhQtHsnKAbELAL9xgElMyBcZYpzC135VKXylX/lRfZIcK9lMjtT5FYIxeK64XYoHL7+G70= ARC-Authentication-Results: i=1; server2.sourceware.org X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045192; MF=jinma@linux.alibaba.com; NM=1; PH=DS; RN=6; SR=0; TI=SMTPD_---0Vw3jADe_1699600865; Received: from localhost.localdomain(mailfrom:jinma@linux.alibaba.com fp:SMTPD_---0Vw3jADe_1699600865) by smtp.aliyun-inc.com; Fri, 10 Nov 2023 15:21:07 +0800 From: Jin Ma To: binutils@sourceware.org, nelson@rivosinc.com Cc: christoph.muellner@vrull.eu, lifang_xia@linux.alibaba.com, jinma.contrib@gmail.com, Jin Ma Subject: [PATCH 02/12] RISC-V: Add CSRs for T-Head VECTOR vendor extension Date: Fri, 10 Nov 2023 15:20:15 +0800 Message-Id: <20231110072015.1684-1-jinma@linux.alibaba.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20231110071759.1640-1-jinma@linux.alibaba.com> References: <20231110071759.1640-1-jinma@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-20.2 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782160691237896877 X-GMAIL-MSGID: 1782160691237896877 T-Head has a range of vendor-specific instructions. Therefore it makes sense to group them into smaller chunks in form of vendor extensions. This patch adds the CSRs for XTheadVector. Because of the conflict between encoding and teh 'V' extension, it is implemented by alias. The 'th' prefix and the "XTheadVector" extension are documented in a PR for the RISC-V toolchain conventions ([1]). [1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/19 Co-developed-by: Lifang Xia Co-developed-by: Christoph Müllner gas/ChangeLog: * config/tc-riscv.c (enum riscv_csr_class): Add the class for the CSRs of the "XTheadVector" extension. (riscv_csr_address): Likewise. * testsuite/gas/riscv/x-thead-vector-csr-warn.d: New test. * testsuite/gas/riscv/x-thead-vector-csr-warn.l: New test. * testsuite/gas/riscv/x-thead-vector-csr.d: New test. * testsuite/gas/riscv/x-thead-vector-csr.s: New test. include/ChangeLog: * opcode/riscv-opc.h (DECLARE_CSR_ALIAS): Likewise. opcodes/ChangeLog: * riscv-dis.c (print_insn_args): Prefix the CSRs disassembly with 'th'. --- gas/config/tc-riscv.c | 4 ++++ .../gas/riscv/x-thead-vector-csr-warn.d | 3 +++ .../gas/riscv/x-thead-vector-csr-warn.l | 16 ++++++++++++++ gas/testsuite/gas/riscv/x-thead-vector-csr.d | 21 +++++++++++++++++++ gas/testsuite/gas/riscv/x-thead-vector-csr.s | 13 ++++++++++++ include/opcode/riscv-opc.h | 7 +++++++ opcodes/riscv-dis.c | 14 +++++++++++-- 7 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 gas/testsuite/gas/riscv/x-thead-vector-csr-warn.d create mode 100644 gas/testsuite/gas/riscv/x-thead-vector-csr-warn.l create mode 100644 gas/testsuite/gas/riscv/x-thead-vector-csr.d create mode 100644 gas/testsuite/gas/riscv/x-thead-vector-csr.s diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 402c46ad753..af9a34a2185 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -91,6 +91,7 @@ enum riscv_csr_class CSR_CLASS_SSTC_AND_H, /* Sstc only (with H) */ CSR_CLASS_SSTC_32, /* Sstc RV32 only */ CSR_CLASS_SSTC_AND_H_32, /* Sstc RV32 only (with H) */ + CSR_CLASS_XTHEADVECTOR, /* xtheadvector only */ }; /* This structure holds all restricted conditions for a CSR. */ @@ -1104,6 +1105,9 @@ riscv_csr_address (const char *csr_name, break; case CSR_CLASS_DEBUG: break; + case CSR_CLASS_XTHEADVECTOR: + extension = "xtheadvector"; + break; default: as_bad (_("internal: bad RISC-V CSR class (0x%x)"), csr_class); } diff --git a/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.d b/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.d new file mode 100644 index 00000000000..17c707ddc7e --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.d @@ -0,0 +1,3 @@ +#as: -march=rv64gc -mcsr-check +#source: x-thead-vector-csr.s +#warning_output: x-thead-vector-csr-warn.l diff --git a/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.l b/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.l new file mode 100644 index 00000000000..4dd867ce2ee --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-vector-csr-warn.l @@ -0,0 +1,16 @@ +.*Assembler messages: +.*Warning: invalid CSR `th.vstart', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vxsat', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vxrm', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vl', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vtype', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vlenb', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vstart', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vxsat', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vxrm', needs `xtheadvector' extension +.*Warning: invalid CSR `th.vl', needs `xtheadvector' extension +.*Warning: read-only CSR is written `csrw th.vl,a0' +.*Warning: invalid CSR `th.vtype', needs `xtheadvector' extension +.*Warning: read-only CSR is written `csrw th.vtype,a0' +.*Warning: invalid CSR `th.vlenb', needs `xtheadvector' extension +.*Warning: read-only CSR is written `csrw th.vlenb,a0' \ No newline at end of file diff --git a/gas/testsuite/gas/riscv/x-thead-vector-csr.d b/gas/testsuite/gas/riscv/x-thead-vector-csr.d new file mode 100644 index 00000000000..75357b204cc --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-vector-csr.d @@ -0,0 +1,21 @@ +#as: -march=rv32if_xtheadvector +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +0+000 <.text>: +[ ]+[0-9a-f]+:[ ]+00802573[ ]+csrr[ ]+a0,th.vstart +[ ]+[0-9a-f]+:[ ]+00902573[ ]+csrr[ ]+a0,th.vxsat +[ ]+[0-9a-f]+:[ ]+00a02573[ ]+csrr[ ]+a0,th.vxrm +[ ]+[0-9a-f]+:[ ]+c2002573[ ]+csrr[ ]+a0,th.vl +[ ]+[0-9a-f]+:[ ]+c2102573[ ]+csrr[ ]+a0,th.vtype +[ ]+[0-9a-f]+:[ ]+c2202573[ ]+csrr[ ]+a0,th.vlenb +[ ]+[0-9a-f]+:[ ]+00851073[ ]+csrw[ ]+th.vstart,a0 +[ ]+[0-9a-f]+:[ ]+00951073[ ]+csrw[ ]+th.vxsat,a0 +[ ]+[0-9a-f]+:[ ]+00a51073[ ]+csrw[ ]+th.vxrm,a0 +[ ]+[0-9a-f]+:[ ]+c2051073[ ]+csrw[ ]+th.vl,a0 +[ ]+[0-9a-f]+:[ ]+c2151073[ ]+csrw[ ]+th.vtype,a0 +[ ]+[0-9a-f]+:[ ]+c2251073[ ]+csrw[ ]+th.vlenb,a0 diff --git a/gas/testsuite/gas/riscv/x-thead-vector-csr.s b/gas/testsuite/gas/riscv/x-thead-vector-csr.s new file mode 100644 index 00000000000..e11f87f1a07 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-vector-csr.s @@ -0,0 +1,13 @@ + csrr a0, th.vstart + csrr a0, th.vxsat + csrr a0, th.vxrm + csrr a0, th.vl + csrr a0, th.vtype + csrr a0, th.vlenb + + csrw th.vstart, a0 + csrw th.vxsat, a0 + csrw th.vxrm, a0 + csrw th.vl, a0 # read-only CSR + csrw th.vtype, a0 # read-only CSR + csrw th.vlenb, a0 # read-only CSR diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h index 24217062edc..ed29384e825 100644 --- a/include/opcode/riscv-opc.h +++ b/include/opcode/riscv-opc.h @@ -4121,4 +4121,11 @@ DECLARE_CSR_ALIAS(etrigger, CSR_TDATA1, CSR_CLASS_DEBUG, PRIV_SPEC_CLASS_NONE, P DECLARE_CSR_ALIAS(tmexttrigger, CSR_TDATA1, CSR_CLASS_DEBUG, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) DECLARE_CSR_ALIAS(textra32, CSR_TDATA3, CSR_CLASS_DEBUG, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) DECLARE_CSR_ALIAS(textra64, CSR_TDATA3, CSR_CLASS_DEBUG, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +/* Unprivileged T-Head Vector CSRs. */ +DECLARE_CSR_ALIAS(th.vstart, CSR_VSTART, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +DECLARE_CSR_ALIAS(th.vxsat, CSR_VXSAT, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +DECLARE_CSR_ALIAS(th.vxrm, CSR_VXRM, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +DECLARE_CSR_ALIAS(th.vl, CSR_VL, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +DECLARE_CSR_ALIAS(th.vtype, CSR_VTYPE, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) +DECLARE_CSR_ALIAS(th.vlenb, CSR_VLENB, CSR_CLASS_XTHEADVECTOR, PRIV_SPEC_CLASS_NONE, PRIV_SPEC_CLASS_NONE) #endif /* DECLARE_CSR_ALIAS */ diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index ca328b4c997..2d7c154cc3d 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -568,8 +568,18 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info } if (riscv_csr_hash[csr] != NULL) - print (info->stream, dis_style_register, "%s", - riscv_csr_hash[csr]); + if (riscv_subset_supports (&riscv_rps_dis, "xtheadvector") + && (csr == CSR_VSTART + || csr == CSR_VXSAT + || csr == CSR_VXRM + || csr == CSR_VL + || csr == CSR_VTYPE + || csr == CSR_VLENB)) + print (info->stream, dis_style_register, "%s", + concat ("th.", riscv_csr_hash[csr], NULL)); + else + print (info->stream, dis_style_register, "%s", + riscv_csr_hash[csr]); else print (info->stream, dis_style_immediate, "0x%x", csr); break;