From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992635; cv=none; d=zohomail.com; s=zohoarc; b=anDTNTvV8faGU+PsmnLzvIv1zdVqdXHvEMpXWtq7sFWZN0ySu7bUk4jhYU1+ktmabAt9rykB3YfxoDVchswqZRNCgpUtc1mAmpmP62fTpRR494WteBDc4JZ1YKv4VQtALyPb/ClIQsrC/4l7fqr/PIqHjfQRKtS8vsruKEOTc4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992635; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5L+7KYs5PRs6ZkFpBvhPkCxAHoPX7eUs+/JRgq5BAgg=; b=gS24774gB9KbxP4ihBLZKpcHCwnORRkRSFrCs6tjLYjxxaBn7CijZNqGFzr4LQm1jYUfU+2XiM1ueZQZa6DJ53AtHKoxJNUCSZmxouwKswnPsigDl21+lLEh8iVqbwLpZFTo6fvK2DOR2VsSgOWCwpeTTyCXUxpL5q5Y6m+s2TI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992635769146.60873537065277; Wed, 18 Nov 2026 01:03:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYr-0008J4-Ok; Wed, 18 Nov 2026 04:02:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYh-0008G3-P8; Wed, 18 Nov 2026 04:02:27 -0500 Received: from [115.124.30.113] (helo=out30-113.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-000426-Kn; Wed, 18 Nov 2026 04:02:26 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0GqhE_1794992515 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:55 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992516; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=5L+7KYs5PRs6ZkFpBvhPkCxAHoPX7eUs+/JRgq5BAgg=; b=l09gUee8yaEZRkd+5aWhvTixpwGWF6I8KPfRNA4y5eGQ98u3ZoyHW/f8yZ0v0+2wjC+B1Eo2fGuCSl1DLEXxUGdd8Sdgly/XffP39LTBBF9AulRR+BvB8p1aIgdOgxQ2sEzyUVaa/oiM6vTQU8eMiBrjgSy6D2mZ937sgXmdS5A= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R311e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033045098064; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0GqhE_1794992515; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:28 +0800 Subject: [PATCH RFC 1/8] disas/riscv: Reject incomplete instruction reads MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-1-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=1474; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=8s05OktAEJZbeNItduUsHh1R/umCaTg8A4jSnWbz1iY=; b=fmSJozOpTdQ3ZLaZ0Dr8V88VMhqS/hakXhJYXFmeIhPamGuNX5s+JR62nTEoKXpcTANIC0UvX KsisNJbxXyRCdosznoxzOW7aAc9roIPW28xCxUK/PIwn+lx4mpp5BaI X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.113 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.113; envelope-from=lyndra@linux.alibaba.com; helo=out30-113.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992637718158500 If a later parcel read fails, print_insn_riscv() decodes the available bits with the missing bits left as zero. A truncated instruction can therefore be displayed as a complete, unrelated instruction. Report every failed required read at its actual address and return -1. If the first 2-byte read fails, return -1 instead of the error code from read_memory_func(). The disassembly loops would otherwise treat the positive error code as an instruction length. Signed-off-by: TANG Tiancheng --- disas/riscv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index ca0d6e90b37321e8c2b7ec07f3ae51f0797585cc..eb4851b4cd4b14a43cc6592bd50= 11c6df53ec219 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -3510,12 +3510,8 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble= _info *info, rv_isa isa) for (n =3D 0; n < len; n +=3D 2) { status =3D (*info->read_memory_func)(memaddr + n, packet, 2, info); if (status !=3D 0) { - /* Don't fail just because we fell off the end. */ - if (n > 0) { - break; - } - (*info->memory_error_func)(status, memaddr, info); - return status; + (*info->memory_error_func)(status, memaddr + n, info); + return -1; } inst |=3D ((rv_inst) bfd_getl16(packet)) << (8 * n); if (n =3D=3D 0) { --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992632; cv=none; d=zohomail.com; s=zohoarc; b=aYBIEjFYrwaIQ93V+zeygXJ9b0ubVWo/QgoiBw4AH49oB0ZTUEokYQhJCMPFbfd7ZolimyzZA20tCnCRdv8ojfEs6MswpXgzI61q/2QleoTjKfUK2D0CoIKejxzxWq+qCaGm+Rxks4FTUGChKBglVhoUtyw9W9ihLA/KyVKi8cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992632; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CPuc4IitNHQxIm1Asdg17+hQBNpZhswNQTFjaeNZzSA=; b=GXShaMaWPWzxyFsCZSCcy2o3KSH6TxdkXMoB0GItpfcxv9kzUcgWvU1VkQq8cp35hTZA9v6uBI1BnUrMSMHQPaQXaHMDg8OHy7HxcCQrS//3+gcj0ZIZMpeFfTERtCvjceu5nwd+CpmSrfJRz3fWdG699OAoXE0o9pBVhLiL7LU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992632593373.4497301698865; Wed, 18 Nov 2026 01:03:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYr-0008Ir-HR; Wed, 18 Nov 2026 04:02:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYg-0008G1-KD; Wed, 18 Nov 2026 04:02:27 -0500 Received: from [115.124.30.110] (helo=out30-110.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-000427-4L; Wed, 18 Nov 2026 04:02:26 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0GqhO_1794992515 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:56 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992517; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=CPuc4IitNHQxIm1Asdg17+hQBNpZhswNQTFjaeNZzSA=; b=W9O/EXimMiq8mA+ZEXQLsPucKi53nNWQsOCmGTwTmqeQpO+l2skQP+Qfo//7RN60SgB3chEEom9LukrZ7u1tsGzFw5lr+vFoPwJgFUegPCfA5IEpQ2QGF23tWkJ2gA61EE/Za9BX8Dj3PR2++XQR6+HXUKjwgXRqSo831Mr0t58= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R151e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037026112; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0GqhO_1794992515; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:29 +0800 Subject: [PATCH RFC 2/8] target/riscv: Share instruction length helper MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-2-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=2775; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=fo4C3Qe0dkkrVp0HxkU905ZdgXelCU2FK4nYM3RyjPM=; b=XkozzhC7ndeLuo5oZOsotqXbUua2koXEWhLPLxMdOMX3SeHg78iLDX0/kkhnMepd+bcGmSB1F 97kTf980NtqA19Vlaod8s8Mpnp2dAK/XyZ+zpSgno+mzSIWuL0aB6Fv X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.110 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.110; envelope-from=lyndra@linux.alibaba.com; helo=out30-110.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992633830158500 The translator and built-in disassembler duplicate the 16/32-bit length rule. Move it into a shared header. Signed-off-by: TANG Tiancheng --- disas/riscv.c | 9 ++------- target/riscv/insn_length.h | 12 ++++++++++++ target/riscv/internals.h | 6 +----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index eb4851b4cd4b14a43cc6592bd5011c6df53ec219..8c9e06b46f19efd6aa9f605ccd0= bf3716fa62d44 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -21,6 +21,7 @@ #include "qemu/bitops.h" #include "disas/dis-asm.h" #include "target/riscv/cpu_cfg.h" +#include "target/riscv/insn_length.h" #include "disas/riscv.h" =20 /* Vendor extensions */ @@ -3170,12 +3171,6 @@ static bool check_constraints(rv_decode *dec, const = rvc_constraint *c) return true; } =20 -/* Same as insn_len() from target/riscv/internals.h */ -static size_t inst_length(rv_inst inst) -{ - return (inst & 3) =3D=3D 3 ? 4 : 2; -} - /* format instruction */ =20 static GString *format_inst(size_t tab, rv_decode *dec, @@ -3515,7 +3510,7 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble_= info *info, rv_isa isa) } inst |=3D ((rv_inst) bfd_getl16(packet)) << (8 * n); if (n =3D=3D 0) { - len =3D inst_length(inst); + len =3D insn_len(inst); } } =20 diff --git a/target/riscv/insn_length.h b/target/riscv/insn_length.h new file mode 100644 index 0000000000000000000000000000000000000000..bfb3af0e6358249daf464fed670= f09d7184d307b --- /dev/null +++ b/target/riscv/insn_length.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* RISC-V instruction length classification. */ + +#ifndef TARGET_RISCV_INSN_LENGTH_H +#define TARGET_RISCV_INSN_LENGTH_H + +static inline int insn_len(uint16_t first_word) +{ + return (first_word & 3) =3D=3D 3 ? 4 : 2; +} + +#endif diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 5466879a4aa541db8d6753c7e1eec8f3128a99c8..2d48abeef5dea2cb9d0e9785249= 5fed75d670ae1 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -23,6 +23,7 @@ #include "hw/core/registerfields.h" #include "fpu/softfloat-types.h" #include "target/riscv/cpu_bits.h" +#include "target/riscv/insn_length.h" =20 /* * The current MMU Modes are: @@ -259,11 +260,6 @@ static inline target_ulong adjust_addr_virt(CPURISCVSt= ate *env, return adjust_addr_body(env, addr, true); } =20 -static inline int insn_len(uint16_t first_word) -{ - return (first_word & 3) =3D=3D 3 ? 4 : 2; -} - int riscv_monitor_get_register_legacy(CPUState *cs, const char *name, int64_t *pval); =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992634; cv=none; d=zohomail.com; s=zohoarc; b=CHbWW3sofvMK5PhRDkXLDqfBdXyxESNjR6vtv6NqLPu4bb4uyNxkE44BBoTjatcdOZVH1yuLPLWalt4vw0OgwWSpoLwKBwh905CrRIklZsoi0EQym0PO5ZemRWigtaBAplzlp/21p+lWn3UDuC8xiL5FUKcx2rrzr1hwDMf53V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992634; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A0/m2QKKaKxovbzQTbRcYg1vI/4ZfgriynYbVmq0CSA=; b=gPfBTEpuqvaCaSrQHqdRCj9s4d7NNCIpGDtBalRuNjufUf8iC+10l4hsPM0fY3V++vV7ZK5w1RtG8j1Ro1H1oaM0mwuWr9kqQrtAcFJIxvBMDp4xLyqK8TC0YknYAaY72hjyf1Zz71F09obbdeUaWvSNTF3tMYlV2aNMZVIsKlo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992634782455.9272200796323; Wed, 18 Nov 2026 01:03:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYs-0008JQ-Pe; Wed, 18 Nov 2026 04:02:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYi-0008G9-0t; Wed, 18 Nov 2026 04:02:29 -0500 Received: from [115.124.30.97] (helo=out30-97.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-000429-4m; Wed, 18 Nov 2026 04:02:27 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0Gqhc_1794992516 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:56 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992517; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=A0/m2QKKaKxovbzQTbRcYg1vI/4ZfgriynYbVmq0CSA=; b=Hb85iUQsTsByXI+OVNFT0vJvomU5r8gPGPSbZdwzzSaBCsTBUB0KrYs4FeTuK9QRoAyLJ4DpAS85Z90/9I7/3kuEQUQILjJzTjFcTWrAIbyuu+LDQlNTyCSGOidR8tSgDqSJqjpB7jkrRrwws43Ke2XhZZ4ksQycqOQHjKRxIhw= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R851e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033032089153; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0Gqhc_1794992516; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:30 +0800 Subject: [PATCH RFC 3/8] target/riscv: Prepare Zl instruction alignment MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-3-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=7418; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=jpIMMq63dduIgaH8ws2nd5moybfR2Tw0edZyyB3MQCA=; b=blepyQwNB1owm4DucBTK6JoEvxX+1UTH/7oVDaPGkJImT28GWQ+0VE9VXqjpa4cTSjLrkn6Tt +iXV2AfdZWQDyOCUetVooZE/yjm1DvFijcaXG2aEygnEBzbmSoHsCm5 X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.97 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.97; envelope-from=lyndra@linux.alibaba.com; helo=out30-97.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992635784158500 Zl requires IALIGN=3D16 even when compressed instructions are disabled. Add an internal ext_zl flag and apply it to jumps, EPC/DPC masking, trap returns and misa.C writes. Keep compressed instruction decoding under its existing extension checks. Signed-off-by: TANG Tiancheng --- target/riscv/cpu.h | 10 +++++++--- target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/internals.h | 4 ++-- target/riscv/tcg/csr.c | 7 +++++-- target/riscv/tcg/insn_trans/trans_rvi.c.inc | 8 ++------ target/riscv/tcg/op_helper.c | 10 ++++------ target/riscv/tcg/translate.c | 4 +--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 49a1186bdbb2b9b56f3d9ad1e8ba18ae2010c7cb..f157a40b019a1bc23408d2a7053= 0d1b58b7278d0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -921,10 +921,14 @@ bool riscv_cpu_eff_priv(CPURISCVState *env, privilege= _mode_t *priv, bool *virt) return mode_modified; } =20 -static inline bool riscv_cpu_allow_16bit_insn(const RISCVCPUConfig *cfg, - uint32_t priv_ver, - uint32_t misa_ext) +/* Instruction alignment is independent of compressed instruction decoding= . */ +static inline bool riscv_cpu_ialign16(const RISCVCPUConfig *cfg, + uint32_t priv_ver, uint32_t misa_ext) { + if (cfg->ext_zl) { + return true; + } + /* In priv spec version 1.12 or newer, C always implies Zca */ if (priv_ver >=3D PRIV_VERSION_1_12_0) { return cfg->ext_zca; diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_field= s.h.inc index 85fc3ad8bb8ca059b4c391afde2ab14c95018145..30a8d21b7553b7d22b1ca2647dc= 00789330657f5 100644 --- a/target/riscv/cpu_cfg_fields.h.inc +++ b/target/riscv/cpu_cfg_fields.h.inc @@ -30,6 +30,7 @@ BOOL_FIELD(ext_zks) BOOL_FIELD(ext_zksed) BOOL_FIELD(ext_zksh) BOOL_FIELD(ext_zkt) +BOOL_FIELD(ext_zl) BOOL_FIELD(ext_zifencei) BOOL_FIELD(ext_zicntr) BOOL_FIELD(ext_zicsr) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 2d48abeef5dea2cb9d0e97852495fed75d670ae1..4e11888b03e0dcb050426892e17= 58d733273bf99 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -191,9 +191,9 @@ static inline target_ulong get_xepc_mask(CPURISCVState = *env) =20 /* * When IALIGN=3D32, both low bits must be zero. - * When IALIGN=3D16 (has C or Zc* extensions), only bit 0 must be zero. + * When IALIGN=3D16 (C, Zc* or Zl fetch), only bit 0 must be zero. */ - if (riscv_has_ext(env, RVC) || cpu->cfg.ext_zca || + if (cpu->cfg.ext_zl || riscv_has_ext(env, RVC) || cpu->cfg.ext_zca || cpu->cfg.ext_zcb || cpu->cfg.ext_zcd || cpu->cfg.ext_zce || cpu->cfg.ext_zcf || cpu->cfg.ext_zcmp || cpu->cfg.ext_zcmt) { return ~(target_ulong)1; diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c index af444e3e6f32f5d0b6cc86eeb530705a8bcad0e6..3972d1f4112f3ad52ae352d4c55= a2799aed0c992 100644 --- a/target/riscv/tcg/csr.c +++ b/target/riscv/tcg/csr.c @@ -2231,8 +2231,11 @@ static RISCVException write_misa(CPURISCVState *env,= int csrno, /* Mask extensions that are not supported by this hart */ val &=3D env->misa_ext_mask; =20 - /* drop write if RVC is cleared and next instruction is not aligned */ - if ((env->misa_ext & RVC) && !(val & RVC) && + /* + * Ignore writes that clear C if the next instruction is not 4-byte al= igned. + * With Zl, IALIGN remains 16 and the write need not be suppressed. + */ + if (!cpu->cfg.ext_zl && (env->misa_ext & RVC) && !(val & RVC) && (get_next_pc(env, ra) & 3) !=3D 0) { qemu_log_mask(LOG_GUEST_ERROR, "Unable to write MISA ext value " "0x%x, MISA.C disable failed\n", env->misa_ext); diff --git a/target/riscv/tcg/insn_trans/trans_rvi.c.inc b/target/riscv/tcg= /insn_trans/trans_rvi.c.inc index 4784ea1607e74eb5b0076425a732b5d3817b3482..ba5e274da3b778d564930386471= 387a36ddd63ce 100644 --- a/target/riscv/tcg/insn_trans/trans_rvi.c.inc +++ b/target/riscv/tcg/insn_trans/trans_rvi.c.inc @@ -151,9 +151,7 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) tcg_gen_ext32s_tl(target_pc, target_pc); } =20 - if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr, - ctx->priv_ver, - ctx->misa_ext)) { + if (!riscv_cpu_ialign16(ctx->cfg_ptr, ctx->priv_ver, ctx->misa_ext)) { TCGv t0 =3D tcg_temp_new(); =20 misaligned =3D gen_new_label(); @@ -302,9 +300,7 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCG= Cond cond) =20 gen_set_label(l); /* branch taken */ =20 - if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr, - ctx->priv_ver, - ctx->misa_ext) && + if (!riscv_cpu_ialign16(ctx->cfg_ptr, ctx->priv_ver, ctx->misa_ext) && (a->imm & 0x3)) { /* misaligned */ TCGv target_pc =3D tcg_temp_new(); diff --git a/target/riscv/tcg/op_helper.c b/target/riscv/tcg/op_helper.c index f9c79fe6b9006c7667acfda4865ca59fbb970d5d..0dda250203790840e0c0ed20d91= 7eeb645c61a60 100644 --- a/target/riscv/tcg/op_helper.c +++ b/target/riscv/tcg/op_helper.c @@ -318,9 +318,8 @@ target_ulong HELPER(sret)(CPURISCVState *env) } =20 target_ulong retpc =3D env->sepc & get_xepc_mask(env); - if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg, - env->priv_ver, - env->misa_ext) && (retpc & 0x3)) { + if (!riscv_cpu_ialign16(&env_archcpu(env)->cfg, env->priv_ver, + env->misa_ext) && (retpc & 0x3)) { riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } =20 @@ -395,9 +394,8 @@ static void check_ret_from_m_mode(CPURISCVState *env, t= arget_ulong retpc, riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); } =20 - if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg, - env->priv_ver, - env->misa_ext) && (retpc & 0x3)) { + if (!riscv_cpu_ialign16(&env_archcpu(env)->cfg, env->priv_ver, + env->misa_ext) && (retpc & 0x3)) { riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, ra); } =20 diff --git a/target/riscv/tcg/translate.c b/target/riscv/tcg/translate.c index 79b0f444efbd954c48c14812b0f566ace7830245..51024ee9a37df548ec27587c9b4= bb240afd1d5a5 100644 --- a/target/riscv/tcg/translate.c +++ b/target/riscv/tcg/translate.c @@ -630,9 +630,7 @@ static void gen_jal(DisasContext *ctx, int rd, target_u= long imm) TCGv succ_pc =3D dest_gpr(ctx, rd); =20 /* check misaligned: */ - if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr, - ctx->priv_ver, - ctx->misa_ext)) { + if (!riscv_cpu_ialign16(ctx->cfg_ptr, ctx->priv_ver, ctx->misa_ext)) { if ((imm & 0x3) !=3D 0) { TCGv target_pc =3D tcg_temp_new(); gen_pc_plus_diff(target_pc, ctx, imm); --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992598; cv=none; d=zohomail.com; s=zohoarc; b=ZXc4W4MIyeU5kRNy/OKwqWVqoIRAJvA4FrUOhqY+ilo/7Ar3uwkicth3jKaULAJh9lvx6WEhi/ljr+y6BXkvOiQs5pEdBcGL3WTxavaWi0Cyi+GzGzQyyTZmvTqIk0YURy3j93RTKLrcR7Uzjh9fU7QyrXUee5EpZ2sTVphGK8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992598; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XM7VH7UpAJHWcHedQn+0lNYBsTWS2/H8sd8mCGBqPrI=; b=mrPyW7r7HU4oHpPeSPgcROIXUwPc7BiJhLrECCsWWV4nxfe8cQCJojnKw4GzI/LNKfGmogsYO61Zt31d3ewKbbP3P3equk7TGQu73mZtZTMvN+zJ2lBjDZQTogvlQlQqsV3bUC+++xzBDnWq/IJK3WYv9scodtw6dKJM1uqZFCc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992598096760.71235969463; Wed, 18 Nov 2026 01:03:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYp-0008IF-DD; Wed, 18 Nov 2026 04:02:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYi-0008GY-LT; Wed, 18 Nov 2026 04:02:29 -0500 Received: from [115.124.30.111] (helo=out30-111.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-000428-3z; Wed, 18 Nov 2026 04:02:28 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0Gqhq_1794992516 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:57 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992517; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=XM7VH7UpAJHWcHedQn+0lNYBsTWS2/H8sd8mCGBqPrI=; b=PhmkXvebvIjmmptNA8+kpxAEgGOaZcJkhPL95atbwRpdWSqD8kkmoDKKsxYJssIV4fj/OLdlFzMQQPadwobudN2tPfJMXgIaEFAVTwiFgQMnW6zIM2HUeKSwIO4TE/YzIgvTrkdzcOACRP1WhsEV3mIoBXrn4p0xNWcb39nkT+4= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R151e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037026112; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0Gqhq_1794992516; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:31 +0800 Subject: [PATCH RFC 4/8] disas/riscv: Decode Zl instruction lengths MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-4-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=4851; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=ZlSrbm9uKweZufnx0DfkXjICY9/CjSCeOVXamUQOyZc=; b=ReAza96r9Cke9uBx6R6+1wNrUWVoziWO9Wwmxph+Mx14p4QqDaKGreAvEG1FgCns0gO+VoAmv ++5NfKcABjRAimMLmqR4yz/050cM6CIeIfu13+m7kWaC8qUnjiBjcv2 X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.111 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.111; envelope-from=lyndra@linux.alibaba.com; helo=out30-111.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992599504158500 The Zl draft identifies long instructions from parcel A and determines their 48/64-bit length from parcel C. Read complete 48-bit and 64-bit encodings and return their decoded lengths. The disassembler does not yet decode instruction mnemonics for these encodings, so print "unknown" rather than decoding part of a long instruction as a 16-bit or 32-bit instruction. When opcode display is enabled, also print the full encoding in hexadecimal. Link: https://github.com/riscv/riscv-long-instruction/blob/65c377a665feb29a= 4848384ad566a9873c5fd423/src/unpriv/zl.adoc Signed-off-by: TANG Tiancheng --- disas/riscv.c | 34 ++++++++++++++++++++++++++++------ disas/riscv.h | 4 ++-- target/riscv/insn_length.h | 17 +++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index 8c9e06b46f19efd6aa9f605ccd0bf3716fa62d44..d2a2b322374643dc51b3bc51775= 484da9a99e039 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -3489,17 +3489,21 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc= , rv_inst inst, return format_inst(24, &dec, op); } =20 -#define INST_FMT_2 "%04x " -#define INST_FMT_4 "%08x " +#define INST_FMT_2 "%04" PRIx64 " " +#define INST_FMT_4 "%08" PRIx64 " " +#define INST_FMT_6 "%012" PRIx64 " " +#define INST_FMT_8 "%016" PRIx64 " " =20 static int print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa is= a) { + const RISCVCPUConfig *cfg =3D info->target_info; bfd_byte packet[2]; rv_inst inst =3D 0; size_t len =3D 2; bfd_vma n; int status; + bool zl =3D cfg && cfg->ext_zl; =20 /* Instructions are made of 2-byte packets in little-endian order */ for (n =3D 0; n < len; n +=3D 2) { @@ -3510,7 +3514,15 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble= _info *info, rv_isa isa) } inst |=3D ((rv_inst) bfd_getl16(packet)) << (8 * n); if (n =3D=3D 0) { - len =3D insn_len(inst); + /* Zl needs parcel C to determine a long instruction's length.= */ + len =3D zl && riscv_insn_is_long(inst) ? 6 : insn_len(inst); + } else if (zl && n =3D=3D 4) { + len =3D riscv_zl_insn_length(inst >> 32); + } + if (len =3D=3D 0) { + (*info->fprintf_func)(info->stream, + ""); + return -1; } } =20 @@ -3522,14 +3534,24 @@ print_insn_riscv(bfd_vma memaddr, struct disassembl= e_info *info, rv_isa isa) case 4: (*info->fprintf_func)(info->stream, INST_FMT_4, inst); break; + case 6: + (*info->fprintf_func)(info->stream, INST_FMT_6, inst); + break; + case 8: + (*info->fprintf_func)(info->stream, INST_FMT_8, inst); + break; default: g_assert_not_reached(); } } =20 - g_autoptr(GString) str =3D - disasm_inst(isa, memaddr, inst, - (const RISCVCPUConfig *)info->target_info); + /* Long instruction mnemonics are not decoded yet. */ + if (len > 4) { + (*info->fprintf_func)(info->stream, "unknown"); + return len; + } + + g_autoptr(GString) str =3D disasm_inst(isa, memaddr, inst, cfg); (*info->fprintf_func)(info->stream, "%s", str->str); =20 return len; diff --git a/disas/riscv.h b/disas/riscv.h index 4f1ffc4ae02fb1e5940e833ef972f80e28603a19..b49bcadab8e4fa1f32f28e1d5ed= 9035c5b55a359 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -11,7 +11,7 @@ =20 /* types */ =20 -typedef uint32_t rv_inst; +typedef uint64_t rv_inst; typedef uint16_t rv_opcode; =20 /* enums */ @@ -184,7 +184,7 @@ struct rv_opcode_data { typedef struct { const RISCVCPUConfig *cfg; uint64_t pc; - uint64_t inst; + rv_inst inst; int32_t imm; int32_t imm1; uint8_t rd; diff --git a/target/riscv/insn_length.h b/target/riscv/insn_length.h index bfb3af0e6358249daf464fed670f09d7184d307b..14bf5c7fa98a388705e023ff7d0= d0840d1306c63 100644 --- a/target/riscv/insn_length.h +++ b/target/riscv/insn_length.h @@ -9,4 +9,21 @@ static inline int insn_len(uint16_t first_word) return (first_word & 3) =3D=3D 3 ? 4 : 2; } =20 +static inline bool riscv_insn_is_long(uint16_t first_parcel) +{ + return (first_parcel & 0x1f) =3D=3D 0x1f; +} + +/* Call only after fetching parcel C; zero means an undefined length. */ +static inline unsigned riscv_zl_insn_length(uint16_t third_parcel) +{ + if ((third_parcel & 3) !=3D 3) { + return 6; + } + if ((third_parcel & 0x1f) !=3D 0x1f) { + return 8; + } + return 0; +} + #endif --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992622; cv=none; d=zohomail.com; s=zohoarc; b=WYNbopEa97LEYV7D805dd7+4KnHj/EpLJUx/WZ6SZ+wkXIh6hXqoz4WQOgk2cpWe6HTY1NCeVJXkyngTvRR5xcayKBxIMmZZ+5fGFT9peQkoGX8VFlDm8IWBRG6y/4k96V5gHqb0igwSAKEBNgPH0pOWu9oOgT+Jn7bCBmzulRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992622; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TCgHYFytt97lFj80Wh+mfBZNQ2KuAfwkkRoDCBWdI14=; b=KuijV8CiLv0jnarsR2NSmVMweFw6I6H9d8abcp12lbQWH0OH7jtASRz+CiOzio2ZH/kzSt8fGObYF6HndxLSNHDa1IsSmqPVKDur50ql9NIymAqcvlpr6zRP1Vy9AE4DkQ0cUW+iR0syLMUzevLJebvdeF2EvDa0P13MpjLXBEQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179499262263570.98329389369712; Wed, 18 Nov 2026 01:03:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYp-0008ID-Cg; Wed, 18 Nov 2026 04:02:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYg-0008Fz-9r; Wed, 18 Nov 2026 04:02:27 -0500 Received: from [115.124.30.112] (helo=out30-112.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-00042L-54; Wed, 18 Nov 2026 04:02:26 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0Gqi4_1794992517 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:57 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992519; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=TCgHYFytt97lFj80Wh+mfBZNQ2KuAfwkkRoDCBWdI14=; b=Ytt3H9BmQFY/qclUOWfK13atdfnq9Ou4XgiXN8Q1sCjW+l7fdGRefTPnlMqYxZXXH1ZrTEY7Zll2AtNu1GNkkYOASiHDDItEoXiPL4I+pmUaEziHod7+inJPBaZMYx8bMlO8gQWtBNsPm86XhYNmeMpQensTpZw5/je2uskBPWs= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0Gqi4_1794992517; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:32 +0800 Subject: [PATCH RFC 5/8] target/riscv: Limit instruction bits to the trap CSR width MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-5-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=1465; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=hBJOMecAa8MHoBIfvxIpSEskZAi1cdxXEFqTfqRWDgk=; b=5fSfrO3ZwMaQU44G0RH0n76U9xG4u9ZtMGdzuacbkgZxetlSzVsI+5UxfGRw8u2sBPv8Xj5DW PauBIsTB6n2BSJuphZVdqCPESpFpbCh5JQcqwnGLU5v0mWVX4b5RBo/ X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.112 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.112; envelope-from=lyndra@linux.alibaba.com; helo=out30-112.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992623834158500 The instruction bits in env->bins can be wider than the destination trap CSR. Keep env->bins intact and limit the reported value to MXLEN for mtval or SXLEN for stval. Signed-off-by: TANG Tiancheng --- target/riscv/tcg/cpu_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/target/riscv/tcg/cpu_helper.c b/target/riscv/tcg/cpu_helper.c index 58e98e975c29106f39074283a79038dbad255fae..568af11d24ccdfaf953a4d27d1a= 172847a547508 100644 --- a/target/riscv/tcg/cpu_helper.c +++ b/target/riscv/tcg/cpu_helper.c @@ -2260,7 +2260,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) break; case RISCV_EXCP_ILLEGAL_INST: case RISCV_EXCP_VIRT_INSTRUCTION_FAULT: - tval =3D env->bins; + tval =3D mxlen =3D=3D 32 ? (uint32_t)env->bins : env->bins; break; case RISCV_EXCP_BREAKPOINT: tval =3D env->badaddr; @@ -2377,6 +2377,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) sxlen =3D 16 << riscv_cpu_sxl(env); env->scause =3D cause | ((target_ulong)async << (sxlen - 1)); env->sepc =3D env->pc; + if (!async && sxlen =3D=3D 32 && + (cause =3D=3D RISCV_EXCP_ILLEGAL_INST || + cause =3D=3D RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) { + tval =3D (uint32_t)tval; + } env->stval =3D tval; env->htval =3D htval; env->htinst =3D tinst; --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992632; cv=none; d=zohomail.com; s=zohoarc; b=ILO5WtVPZPhPKWpJTzeCr7SG2iVqy6vKLPt1z24ZkVw7WT9azbGeVF6Z/r/1iaStZnKAGe+JbJzdhyxxiJutjh2cjcMwJnnctlYVsbDyJeWuQcwMV5wRiGsmq1H7w2SMzYO+ENdwwSPVmkLBZTfQCRiUsItbzxLafA9o+bAQFqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992632; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zwmTj/RrGDC4hJstDrXF4lWrvPbUyb5kwAi9xLRE+/o=; b=Ab/UW6Kis93wWeCIDlP/vVsXm83f6e/EDVxOIrJeeXWtm5YJIalxtIVrLYw1dJiIpI0/5XU34MOUJ7R4DyXSH5eWv0tuPk8CEkIE5wsONfz+uoVrjfhk2RjP4P5+Mgv2EX7dRS8wI4f8bv6TV1XN+iHRFLM/zLkP0b++6MR+2xc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992632506943.6295958382437; Wed, 18 Nov 2026 01:03:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYt-0008KH-GV; Wed, 18 Nov 2026 04:02:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYh-0008G5-Pl; Wed, 18 Nov 2026 04:02:27 -0500 Received: from [115.124.30.112] (helo=out30-112.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-00042K-42; Wed, 18 Nov 2026 04:02:26 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0GqiU_1794992517 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:58 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992519; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=zwmTj/RrGDC4hJstDrXF4lWrvPbUyb5kwAi9xLRE+/o=; b=NyBgN58Gl/S8EfUfKrcd7lqmbWa0n1kMWyBWOws50NGbyNfV9tOeuaBJUWIkPEK6j520QyrTz8f/eMYYSeD/cg4VZWRHBK9rPYlLO26ldg9jjcHqUqBTZZhe7l1iWJyYorTol5daxZe85ZpIhHwg/K/lP7ihY0OpU6HwyT6X4ow= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R411e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0GqiU_1794992517; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:33 +0800 Subject: [PATCH RFC 6/8] target/riscv: Fetch 48-bit and 64-bit instructions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-6-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=8064; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=dgNNi/AxEfDMDs61yp/J0K1XFRfOSGAWZ5Uhm6hTxeY=; b=fDJ7vsiK8SSl0kvhLZn+X1TsAEtgiXR6Mpsb3786YfVBCAJ2a/aG3HeOP+iPRzsYk988VJ28M lcVSZ2Q7XHLBevRzFn0OPeWoK4IgaxX/lVHv8p75v83aKLpXnh4rCkW X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.112 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.112; envelope-from=lyndra@linux.alibaba.com; helo=out30-112.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992633776158501 Preserve the existing aligned word fetch and halfword fetch sequence. When Zl is enabled, use parcels A and C to determine the instruction length and fetch parcel D only for 64-bit encodings. Keep the complete encoding in ctx->opcode so gen_exception_illegal() can report it through env->bins. For an undefined length, stop after parcel C and set env->bins to zero. This implementation reports no instruction bits rather than fetching additional parcels solely for trap reporting. Stop translation near page ends before a subsequent instruction could require another page. Link: https://github.com/riscv/riscv-long-instruction/blob/65c377a665feb29a= 4848384ad566a9873c5fd423/src/unpriv/zl.adoc Signed-off-by: TANG Tiancheng --- target/riscv/internals.h | 7 ++++ target/riscv/tcg/translate.c | 97 ++++++++++++++++++++++++++++++++--------= ---- 2 files changed, 79 insertions(+), 25 deletions(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 4e11888b03e0dcb050426892e1758d733273bf99..ddd5ca65adc99d9538c98f4ce28= c3c723a967824 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -185,6 +185,13 @@ static inline float16 check_nanbox_bf16(CPURISCVState = *env, uint64_t f) } } =20 +/* Long encodings must already include parcel C. */ +static inline bool riscv_zl_insn_has_undefined_length(uint64_t opcode) +{ + return riscv_insn_is_long(opcode) && + riscv_zl_insn_length(opcode >> 32) =3D=3D 0; +} + static inline target_ulong get_xepc_mask(CPURISCVState *env) { RISCVCPU *cpu =3D env_archcpu(env); diff --git a/target/riscv/tcg/translate.c b/target/riscv/tcg/translate.c index 51024ee9a37df548ec27587c9b4bb240afd1d5a5..b301c41d3341dce777422a9c70a= 407818d3407bd 100644 --- a/target/riscv/tcg/translate.c +++ b/target/riscv/tcg/translate.c @@ -30,6 +30,7 @@ #include "semihosting/semihost.h" =20 #include "internals.h" +#include "insn_length.h" =20 #define HELPER_H "helper.h" #include "exec/helper-info.c.inc" @@ -64,7 +65,7 @@ typedef struct DisasContext { RISCVMXL xl; RISCVMXL address_xl; uint32_t misa_ext; - uint32_t opcode; + uint64_t opcode; RISCVExtStatus mstatus_fs; RISCVExtStatus mstatus_vs; uint32_t mem_idx; @@ -265,7 +266,11 @@ static void generate_exception(DisasContext *ctx, RISC= VException excp) =20 static void gen_exception_illegal(DisasContext *ctx) { - tcg_gen_st_i64(tcg_constant_i64(ctx->opcode), tcg_env, + uint64_t bits =3D ctx->cfg_ptr->ext_zl && + riscv_zl_insn_has_undefined_length(ctx->opcode) ? 0 : ctx->opcode; + + /* Undefined lengths have no complete instruction to report. */ + tcg_gen_st_i64(tcg_constant_i64(bits), tcg_env, offsetof(CPURISCVState, bins)); if (ctx->virt_inst_excp) { generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT); @@ -1240,8 +1245,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" =20 -/* The specification allows for longer insns, but not supported by qemu. */ -#define MAX_INSN_LEN 4 +#define MAX_INSN_LEN 8 =20 const RISCVDecoder decoder_table[] =3D { { always_true_p, decode_insn32 }, @@ -1254,12 +1258,11 @@ const RISCVDecoder decoder_table[] =3D { =20 const size_t decoder_table_size =3D ARRAY_SIZE(decoder_table); =20 -static void decode_opc(CPURISCVState *env, DisasContext *ctx) +static bool fetch_insn(CPURISCVState *env, DisasContext *ctx) { - uint32_t opcode; + uint64_t opcode; bool pc_is_4byte_align =3D ((ctx->base.pc_next % 4) =3D=3D 0); =20 - ctx->virt_inst_excp =3D false; if (pc_is_4byte_align) { /* * Load 4 bytes at once to make instruction fetch atomically. @@ -1276,42 +1279,82 @@ static void decode_opc(CPURISCVState *env, DisasCon= text *ctx) * For unaligned pc, instruction preload may trigger additional * page fault so we only load 2 bytes here. */ - opcode =3D (uint32_t) translator_lduw_end(env, &ctx->base, - ctx->base.pc_next, - MO_LE); + opcode =3D translator_lduw_end(env, &ctx->base, ctx->base.pc_next,= MO_LE); } - ctx->ol =3D ctx->xl; =20 ctx->cur_insn_len =3D insn_len((uint16_t)opcode); /* Check for compressed insn */ if (ctx->cur_insn_len =3D=3D 2) { ctx->opcode =3D (uint16_t)opcode; + return true; + } + + if (!pc_is_4byte_align) { + /* Load last 2 bytes of instruction here */ + opcode =3D deposit64(opcode, 16, 16, + translator_lduw_end(env, &ctx->base, + ctx->base.pc_next + 2, MO_L= E)); + } + ctx->opcode =3D opcode; + + if (ctx->cfg_ptr->ext_zl && riscv_insn_is_long(opcode)) { + uint16_t third_parcel =3D + translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 4, MO= _LE); + unsigned len =3D riscv_zl_insn_length(third_parcel); + + ctx->opcode =3D deposit64(ctx->opcode, 32, 16, third_parcel); + if (len =3D=3D 8) { + uint16_t fourth_parcel =3D + translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 6, + MO_LE); + + ctx->opcode =3D deposit64(ctx->opcode, 48, 16, fourth_parcel); + } + /* An undefined length stops fetching after three parcels. */ + ctx->cur_insn_len =3D len ? len : 6; + return len !=3D 0; + } + return true; +} + +static void decode_opc(CPURISCVState *env, DisasContext *ctx) +{ + bool valid_length; + + ctx->virt_inst_excp =3D false; + ctx->ol =3D ctx->xl; + valid_length =3D fetch_insn(env, ctx); + if (!valid_length) { + goto illegal; + } + + switch (ctx->cur_insn_len) { + case 2: /* * The Zca extension is added as way to refer to instructions in t= he C - * extension that do not include the floating-point loads and stor= es + * extension that do not include the floating-point loads and stor= es. */ if ((has_ext(ctx, RVC) || ctx->cfg_ptr->ext_zca) && - decode_insn16(ctx, opcode)) { + decode_insn16(ctx, (uint16_t)ctx->opcode)) { return; } - } else { - if (!pc_is_4byte_align) { - /* Load last 2 bytes of instruction here */ - opcode =3D deposit32(opcode, 16, 16, - translator_lduw_end(env, &ctx->base, - ctx->base.pc_next + 2, - MO_LE)); - } - ctx->opcode =3D opcode; - + break; + case 4: for (guint i =3D 0; i < ctx->decoders->len; ++i) { riscv_cpu_decode_fn func =3D g_ptr_array_index(ctx->decoders, = i); - if (func(ctx, opcode)) { + if (func(ctx, (uint32_t)ctx->opcode)) { return; } } + break; + case 6: + case 8: + break; + default: + g_assert_not_reached(); } =20 +illegal: gen_exception_illegal(ctx); } =20 @@ -1419,7 +1462,11 @@ static void riscv_tr_translate_insn(DisasContextBase= *dcbase, CPUState *cpu) } else { unsigned page_ofs =3D ctx->base.pc_next & ~TARGET_PAGE_MASK; =20 - if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { + if (ctx->cfg_ptr->ext_zl) { + if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { + ctx->base.is_jmp =3D DISAS_TOO_MANY; + } + } else if (page_ofs > TARGET_PAGE_SIZE - 4) { uint16_t next_insn =3D translator_lduw_end(env, &ctx->base, ctx->base.pc_next, MO_LE); --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992565; cv=none; d=zohomail.com; s=zohoarc; b=ScRO7SFwkx4JrZHfH3h3ZwzE5Y+zB857W6dZoMU3d/CiCj/HHjMZlTilYW9xmZZOg5bni7/rSCNZaK6Tc840urnUB/Et8UGkPgKvIfq28tIeddlwRppypadWxHMfW4BMj9v4RUf0fvVbs11XYzC99IGrPizMDGLWmrPD8s3+LUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992565; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cP3/j6oW9YPflp87Lv/SaZAliOwxUk+ndKs8q61FZko=; b=V+55HnDHXaxx/vdAv8fozoKMNuJBv2PbxW0Wq/Yay28tCWfc/B88oEZhs1v0nl5H0apCza7G7mTwr+bQDV4qAmoahEA7csihY9t0hqIrtvCzUr8+MgI3txk1axlGN8f3Gg7/4wXxVF2EHSKKFllPCk8GCBARDj9KAA1HYXqvddw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992565894475.4746894394324; Wed, 18 Nov 2026 01:02:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYj-0008G0-MR; Wed, 18 Nov 2026 04:02:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYe-0008Fc-NE; Wed, 18 Nov 2026 04:02:25 -0500 Received: from [115.124.30.119] (helo=out30-119.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYb-00042O-MN; Wed, 18 Nov 2026 04:02:24 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0Gqit_1794992518 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:58 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992521; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=cP3/j6oW9YPflp87Lv/SaZAliOwxUk+ndKs8q61FZko=; b=TkY26EhbO8Hpu8a7XnnbRQWFrcjW6x6LRRRljag7J+PpA/72TOuXRYN6xgeZZz0PyopwS+/OD4Y5Qgzp1INamvmyQwcA5ORjlwzs61mFmsFSmxOfH7lfUIPx89h8BUv0cy1sXDm7dksvpq2zluAEbu9VlGSMqmyU7tQJqwKQoLU= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R121e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033032089153; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0Gqit_1794992518; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:34 +0800 Subject: [PATCH RFC 7/8] target/riscv: Enable experimental Zl fetch support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-7-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=1416; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=/Z/uJRmOoyZj3Qm28G1VRL88yCnZ4qouT0wTlkXGZRw=; b=ugwJ7UNmk2cU/qNzrpHJipKl5IUuTe3vjdC2wE3rKCUtmrXzOq20vSjjNd7zO2Hq5REYkTktZ AeZto5Lc0gwDpz45VKdism/DZG3iL1SHSZ05NECUaI/RwKS5rIYjdBz X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.119 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.119; envelope-from=lyndra@linux.alibaba.com; helo=out30-119.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992567696158500 Expose the default-off x-zl property for TCG. Use the built-in disassembler when enabled because Capstone does not implement this draft's instruction lengths. Signed-off-by: TANG Tiancheng --- target/riscv/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 362e5618091483e0ef10f091cf79106fb780c57b..ce6d55cd1143b59232ca2c677b2= 8ffc2e8d6e78b 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -196,6 +196,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zfhmin, PRIV_VERSION_1_11_0, ext_zfhmin), ISA_EXT_DATA_ENTRY(zfinx, PRIV_VERSION_1_12_0, ext_zfinx), ISA_EXT_DATA_ENTRY(zdinx, PRIV_VERSION_1_12_0, ext_zdinx), + ISA_EXPERIMENTAL_EXT_DATA_ENTRY(zl, PRIV_VERSION_1_10_0, ext_zl), ISA_EXT_DATA_ENTRY(zca, PRIV_VERSION_1_12_0, ext_zca), ISA_EXT_DATA_ENTRY(zcb, PRIV_VERSION_1_12_0, ext_zcb), ISA_EXT_DATA_ENTRY(zcf, PRIV_VERSION_1_12_0, ext_zcf), @@ -1155,6 +1156,11 @@ static void riscv_cpu_disas_set_info(const CPUState = *s, disassemble_info *info) g_assert_not_reached(); } =20 + if (cpu->cfg.ext_zl) { + /* Capstone does not implement this draft's instruction lengths. */ + return; + } + info->cap_arch =3D CS_ARCH_RISCV; info->cap_insn_unit =3D 4; info->cap_insn_split =3D 4; --=20 2.43.0 From nobody Mon Nov 23 04:26:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1794992597; cv=none; d=zohomail.com; s=zohoarc; b=jgMptgFZ7W5yR/NyEQ2dv+rFIUuIqk2hrMqliP7Qt2FXN3Pt8iv1JWnT7YNvWerpw1fXjthUVx0skHIFgsaLzhHD4FkIc9k03GQ1b+IjTDjjgHxkuAr6F1JjLEKQGuofMqStAzv6aKq74zjKxA9XqPCMlGPgBzTG0aj46G+7Se4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794992597; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XHeHm4MyKKi/nzVdDi9eeXQ/fXxcSGLMC08hL8tRkQE=; b=Amj3d340BoDX91CmYxbPCDIvwdeq9b/geLqe/qCLTjXeMx+mUxnQxNsFJOBwvwrc5FT/lWciL3oaDMSlNBNoa8ooC9W8Zzc/Bilkc2IOLJr6VgOqe2Ek/6Y67zG8Ol6wf5/CORV7p1EnTFeqZQgECFSLKm5c3V2RX6VKE2Xq/XU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794992597525184.7928148003524; Wed, 18 Nov 2026 01:03:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTbYo-0008IA-Op; Wed, 18 Nov 2026 04:02:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYf-0008Ft-Qh; Wed, 18 Nov 2026 04:02:27 -0500 Received: from [115.124.30.101] (helo=out30-101.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTbYc-00042M-4x; Wed, 18 Nov 2026 04:02:24 -0500 Received: from riscv-project-v011122129236.ea134.tbsite.net(mailfrom:lyndra@linux.alibaba.com fp:SMTPD_---0XF0GqjB_1794992519 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Nov 2026 17:01:59 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1794992520; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=XHeHm4MyKKi/nzVdDi9eeXQ/fXxcSGLMC08hL8tRkQE=; b=q+PI6J/1m/wsrH7JzdAQ5ECK4fGW5kUBSjnAuxAU/D9RAq87/pz/b9BUuiY/Izx7oRSCSTY5UD5KhYJqatK3DrBFQupmrR2WC4v1nkD95y8sILBq755VWr/JENKpCCYzgAgiYDNynAmj45si6RVWAobLZguLpiLg9XDxWrYLjAE= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R951e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037026112; MF=lyndra@linux.alibaba.com; NM=1; PH=DS; RN=9; SR=0; TI=SMTPD_---0XF0GqjB_1794992519; From: TANG Tiancheng Date: Wed, 18 Nov 2026 17:01:35 +0800 Subject: [PATCH RFC 8/8] tests/tcg/riscv: Check Zl fetching and halfword alignment MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-zl-master-v1-8-129f85e0f887@linux.alibaba.com> References: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> In-Reply-To: <20261118-zl-master-v1-0-129f85e0f887@linux.alibaba.com> To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Weiwei Li , Liu Zhiwei , Chao Liu , TANG Tiancheng X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794992514; l=6163; i=lyndra@linux.alibaba.com; s=20250909; h=from:subject:message-id; bh=GdTIv6TJyvY3YpDRzfwf1R3vTW3eALq80nFWDjtTRZA=; b=3cqTpMQVhqMEA1IZNmFSaAa6DDk2C3icdxzyuOXohugWFSdvX9h4KmldP8jftbrdqfF9SExhr VMBrcsS9W2pBwzFi0yte3/c6oGjTkBRQ05wsSS/YscxQBzLZgPnOZkw X-Developer-Key: i=lyndra@linux.alibaba.com; a=ed25519; pk=GQh4uOSLVucXGkaZfEuQ956CrYS14cn1TA3N8AiIjBw= X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.101 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.101; envelope-from=lyndra@linux.alibaba.com; helo=out30-101.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1794992599401158500 Run the same bare-metal program on RV32 and RV64 with C and Zca disabled. Check complete 48/64-bit encodings and undefined lengths. Place a 48-bit encoding and an encoding with an undefined instruction length at the end of RAM to detect unnecessary reads of parcel D. Place required parcels C and D beyond the end of RAM in separate cases to check instruction access faults. Check mcause, mepc and mtval, including the failing fetch address, RV32 truncation of instruction bits, and zero for undefined lengths. Check IALIGN=3D16 for JAL, JALR, BEQ and MRET. Check that a compressed instruction remains illegal. Signed-off-by: TANG Tiancheng --- tests/tcg/riscv/zl/zl.S | 165 +++++++++++++++++++++++++++++++= ++++ tests/tcg/riscv32/system/meson.build | 9 ++ tests/tcg/riscv64/system/meson.build | 9 ++ 3 files changed, 183 insertions(+) diff --git a/tests/tcg/riscv/zl/zl.S b/tests/tcg/riscv/zl/zl.S new file mode 100644 index 0000000000000000000000000000000000000000..c289f64f1262ab240d11a96b365= b97aa5922ca54 --- /dev/null +++ b/tests/tcg/riscv/zl/zl.S @@ -0,0 +1,165 @@ +/* + * Zl lengths, required fetches and IALIGN=3D16 with C/Zca disabled. + * Run on virt with 16 MiB RAM: 0x80000000 <=3D address < 0x81000000. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + .option norvc + .option norelax + .text + .global _start + + /* s0: faulting PC; s1: cause; s2: tval; s3: resume PC. */ + .macro expect_exception cause, tval + li s1, \cause + li s2, \tval + lla s3, 1f + jr s0 +1: + .endm + +_start: + lla t0, trap_handler + csrw mtvec, t0 + csrw mie, zero + li s4, 0 + csrr t0, misa + andi t0, t0, 4 + bnez t0, failed + + /* JALR to a 48-bit candidate at RAM end; D must not be fetched. */ + li s0, 0x80fffffa + lla t0, insn48 + lhu t1, 0(t0) + sh t1, 0(s0) + lhu t1, 2(t0) + sh t1, 2(s0) + lhu t1, 4(t0) + sh t1, 4(s0) + fence.i +#if __riscv_xlen =3D=3D 64 + expect_exception 2, 0x5a692468003f +#else + expect_exception 2, 0x2468003f +#endif + + /* Undefined C still stops after A/B/C, with no instruction bits. */ + li t0, 0x5a7f + sh t0, 4(s0) + fence.i + expect_exception 2, 0 + + lla s0, insn64 +#if __riscv_xlen =3D=3D 64 + expect_exception 2, 0x9abc5a632468001f +#else + expect_exception 2, 0x2468001f +#endif + + /* A/B present, C missing: fault at the first inaccessible parcel. */ + li s0, 0x80fffffc + li t0, 0x2468003f + sw t0, 0(s0) + fence.i + expect_exception 1, 0x81000000 + + /* A/B/C present, D missing; C requests eight bytes. */ + li s0, 0x80fffffa + lla t0, insn64 + lhu t1, 0(t0) + sh t1, 0(s0) + lhu t1, 2(t0) + sh t1, 2(s0) + lhu t1, 4(t0) + sh t1, 4(s0) + fence.i + expect_exception 1, 0x81000000 + + /* JAL and a word-aligned BEQ must reach halfword targets. */ + jal zero, half_jal + j failed + .balign 4, 0 + .2byte 0 +half_jal: + j branch_entry + .balign 4, 0 +branch_entry: + beq zero, zero, half_branch + j failed + .balign 4, 0 + .2byte 0 +half_branch: + lla t0, half_return + andi t1, t0, 3 + li t2, 2 + bne t1, t2, failed + csrw mepc, t0 + csrr t1, mepc + bne t0, t1, failed + li t1, 0x1800 + csrs mstatus, t1 + mret + .balign 4, 0 + .2byte 0 +half_return: + lla s0, compressed + expect_exception 2, 1 + li t0, 6 + bne s4, t0, failed + j passed + + .balign 4, 0 +trap_handler: + csrr t0, mcause + bne t0, s1, failed + csrr t0, mepc + bne t0, s0, failed + csrr t0, mtval + bne t0, s2, failed + addi s4, s4, 1 + csrw mepc, s3 + mret + + /* A alone would select the opposite length under the old encoding. */ +insn48: + .2byte 0x003f, 0x2468, 0x5a69 +insn64: + .2byte 0x001f, 0x2468, 0x5a63, 0x9abc +compressed: + .2byte 0x0001, 0 + + .balign 4, 0 +passed: + li a0, 4 + lla a1, pass + .balign 16 + slli zero, zero, 31 + ebreak + srai zero, zero, 7 + li a0, 0 + j exit +failed: + li a0, 1 +exit: + lla a1, semiargs +#if __riscv_xlen =3D=3D 64 + sd a0, 8(a1) +#else + sw a0, 4(a1) +#endif + li a0, 0x20 + .balign 16 + slli zero, zero, 31 + ebreak + srai zero, zero, 7 + j . + + .data + .balign 8 +semiargs: +#if __riscv_xlen =3D=3D 64 + .dword 0x20026, 0 +#else + .word 0x20026, 0 +#endif +pass: + .asciz "Zl PASS\n" diff --git a/tests/tcg/riscv32/system/meson.build b/tests/tcg/riscv32/syste= m/meson.build index 117ae6fbce4a0e26fea242a2a86fc7f6ecb448a4..b36047a6240f5afa3dc22817fed= 12b979427f50f 100644 --- a/tests/tcg/riscv32/system/meson.build +++ b/tests/tcg/riscv32/system/meson.build @@ -22,6 +22,15 @@ tests +=3D { }, } =20 +tests +=3D { + '../riscv/zl/zl.S': { + 'cflags': cflags + ['-march=3Drv32i_zicsr_zifencei'], + 'qemu_args': ['-M', 'virt', '-m', '16M', '-bios', 'none', '-display', = 'none', + '-serial', 'none', '-monitor', 'none', '-semihosting', + '-cpu', 'rv32,x-zl=3Dtrue,c=3Dfalse,zca=3Dfalse', '-kern= el'], + }, +} + if 'qemu-system-riscv32' in emulators tcg_tests +=3D { 'riscv32-softmmu': { diff --git a/tests/tcg/riscv64/system/meson.build b/tests/tcg/riscv64/syste= m/meson.build index 3c8b018d9e98e0b5498952d2b50b48894c99c377..0b5a6db4a4926d342c6e6134907= 31fb7a663fb5c 100644 --- a/tests/tcg/riscv64/system/meson.build +++ b/tests/tcg/riscv64/system/meson.build @@ -89,6 +89,15 @@ tests +=3D { } } =20 +tests +=3D { + '../riscv/zl/zl.S': { + 'cflags': cflags + ['-march=3Drv64i_zicsr_zifencei', '-mabi=3Dlp64'], + 'qemu_args': ['-M', 'virt', '-m', '16M', '-bios', 'none', '-display', = 'none', + '-serial', 'none', '-monitor', 'none', '-semihosting', + '-cpu', 'rv64,x-zl=3Dtrue,c=3Dfalse,zca=3Dfalse', '-kern= el'], + }, +} + if 'qemu-system-riscv64' in emulators tcg_tests +=3D { 'riscv64-softmmu': { --=20 2.43.0