From patchwork Thu Oct 6 09:56:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 1776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp226399wrs; Thu, 6 Oct 2022 02:56:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6kXACjBm5dzmTWZOJ4uBNGd2AS39s1IpoEXcJMPdSM9i7yJdqKbvW975jnC6qjMCGcXRMp X-Received: by 2002:a17:907:e9f:b0:78d:3bab:e5df with SMTP id ho31-20020a1709070e9f00b0078d3babe5dfmr3323767ejc.65.1665050217634; Thu, 06 Oct 2022 02:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665050217; cv=none; d=google.com; s=arc-20160816; b=DTd6F9PHfP50WOQW0ZnFXrwc2Zj1Zq9AYLnT0OFxBDSAuGdsKVlRxxu92wah33dnFj auiq0LNq/EkMsk6ZhEFlCGwGXCxcgdmxTOAssDpe30ENuwJGEU5q+xJKH7KlT6oRgsRU TPbhiR+I+8IQpwoW/X2L/NwfmNBGzgipHa0t2N4RZjnutK0OM5sr/Wuiz48SsS6EB/Bp HwCI2WsBiMjKztY3terUk2thVV4uNHTIeU9Kfi8xcHjIDlgXUpKsBHnWUqSh5/HakWDh h6kVh4mhQ9hRFdO9ruB9IAhc+Ua5Xe0IGkmU1+Z2SfdgpYNFI/gGG/XUxVEvWk21IMuY 5dhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=1C1v2VA1s9Z0h0XEHh5iunC0k8IzNO4SWx8cSZo//+k=; b=COa5qeHhFUls41lhEOrm9WVgzjyKChYim+pvdNq2GfchpYe+FWYSV+lJKfKZWJhprv b48Itoiy0o+mcPU4CHnpbS8myW7SMZ5hdgSYY4dHz+OrVCyUxx6+RMjW28caGw/NxlMh 9v8P93CHtjVWhTKSlOURwnuqhLbhV8K99oBuhdAbv8oCguPgy68Rd4rOj79DvGSqQJwK Ul50ZNJ1rhr17Iqt6aeK9moEhctZlOHv9WwMnrn3QFyjK5pVuut9m8IE542eSDlFxVOj xt89zYgxFIACDEZWCeh2q1oF9B+Yiqe56f3JxVUjPwbjPxDo5V1Wd61z45BBFbUUJ0SK aO0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Nixziy5X; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s12-20020a05640217cc00b00458d2bdcb30si11663164edy.96.2022.10.06.02.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 02:56:57 -0700 (PDT) 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; dkim=pass header.i=@sourceware.org header.s=default header.b=Nixziy5X; 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=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 5B142384BC3A for ; Thu, 6 Oct 2022 09:56:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B142384BC3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665050216; bh=1C1v2VA1s9Z0h0XEHh5iunC0k8IzNO4SWx8cSZo//+k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Nixziy5XPZJyyjfEzCsfwDxSRujXAVP5gz8suz+DaFanFLdhC7ckk2uAGC+XsqAbb RGNt6hsbhrzRAGrzS/zHK7rmX0qUbz83P8zgmdNSSXtiHmsS4hQ9EP5wkXcBRP2t/j gPYCF9Xyn1FKTSszrxYdfMQOgUnbfNZIWKb6gfv8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id CA0EA384D15E for ; Thu, 6 Oct 2022 09:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA0EA384D15E Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 275A9300089; Thu, 6 Oct 2022 09:56:45 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Subject: [PATCH v3 1/2] RISC-V: Fallback for instructions longer than 64b Date: Thu, 6 Oct 2022 09:56:30 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 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 Cc: binutils@sourceware.org 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?1745911805079942387?= X-GMAIL-MSGID: =?utf-8?q?1745931697090394723?= We don't support instructions longer than 64-bits yet. Still, we can modify validate_riscv_insn function to prevent unexpected behavior by limiting the "length" of an instruction to 64-bit (or less). gas/ChangeLog: * config/tc-riscv.c (validate_riscv_insn): Fix function description comment based on current spec. Limit instruction length up to 64-bit for now. Make sure that required_bits does not corrupt even if unsigned long long is longer than 64-bit. --- gas/config/tc-riscv.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 22385d1baa0..41d6dfc6062 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -1109,7 +1109,8 @@ arg_lookup (char **s, const char *const *array, size_t size, unsigned *regnop) /* For consistency checking, verify that all bits are specified either by the match/mask part of the instruction definition, or by the - operand list. The `length` could be 0, 4 or 8, 0 for auto detection. */ + operand list. The `length` could be the actual instruction length or + 0 for auto-detection. */ static bool validate_riscv_insn (const struct riscv_opcode *opc, int length) @@ -1120,11 +1121,13 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length) insn_t required_bits; if (length == 0) - insn_width = 8 * riscv_insn_length (opc->match); - else - insn_width = 8 * length; + length = riscv_insn_length (opc->match); + /* We don't support instructions longer than 64-bits yet. */ + if (length > 8) + length = 8; + insn_width = 8 * length; - required_bits = ~0ULL >> (64 - insn_width); + required_bits = ((insn_t)~0ULL) >> (64 - insn_width); if ((used_bits & opc->match) != (opc->match & required_bits)) { From patchwork Thu Oct 6 09:56:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 1777 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp226462wrs; Thu, 6 Oct 2022 02:57:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6s95zaqx5CSGWRT52dwTflUODHbiHmTlO2KbkKr94NmSwz8g6JZxNINwPrXkfOz0bUwiJN X-Received: by 2002:a05:6402:2b85:b0:457:6216:d251 with SMTP id fj5-20020a0564022b8500b004576216d251mr3905901edb.56.1665050231563; Thu, 06 Oct 2022 02:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665050231; cv=none; d=google.com; s=arc-20160816; b=chuqvw+VibbYMUDPV11OL836whlgtZBIgMsU6s58Oxb9A/HrqqpmDTQiNQXnXPIXgh iI6i7Alo0F5NXo1PDzb0NQIexpDwjvyQlhxinP5WiLElvFK93/dGoi+GMUBObics6Jfj rWwxkPpo8tbxGj4xsEYbhqW6Z3IJmqZnyQEv8lnG1WjPz3smVEz6Hf+6DgoPenblUDuu FdXyEAl/twY7vKBatsaG8ualJSEZOYAKCvtaMzkAXdtreqNY6wP/ObSzQ7+op6956JMv aDesrXW9msBobgYt8oTu1WdrTZLIkrD/sKY/Q5VPOTwJ4W2OZP7XXjHVlomi8N1uoAEd y6Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=fFeX2GXLp5IX1DPxkKJfYsrCvYhHdsEUUjwoXuMUefI=; b=OED3K/PxEZC6DTrjKWeWbIz/KJbezvM6au2PC0edyiVVg6onR/p9rwJ4go2T8IadcC Yqf9y0iu6OxttXUEa2y+u5EMPl9dsbn7hteQELPOaNz0fhOG7hjX+jOcgZAtLmCbMxwy yWhbibdwuyI0vpng9f6cXGeabnbEM93/sNScLFE9dMfwJpK3wzGdDSR+1i08YxJFsIFW whZB3EXq7buAjGs26Yg0ShTMJxLJVWB+mAdvBOiD/OtNIXQplmMvMh82ET3JDHtxJ+Lj jzvgGgu1N8xslaxR1BQ14FX3evi1oSLPpn9y0byKKXdcFYPdn6T/chR/iLHtfOjm55GM izRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=n4OAGHGJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qf12-20020a1709077f0c00b0078334ccc570si17034319ejc.328.2022.10.06.02.57.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 02:57:11 -0700 (PDT) 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; dkim=pass header.i=@sourceware.org header.s=default header.b=n4OAGHGJ; 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=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 A99E9383FB99 for ; Thu, 6 Oct 2022 09:57:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A99E9383FB99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665050226; bh=fFeX2GXLp5IX1DPxkKJfYsrCvYhHdsEUUjwoXuMUefI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=n4OAGHGJTO6VZTUg2NXKP0AFBj9s8ZTZEJReYMj9aN++4OkNLHC4gxLDnS7zoL1tw kA5/6OdYiLEkwDwoXPCqxndEFV3yVfvITLzI04tYW9DXjBy61KHFcMO1PLq7wk0SQB iboPBPAD+B2uUZ1kPfbMHrvAF2w3ylQzpACkXNJM= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 4D444384B82F for ; Thu, 6 Oct 2022 09:56:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D444384B82F Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 9FED0300089; Thu, 6 Oct 2022 09:56:55 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Subject: [PATCH v3 2/2] RISC-V: Improve "bits undefined" diagnostics Date: Thu, 6 Oct 2022 09:56:31 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 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 Cc: binutils@sourceware.org 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?1745911799964221706?= X-GMAIL-MSGID: =?utf-8?q?1745931711413666504?= This commit improves internal error message "internal: bad RISC-V opcode (bits 0x%lx undefined): %s %s" to display actual unused bits (excluding non-instruction bits). gas/ChangeLog: * config/tc-riscv.c (validate_riscv_insn): Exclude non- instruction bits from displaying internal diagnostics. Change error message slightly. --- gas/config/tc-riscv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 41d6dfc6062..dacfe0f1d25 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -1313,8 +1313,8 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length) if (used_bits != required_bits) { as_bad (_("internal: bad RISC-V opcode " - "(bits 0x%lx undefined): %s %s"), - ~(unsigned long)(used_bits & required_bits), + "(bits %#llx undefined or invalid): %s %s"), + (unsigned long long)(used_bits ^ required_bits), opc->name, opc->args); return false; }