From patchwork Wed Nov 23 08:30:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 24787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2662664wrr; Wed, 23 Nov 2022 00:31:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5haSQIqwZ9Ja1y04Po2jC3jmTDZDKZd481zJJW72Xa9skWgCrOlxKtMvSYVFnQMxFi1pt0 X-Received: by 2002:a17:906:fa19:b0:78d:9002:fe3b with SMTP id lo25-20020a170906fa1900b0078d9002fe3bmr19196457ejb.769.1669192285878; Wed, 23 Nov 2022 00:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669192285; cv=none; d=google.com; s=arc-20160816; b=BN22FFAPJ9BKCfpzeMhnzxrEd+3mYV27wiFhh1e2aHil8ivmrvRN6w6TpCS2ov+DTK tP2YWtIKDqJYqgrOPRyBguLlukBFcN05wHckvSyRIXIu163oyN973Jkbq9q+O4UntkaV 8unF6u2HE/nCHgZ7Mju6O6RmZEa2n3FPUAmKTJZiTN1dYwWKvSZ+Bvy7vLTtECoZiiXY 9HbwO6BthJIktkVUr8n2X96YEGOekSmBckG35QCgF+XObaIzs6uMrlZSHTQx/2doP3or 3+s4maPxvR5O82+Teh/m+ZVHPbb2J4iu34toNIewWn9DIMFbyv9OaMsI1kCH9PqpY99k 4OWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=lMbwzV8pxc4MFXKs32W+YM7Qn3NCimwyMcbeUOY+7XU=; b=Fjh5d0wKrXb0TbFvy8esh/4vYgyqLh0qMjkjmC3I+9/Od8jYd0EfwwEmJfnAaoYKXf ECmn08/aFuXnPiYx1g2ZuD/NDMqP0bmHcimeKR32yvstL6EjISnQ8OwyIqQXg8sI1ecU KExrAVjqF3NwLGPTQxbgHpSvbStP3mG0Va7GpRxapdEst7Qsp8JayWcPJb1SP617kEzx 4VS8wlcZu0YbRxFhHJgNJHOFEJyA3pWcL+RdH1IbwgoGf9De1XNHP3Csx88XJnAuJueQ gPEZ+fnR7i9vXUnlRmqNVuoIzsZxxIz5CO/woKV2iue//LEhzd/0v7xQd8iib7yaK2i1 PDKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ea34tuRP; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id tz14-20020a170907c78e00b0078d288ddfc9si12106389ejc.143.2022.11.23.00.31.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 00:31:25 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ea34tuRP; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24A5F3853D5E for ; Wed, 23 Nov 2022 08:31:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24A5F3853D5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669192280; bh=lMbwzV8pxc4MFXKs32W+YM7Qn3NCimwyMcbeUOY+7XU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ea34tuRPRVtO/w4twSqojrCaMye+TMFaPP0gfZAxd2W3bfE31Z0xbYrbbNifkgM3g HWi3PB4iK/RrxPrD2sRb8H49zi0BPQ+m7TMJdDlwaOhPW056++odsYPcbNx8EmWm6W N/A2IIxkgrFlCr5QthLRvvHNq+AIShJoD7paFS10= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 6FB8D3853D69 for ; Wed, 23 Nov 2022 08:31:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FB8D3853D69 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id E79C3300089; Wed, 23 Nov 2022 08:31:07 +0000 (UTC) To: Tsukasa OI , Jan Beulich , Nelson Chu Cc: binutils@sourceware.org Subject: [PATCH v2 1/2] RISC-V: Make .insn tests stricter Date: Wed, 23 Nov 2022 08:30:48 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749907636693184017?= X-GMAIL-MSGID: =?utf-8?q?1750274970319460222?= From: Tsukasa OI To make sure that all instruction bits are dumped through ".byte", this commit makes matching patterns stricter (to cover all instruction bits). gas/ChangeLog: * testsuite/gas/riscv/insn.d: Make pattern stricter. * testsuite/gas/riscv/insn-na.d: Likewise. --- gas/testsuite/gas/riscv/insn-na.d | 20 ++++++++++---------- gas/testsuite/gas/riscv/insn.d | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gas/testsuite/gas/riscv/insn-na.d b/gas/testsuite/gas/riscv/insn-na.d index 66dce71ebc21..be6c9f9dd66a 100644 --- a/gas/testsuite/gas/riscv/insn-na.d +++ b/gas/testsuite/gas/riscv/insn-na.d @@ -61,15 +61,15 @@ Disassembly of section .text: [^:]+:[ ]+022180d7[ ]+vadd\.vv[ ]+v1,v2,v3 [^:]+:[ ]+0001[ ]+c\.addi[ ]+zero,0 [^:]+:[ ]+00000013[ ]+addi[ ]+zero,zero,0 -[^:]+:[ ]+001f 0000 0000[ ].* -[^:]+:[ ]+0000003f 00000000[ ].* -[^:]+:[ ]+007f 0000 0000 0000 0000[ ]+[._a-z].* -[^:]+:[ ]+0000107f 00000000 00000000[ ]+[._a-z].* -[^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+[._a-z].* +[^:]+:[ ]+001f 0000 0000[ ]+\.byte[ ]+0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+0000003f 00000000[ ]+\.8byte[ ]+0x3f +[^:]+:[ ]+007f 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+0000107f 00000000 00000000[ ]+\.byte[ ]+0x7f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+0001[ ]+c\.addi[ ]+zero,0 [^:]+:[ ]+00000013[ ]+addi[ ]+zero,zero,0 -[^:]+:[ ]+001f 0000 0000[ ].* -[^:]+:[ ]+0000003f 00000000[ ].* -[^:]+:[ ]+007f 0000 0000 0000 0000[ ]+[._a-z].* -[^:]+:[ ]+0000107f 00000000 00000000[ ]+[._a-z].* -[^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+[._a-z].* +[^:]+:[ ]+001f 0000 0000[ ]+\.byte[ ]+0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+0000003f 00000000[ ]+\.8byte[ ]+0x3f +[^:]+:[ ]+007f 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+0000107f 00000000 00000000[ ]+\.byte[ ]+0x7f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 diff --git a/gas/testsuite/gas/riscv/insn.d b/gas/testsuite/gas/riscv/insn.d index 2e5d35b39702..cf84f177af39 100644 --- a/gas/testsuite/gas/riscv/insn.d +++ b/gas/testsuite/gas/riscv/insn.d @@ -83,12 +83,12 @@ Disassembly of section .text: [^:]+:[ ]+0000 0000 0000 ? [^:]+:[ ]+0001[ ]+nop [^:]+:[ ]+00000013[ ]+nop -[^:]+:[ ]+001f 0000 0000[ ].* -[^:]+:[ ]+0000003f 00000000[ ].* -[^:]+:[ ]+007f 0000 0000 0000[ ]+[._a-z].* +[^:]+:[ ]+001f 0000 0000[ ]+\.byte[ ]+0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+0000003f 00000000[ ]+\.8byte[ ]+0x3f +[^:]+:[ ]+007f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+0000 ? -[^:]+:[ ]+0000107f 00000000[ ]+[._a-z].* +[^:]+:[ ]+0000107f 00000000[ ]+\.byte[ ]+0x7f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+00000000 ? -[^:]+:[ ]+607f 0000 0000 0000[ ]+[._a-z].* +[^:]+:[ ]+607f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+0000 0000 0000 0000 ? [^:]+:[ ]+0000 0000 0000 ? From patchwork Wed Nov 23 08:30:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 24789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2663007wrr; Wed, 23 Nov 2022 00:32:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kIUZROipZtt3I3yiogkmpWdMb1hbHWX4VnU9U5KA+j16ijJFS6FYzqBgIEiipLqT/g7cB X-Received: by 2002:aa7:c9d1:0:b0:461:4ab3:97ca with SMTP id i17-20020aa7c9d1000000b004614ab397camr8693145edt.211.1669192346840; Wed, 23 Nov 2022 00:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669192346; cv=none; d=google.com; s=arc-20160816; b=IwL0lI7CkcR6eSFR72s0y8wCtNTgpmAtnO9afYjKlXs1X8wbWABw9qbG8nx68id+Ev tr6WGXcb5/kPlVT2gbyP/mhsdc8YYACSGYicJnjIa0E4yAX3BINj/Jkw9bL4YOYA7S5x 3ixmZRRozx5p2DBhzDHPMvpQI36vN41cu3X8D9hUn8lZ++R4bamI3pK8Y3JOD3zgfuFk 7vbynAkIgwixCC05A+WJqaMz0g47NWYgwALmR0dK30oZwS+4tYV3gxlKjHJhzqtIigwk fFzOwVSNW7/wkywldecjJsYZpKUTzgeLl5kOx0GlZRxHUe8jtRxWgWKDDjnCMu4w9782 RdCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=WBaOwVw980jL7UnTp/ysqXduIfKG2hLTW2bCSHHZrPs=; b=KQFAptSrWuZMFJd/qVcqkpploKFXpRWSwF/wBv64vmI07WrAhWCFiu0Xmo6IkcNMf0 EteLAzUmumy7izALyZGbinuduAbfo3paeOAAyAUjdwBQlIh2p4xEhxE81R0JHc0XiBMF 9zev00N9UaBsv66iuQFc7UbeH6/+hz79P/zWyqFOXABlfMwW2m2IvKj00uka1dR5GH58 8CcPC61l6xl4E95uybF7dJHZ9fFpGtT1A5MKg5RElfZ96CA1KDqK+qimEA6CfU3s6YVS pdZPhuKjPG2G9OtxHcWHtJNpGvFJIqnGDGPY4eBXuj1cvyJZLlW/14UeLIhjpNE82jxc 1F3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=whfGXUXY; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y7-20020a1709060a8700b0078e9ca562d8si11636208ejf.879.2022.11.23.00.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 00:32:26 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=whfGXUXY; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 478103852C46 for ; Wed, 23 Nov 2022 08:32:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 478103852C46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669192342; bh=WBaOwVw980jL7UnTp/ysqXduIfKG2hLTW2bCSHHZrPs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=whfGXUXYIvshXD4Rl4XVq/VyTIgRFNowyHXAkEaaiDeip8KrlUSMJIBgZ6V1PAPlB TKfuDLpi6pcraoQfdu2ySzyZZvrnvYyOfpIdPp9fcsZ7iQmwBk2S4vXW41K1uq5C6v 3c0AfFEC89rqcGyvGHZA+N++Zb2kxDiYFncmMCJQ= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 18F41385457E for ; Wed, 23 Nov 2022 08:31:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 18F41385457E Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 7007C300089; Wed, 23 Nov 2022 08:31:18 +0000 (UTC) To: Tsukasa OI , Jan Beulich , Nelson Chu Cc: binutils@sourceware.org Subject: [PATCH v2 2/2] RISC-V: Better support for long instructions Date: Wed, 23 Nov 2022 08:30:49 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_LOTSOFHASH, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749907698763029591?= X-GMAIL-MSGID: =?utf-8?q?1750275034415735546?= From: Tsukasa OI Commit bb996692bd96 ("RISC-V/gas: allow generating up to 176-bit instructions with .insn") tried to start supporting long instructions but it was insufficient. 1. It heavily depended on the bignum internals (radix of 2^16), 2. It generates "value conflicts with instruction length" even if a big number instruction encoding does not exceed its expected length, 3. Because long opcode was handled separately (from struct riscv_cl_insn), some information like DWARF line number correspondence was missing and 4. On the disassembler, disassembler dump was limited up to 64-bit. For long (unknown) instructions, instruction bits are incorrectly zeroed out. To solve these problems, this commit: 1. Handles bignum (and its encodings) precisely, 2. Incorporates long opcode handling into regular struct riscv_cl_insn-handling functions and 3. Adds packet argument to support dumping instructions longer than 64-bits. gas/ChangeLog: * config/tc-riscv.c (struct riscv_cl_insn): Add long opcode field. (create_insn) Clear long opcode marker. (install_insn) Install longer opcode as well. (s_riscv_insn) Likewise. (riscv_ip_hardcode): Make big number handling stricter. Length and the value conflicts only if the bignum size exceeds the expected maximum length. * testsuite/gas/riscv/insn.s: Add testcases such that big number handling is required. * testsuite/gas/riscv/insn.d: Likewise. * testsuite/gas/riscv/insn-na.d: Likewise. * testsuite/gas/riscv/insn-dwarf.d: Likewise. opcodes/ChangeLog: * riscv-dis.c (riscv_disassemble_insn): Print unknown instruction using the new argument packet. (riscv_disassemble_data): Add unused argument packet. (print_insn_riscv): Pass packet to the disassemble function. --- gas/config/tc-riscv.c | 38 ++++++++++++++++++++++------ gas/testsuite/gas/riscv/insn-dwarf.d | 10 +++++++- gas/testsuite/gas/riscv/insn-na.d | 8 ++++++ gas/testsuite/gas/riscv/insn.d | 22 ++++++++++++++++ gas/testsuite/gas/riscv/insn.s | 9 +++++++ opcodes/riscv-dis.c | 13 ++++++---- 6 files changed, 86 insertions(+), 14 deletions(-) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 019545171f5e..2237062d8b45 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -45,6 +45,9 @@ struct riscv_cl_insn /* The encoded instruction bits. */ insn_t insn_opcode; + /* The long encoded instruction bits ([0] is non-zero if used). */ + char insn_long_opcode[RISCV_MAX_INSN_LEN]; + /* The frag that contains the instruction. */ struct frag *frag; @@ -714,6 +717,7 @@ create_insn (struct riscv_cl_insn *insn, const struct riscv_opcode *mo) { insn->insn_mo = mo; insn->insn_opcode = mo->match; + insn->insn_long_opcode[0] = 0; /* Long insn has non-zero value. */ insn->frag = NULL; insn->where = 0; insn->fixp = NULL; @@ -725,7 +729,10 @@ static void install_insn (const struct riscv_cl_insn *insn) { char *f = insn->frag->fr_literal + insn->where; - number_to_chars_littleendian (f, insn->insn_opcode, insn_length (insn)); + if (insn->insn_long_opcode[0] != 0) + memcpy (f, insn->insn_long_opcode, insn_length (insn)); + else + number_to_chars_littleendian (f, insn->insn_opcode, insn_length (insn)); } /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly @@ -3481,7 +3488,9 @@ riscv_ip_hardcode (char *str, values[num++] = (insn_t) imm_expr->X_add_number; break; case O_big: - values[num++] = generic_bignum[0]; + /* Extract lower 32-bits of a big number. + Assume that generic_bignum_to_int32 work on such number. */ + values[num++] = (insn_t) generic_bignum_to_int32 (); break; default: /* The first value isn't constant, so it should be @@ -3508,12 +3517,25 @@ riscv_ip_hardcode (char *str, if (imm_expr->X_op == O_big) { - if (bytes != imm_expr->X_add_number * CHARS_PER_LITTLENUM) + unsigned int llen = 0; + for (LITTLENUM_TYPE lval = generic_bignum[imm_expr->X_add_number - 1]; + lval != 0; llen++) + lval >>= BITS_PER_CHAR; + unsigned int repr_bytes + = (imm_expr->X_add_number - 1) * CHARS_PER_LITTLENUM + llen; + if (bytes < repr_bytes) return _("value conflicts with instruction length"); - char *f = frag_more (bytes); - for (num = 0; num < imm_expr->X_add_number; ++num) - number_to_chars_littleendian (f + num * CHARS_PER_LITTLENUM, - generic_bignum[num], CHARS_PER_LITTLENUM); + for (num = 0; num < imm_expr->X_add_number - 1; ++num) + number_to_chars_littleendian ( + ip->insn_long_opcode + num * CHARS_PER_LITTLENUM, + generic_bignum[num], + CHARS_PER_LITTLENUM); + if (llen != 0) + number_to_chars_littleendian ( + ip->insn_long_opcode + num * CHARS_PER_LITTLENUM, + generic_bignum[num], + llen); + memset(ip->insn_long_opcode + repr_bytes, 0, bytes - repr_bytes); return NULL; } @@ -4590,7 +4612,7 @@ s_riscv_insn (int x ATTRIBUTE_UNUSED) else as_bad ("%s `%s'", error.msg, error.statement); } - else if (imm_expr.X_op != O_big) + else { gas_assert (insn.insn_mo->pinfo != INSN_MACRO); append_insn (&insn, &imm_expr, imm_reloc); diff --git a/gas/testsuite/gas/riscv/insn-dwarf.d b/gas/testsuite/gas/riscv/insn-dwarf.d index 89dc8d58ff09..b8bd42dff18c 100644 --- a/gas/testsuite/gas/riscv/insn-dwarf.d +++ b/gas/testsuite/gas/riscv/insn-dwarf.d @@ -74,5 +74,13 @@ insn.s +69 +0xf6.* insn.s +70 +0xfe.* insn.s +71 +0x108.* insn.s +72 +0x114.* -insn.s +- +0x12a +insn.s +74 +0x12a.* +insn.s +75 +0x134.* +insn.s +76 +0x13e.* +insn.s +77 +0x154.* +insn.s +78 +0x16a.* +insn.s +79 +0x180.* +insn.s +80 +0x196.* +insn.s +81 +0x1ac.* +insn.s +- +0x1c2 #pass diff --git a/gas/testsuite/gas/riscv/insn-na.d b/gas/testsuite/gas/riscv/insn-na.d index be6c9f9dd66a..60024555c71f 100644 --- a/gas/testsuite/gas/riscv/insn-na.d +++ b/gas/testsuite/gas/riscv/insn-na.d @@ -73,3 +73,11 @@ Disassembly of section .text: [^:]+:[ ]+007f 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+0000107f 00000000 00000000[ ]+\.byte[ ]+0x7f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 +[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 +[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe diff --git a/gas/testsuite/gas/riscv/insn.d b/gas/testsuite/gas/riscv/insn.d index cf84f177af39..b02d67c5f120 100644 --- a/gas/testsuite/gas/riscv/insn.d +++ b/gas/testsuite/gas/riscv/insn.d @@ -92,3 +92,25 @@ Disassembly of section .text: [^:]+:[ ]+607f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 [^:]+:[ ]+0000 0000 0000 0000 ? [^:]+:[ ]+0000 0000 0000 ? +[^:]+:[ ]+007f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 +[^:]+:[ ]+8000 ? +[^:]+:[ ]+007f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 +[^:]+:[ ]+8000 ? +[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+3210 7654 ba98 fedc ? +[^:]+:[ ]+0000 0000 0000 ? +[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +[^:]+:[ ]+3210 7654 ba98 fedc ? +[^:]+:[ ]+0000 0000 0000 ? +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 +[^:]+:[ ]+89ab 4567 0123 3210 ? +[^:]+:[ ]+7654 ba98 00dc ? +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 +[^:]+:[ ]+89ab 4567 0123 3210 ? +[^:]+:[ ]+7654 ba98 00dc ? +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe +[^:]+:[ ]+89ab 4567 0123 3210 ? +[^:]+:[ ]+7654 ba98 fedc ? +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe +[^:]+:[ ]+89ab 4567 0123 3210 ? +[^:]+:[ ]+7654 ba98 fedc ? diff --git a/gas/testsuite/gas/riscv/insn.s b/gas/testsuite/gas/riscv/insn.s index 94f62fe5672e..48db59b14e88 100644 --- a/gas/testsuite/gas/riscv/insn.s +++ b/gas/testsuite/gas/riscv/insn.s @@ -70,3 +70,12 @@ target: .insn 10, 0x007f .insn 12, 0x107f .insn 22, 0x607f + + .insn 0x8000000000000000007f + .insn 10, 0x8000000000000000007f + .insn 0x000000000000fedcba98765432100123456789ab607f + .insn 22, 0x000000000000fedcba98765432100123456789ab607f + .insn 0x00dcba98765432100123456789abcdef55aa33cc607f + .insn 22, 0x00dcba98765432100123456789abcdef55aa33cc607f + .insn 0xfedcba98765432100123456789abcdef55aa33cc607f + .insn 22, 0xfedcba98765432100123456789abcdef55aa33cc607f diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 3a31647a2f80..59ebbaf13417 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -641,7 +641,10 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info this is little-endian code. */ static int -riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info) +riscv_disassemble_insn (bfd_vma memaddr, + insn_t word, + const bfd_byte *packet, + disassemble_info *info) { const struct riscv_opcode *op; static bool init = false; @@ -806,8 +809,7 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info) ", "); (*info->fprintf_styled_func) (info->stream, dis_style_immediate, "0x%02x", - (unsigned int) (word & 0xff)); - word >>= 8; + (unsigned int) (*packet++)); } } break; @@ -983,6 +985,7 @@ riscv_data_length (bfd_vma memaddr, static int riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED, insn_t data, + const bfd_byte *packet ATTRIBUTE_UNUSED, disassemble_info *info) { info->display_endian = info->endian; @@ -1037,7 +1040,7 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) bfd_vma dump_size; int status; enum riscv_seg_mstate mstate; - int (*riscv_disassembler) (bfd_vma, insn_t, struct disassemble_info *); + int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte*, struct disassemble_info *); if (info->disassembler_options != NULL) { @@ -1081,7 +1084,7 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) } insn = (insn_t) bfd_get_bits (packet, dump_size * 8, false); - return (*riscv_disassembler) (memaddr, insn, info); + return (*riscv_disassembler) (memaddr, insn, packet, info); } disassembler_ftype