From nobody Fri Apr 4 03:50:00 2025 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1742371576; cv=none; d=zohomail.com; s=zohoarc; b=S1PNFRMqEXDUC6X778gi8WClYPTzf4PRZf5gHR5y8OLvgDJhpMdQaQdaysoK5z8znqnYymEeJLaVX3kWO9EHznK8K/Ake81IBieCg5ersOKMcWDxFU2WY9LW2QQMnf1RR3VROMUJpaZxYhjlgc+umsh9/le7oHql/1BMADOy0uU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742371576; h=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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IRFeyxnlx7B6/bhH6tCMKsSu+jXikzi9UZmWl9GXpsY=; b=SiX/nkUzhFpEHssjrL0VwkMgSsC6xgmhr5825lmxDmHwPEYnhM8J+rzDxN+8MQU0ZtJEGe6EF/xv2NmvYjavE6780FOgRT3FITX/+bywmuPRSF0/xLhzMhAV28mjtthfauZVC9O/ztLBItLS8laI6peWz2DTpZHx1PHu9gKxyk4= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742371575999205.05601204771403; Wed, 19 Mar 2025 01:06:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuoPj-0000Mt-2I; Wed, 19 Mar 2025 04:04:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuoP4-00085m-Jr for qemu-devel@nongnu.org; Wed, 19 Mar 2025 04:03:56 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tuoP2-0004Uc-Jz for qemu-devel@nongnu.org; Wed, 19 Mar 2025 04:03:54 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-300f92661fcso6882062a91.3 for ; Wed, 19 Mar 2025 01:03:52 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c6ba6c8dsm107725255ad.156.2025.03.19.01.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 01:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742371431; x=1742976231; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IRFeyxnlx7B6/bhH6tCMKsSu+jXikzi9UZmWl9GXpsY=; b=HR/WPBNJfx1oxTLrvnOK8BxBnNt+rSA8JkHYVw3Y/AkxBJ6KJ56yW1dTehdvUaPpS6 iE6NE7fxGEh8jTsJE2NPQzfmvO/mNfIA0ZedDv4RYKIr4jyhbVc2trKE9KUTd5C6ITnV IULT5izP/wNzFZwDPmzCi5RNAF+WYjCziQ24Hg1IKr7Q3EHa3AVM/cxQ5P4/Xbrw+UbX PxJxn9IKqApXRVu4SptTByXcxYRSZJz/vfFUVCuJARjh5qHRDSmeocEFXQiT029CoLhj zKBwktIQgd1+yrBEiER+RI1sC54FBol2pufNBVnNJ9mon9QeURG5DHwlla8ylwwOkMqz riCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742371431; x=1742976231; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IRFeyxnlx7B6/bhH6tCMKsSu+jXikzi9UZmWl9GXpsY=; b=bLlPqZ7IlV0URyP1CYU7aqPkN0UlD6Vtjbn9Hf6Xdsz71sPQ3IejZ9UhPWn7HGSPq4 flc41P8fyz/7jtuLFLBmWjklhK8aTN9KxIU5ME36P65LaaQJCYSbhjoK6apRyx7UXTGF D4Yt6T8MI3Qz0lJT3b+eFStZXOATg3GrpGOu1hs4cZ3DJPV7bY8/BwCofLE/HbTtNedM XK9zl8KIb3PnBrAURYldMVEX6fCZ3U7gopH74gmCMT58UXYmfyarg83EC28DwXCT0+kh aGaU7l4qrMxgcAafNTJP8Mahj6V34mfpmzMRpouW8AOBDLT4/LEZ+s4yDBB8rXZbQqry RqtA== X-Gm-Message-State: AOJu0YxKxoDFtVvCrl5rMMwWQNfqzjKQlixmCFDdK/Z52wd7llnqJeav hoa0zYJdpl/kiJvgX6bZxjnfepByTi3vOyGJDXE5QJC3pbCxPfFnsTcVKg== X-Gm-Gg: ASbGncvl5CWoCCBV3c6kvccDuLYpjJ2vuxQXnXTzazFO9VDELWhgTMzdGxbVAr1Y04/ CzSyOm6WaX2xDr4n58ddF5GBzmd2TZxxgyNVpUVOXzoWN7DL6oDMxxVWof4Xy+tL1i09sbML9C/ mzpOhCBQamLOgcDiPmw+P2tCmhjYVtA9915m34OIJNZpGEuWc+VGFWa/O6enl7juB7RC7gZBzMK O3nBufQpZNCNhdmiwgKlv17z+k8qpMo6EMaO05RElH6CVarqjMkFspL85tnd7QebHCvpa4ZprQ0 URk6uvY9EXBI3vCfKP53i+9bpz4NKJjSz5Lcn6SNgeWwLiPBFiLMrrPRHfWQ1bJw5PV9rdMKhew KcCBR6OL5SOMHiev9vx2Or5mIh+tWCDYTTcBt/bqCFS2seHnQ X-Google-Smtp-Source: AGHT+IHzBLNjgxLLSvuWhv1/uuaTros0JCIJbc2zJOzc5842bJYU8qY2h58gEhbs3pC6xVx9UpCVlQ== X-Received: by 2002:a17:90b:4fc4:b0:301:1c29:a1d9 with SMTP id 98e67ed59e1d1-301be0925b9mr2790860a91.21.1742371430658; Wed, 19 Mar 2025 01:03:50 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Yu-Ming Chang , Alistair Francis Subject: [PULL 10/10] target/riscv: Add check for 16-bit aligned PC for different priv versions. Date: Wed, 19 Mar 2025 18:03:08 +1000 Message-ID: <20250319080308.609520-11-alistair.francis@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250319080308.609520-1-alistair.francis@wdc.com> References: <20250319080308.609520-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=alistair23@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @gmail.com) X-ZM-MESSAGEID: 1742371579157019100 Content-Type: text/plain; charset="utf-8" From: Yu-Ming Chang For privilege version 1.12 or newer, C always implies Zca. We can only check ext_zca to allow 16-bit aligned PC addresses. For older privilege versions, we only check C. Signed-off-by: Yu-Ming Chang Reviewed-by: Alistair Francis Message-ID: <174184718265.10540.10120024221661781046-0@git.sr.ht> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 12 ++++++++++++ target/riscv/op_helper.c | 8 ++++++-- target/riscv/translate.c | 4 +++- target/riscv/insn_trans/trans_rvi.c.inc | 8 ++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7de19b4183..51e49e03de 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -765,6 +765,18 @@ static inline RISCVMXL riscv_cpu_sxl(CPURISCVState *en= v) } #endif =20 +static inline bool riscv_cpu_allow_16bit_insn(const RISCVCPUConfig *cfg, + target_long priv_ver, + uint32_t misa_ext) +{ + /* 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; + } else { + return misa_ext & RVC; + } +} + /* * Encode LMUL to lmul as follows: * LMUL vlmul lmul diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 0d4220ba93..72dc48e58d 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -279,7 +279,9 @@ target_ulong helper_sret(CPURISCVState *env) } =20 target_ulong retpc =3D env->sepc; - if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) { + if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg, + env->priv_ver, + env->misa_ext) && (retpc & 0x3)) { riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } =20 @@ -357,7 +359,9 @@ static void check_ret_from_m_mode(CPURISCVState *env, t= arget_ulong retpc, riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } =20 - if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) { + if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg, + env->priv_ver, + env->misa_ext) && (retpc & 0x3)) { riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } =20 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index eaa5d86eae..d6651f244f 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -606,7 +606,9 @@ static void gen_jal(DisasContext *ctx, int rd, target_u= long imm) TCGv succ_pc =3D dest_gpr(ctx, rd); =20 /* check misaligned: */ - if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) { + if (!riscv_cpu_allow_16bit_insn(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); diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index b55f56a5eb..b9c7160468 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -151,7 +151,9 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) tcg_gen_ext32s_tl(target_pc, target_pc); } =20 - if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) { + if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr, + ctx->priv_ver, + ctx->misa_ext)) { TCGv t0 =3D tcg_temp_new(); =20 misaligned =3D gen_new_label(); @@ -300,7 +302,9 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCG= Cond cond) =20 gen_set_label(l); /* branch taken */ =20 - if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca && + if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr, + ctx->priv_ver, + ctx->misa_ext) && (a->imm & 0x3)) { /* misaligned */ TCGv target_pc =3D tcg_temp_new(); --=20 2.48.1