From nobody Mon May 6 00:02:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290484; cv=none; d=zohomail.com; s=zohoarc; b=bx4aHI38U/LSF8yVmyy9JBQBzwgck+O1MRbYLDFjN49vDq6FAiHVP9ffPWWq+dHyiJT1WcQFMskdgyImCyvBRq7yVzvSfO2VwTZBRwTywEG3NSU5Tl8DsJ2/KrANwZ0Wi4TJQSp768bu8sOzA2GRzzwu4rtk16Tb0pOl/rlwZlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290484; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0uFP/4oZJWV6gMtY2Vk1JIc3xSjWv9QRgHyg1t8UV38=; b=lLNIcsmGKYx1Yv2hSB5DG1zt2pN1zuQOaTYSo7VqWpG79xBCdubLol2RkSLeGTDJ1F8AWzxPaqi1hgzDNMPQLfXaC2mrnk7McBC/epsTYJswvJ8R+oggso5sAkXlBexEZzu1xxWFI5PIO+/6Aoz4Vxhi5dLZg3ctzm9pC/A5IAw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617290484298192.27965822324052; Thu, 1 Apr 2021 08:21:24 -0700 (PDT) Received: from localhost ([::1]:38934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRz8N-0008Tk-4Y for importer@patchew.org; Thu, 01 Apr 2021 11:21:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6u-0006rX-Qv; Thu, 01 Apr 2021 11:19:52 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:23952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6s-0004bc-Sl; Thu, 01 Apr 2021 11:19:52 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:19:21 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:01:01 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip01.wdc.com with ESMTP; 01 Apr 2021 08:19:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290390; x=1648826390; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zoHC4AzVEMXtlU03lfldjp69ztUi/A9eWdMTD404NeU=; b=S4aY87QLEFy3V5eP0NmyU1QlUA/r+fuR+RDTKli/5Zewrn/YtynXN0Hb eWeTve9M/6fmGzwLyjIP0ahNDgNw0Mbre9eEvOs+eDCdBE9mxEEARpAyV 4f9ajgn5yEk24bInTxfrN0WPSkEe+6QifHsRhDfc9NIEsDKH58LvaCc99 4j9lTnEqfiBharDR1tEgU+pQR3FwH9YphgsruWg1cVBu2ZY3zvzM36Lbh oteZLT2jDKhDEAaY5Qa5Njp/Q5vN7gLk8YRPa6C3PqvNxSlK/8YOpzlez LHUWn5Jkl0qhJelJ78QCt6bbltwpQwvQi4IhH0Z0XwMTJwKY4Vq1th5zv w==; IronPort-SDR: ZFzMLAEKriHE9fQTDZiWq3B287xbzGiQ70A7VdEbZ3wilRHToTX5SPPuaNMalMOAgCPuzz1v8+ gpAjepoujJkMUhnQWLTOQiaZuJlHMOZ+fFvivyq7baI4OgjpIf9p837NnJ6xKTUm3DG4PxG3RZ qsqX/13AhAmXTv9apNUTIqyKE/B6xP67OPOI5Z5f45eKoAD1h2MMi4eTEv9V0im00dVtJzslyR jU0xJmTp78ZkpNuj2GDxJD41r/OHQoIOKJDMp8IqWs7gjx02Ae1Pg1u11y4heEdv5BMA5j8uGZ fUs= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="163455419" IronPort-SDR: wbLkO5XoO534lhqxUeQTR53Gxpaa1A9n/HUZ3JF+i1LzwmCfUeSZjlMx5ULdXv7it42J+GCsRL COXToohO940gbZUx3Rfq2mYs9ehwuY5X/lt98oIme6TXRLQtu9wlasyhBcpFUashi5JrTEbOMB h6DfvVxE3se61GbjBY81Ls/NUNbPQ1GeX5TxqdmkYf1i124+XjpfnnnMGejRTWEs1dnv7KiJb5 aGG4p/9QHxxOhDBgHbegR6FFbmM5N6HY4lF6k/ra2cMH8O+Bqa3aED55avBpgSRsC1ER56y9OE mr3okU6MKmUl3redLLlsjyHK IronPort-SDR: uj2lWVMIvUualg/MLCKa7i/JHtBeNyG5W5Kf8LhFlqhKsX43zpM8DPQNJZtNwug4afXffSv0nK ZIXebYDb8ZVtwA1SewuV5/eK83o/9xjwY3LrDHm5HBwXbJInc5CQSTh7xh/HN8Hj2XDGfjd8wy SBGeZgPo7XBBIccK8RRLpXJ54rd//HbHEwt9+FJUD0s6bJanaFlsX5J0lJ6XkQf4B28piDbMkE jQ2whrKhvkZ3M1OHe8RaEztO0eV7eJ/op+BhGAghUKCT8z5E4h3e2ViNprhiSzz1dDcuMRWxn+ crg= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 1/5] target/riscv: Convert the RISC-V exceptions to an enum Date: Thu, 1 Apr 2021 11:17:29 -0400 Message-Id: X-Mailer: git-send-email 2.31.0 In-Reply-To: References: 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=216.71.154.42; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu_bits.h | 44 ++++++++++++++++++++------------------- target/riscv/cpu.c | 2 +- target/riscv/cpu_helper.c | 4 ++-- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index caf4599207..f9ff932e85 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -527,27 +527,29 @@ #define DEFAULT_RSTVEC 0x1000 =20 /* Exception causes */ -#define EXCP_NONE -1 /* sentinel value */ -#define RISCV_EXCP_INST_ADDR_MIS 0x0 -#define RISCV_EXCP_INST_ACCESS_FAULT 0x1 -#define RISCV_EXCP_ILLEGAL_INST 0x2 -#define RISCV_EXCP_BREAKPOINT 0x3 -#define RISCV_EXCP_LOAD_ADDR_MIS 0x4 -#define RISCV_EXCP_LOAD_ACCESS_FAULT 0x5 -#define RISCV_EXCP_STORE_AMO_ADDR_MIS 0x6 -#define RISCV_EXCP_STORE_AMO_ACCESS_FAULT 0x7 -#define RISCV_EXCP_U_ECALL 0x8 -#define RISCV_EXCP_S_ECALL 0x9 -#define RISCV_EXCP_VS_ECALL 0xa -#define RISCV_EXCP_M_ECALL 0xb -#define RISCV_EXCP_INST_PAGE_FAULT 0xc /* since: priv-1.10.0= */ -#define RISCV_EXCP_LOAD_PAGE_FAULT 0xd /* since: priv-1.10.0= */ -#define RISCV_EXCP_STORE_PAGE_FAULT 0xf /* since: priv-1.10.0= */ -#define RISCV_EXCP_SEMIHOST 0x10 -#define RISCV_EXCP_INST_GUEST_PAGE_FAULT 0x14 -#define RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT 0x15 -#define RISCV_EXCP_VIRT_INSTRUCTION_FAULT 0x16 -#define RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT 0x17 +typedef enum RISCVException { + RISCV_EXCP_NONE =3D -1, /* sentinel value */ + RISCV_EXCP_INST_ADDR_MIS =3D 0x0, + RISCV_EXCP_INST_ACCESS_FAULT =3D 0x1, + RISCV_EXCP_ILLEGAL_INST =3D 0x2, + RISCV_EXCP_BREAKPOINT =3D 0x3, + RISCV_EXCP_LOAD_ADDR_MIS =3D 0x4, + RISCV_EXCP_LOAD_ACCESS_FAULT =3D 0x5, + RISCV_EXCP_STORE_AMO_ADDR_MIS =3D 0x6, + RISCV_EXCP_STORE_AMO_ACCESS_FAULT =3D 0x7, + RISCV_EXCP_U_ECALL =3D 0x8, + RISCV_EXCP_S_ECALL =3D 0x9, + RISCV_EXCP_VS_ECALL =3D 0xa, + RISCV_EXCP_M_ECALL =3D 0xb, + RISCV_EXCP_INST_PAGE_FAULT =3D 0xc, /* since: priv-1.10.0 */ + RISCV_EXCP_LOAD_PAGE_FAULT =3D 0xd, /* since: priv-1.10.0 */ + RISCV_EXCP_STORE_PAGE_FAULT =3D 0xf, /* since: priv-1.10.0 */ + RISCV_EXCP_SEMIHOST =3D 0x10, + RISCV_EXCP_INST_GUEST_PAGE_FAULT =3D 0x14, + RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT =3D 0x15, + RISCV_EXCP_VIRT_INSTRUCTION_FAULT =3D 0x16, + RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT =3D 0x17, +} RISCVException; =20 #define RISCV_EXCP_INT_FLAG 0x80000000 #define RISCV_EXCP_INT_MASK 0x7fffffff diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7d6ed80f6b..500c9595bc 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -358,7 +358,7 @@ static void riscv_cpu_reset(DeviceState *dev) env->pc =3D env->resetvec; env->two_stage_lookup =3D false; #endif - cs->exception_index =3D EXCP_NONE; + cs->exception_index =3D RISCV_EXCP_NONE; env->load_res =3D -1; set_default_nan_mode(1, &env->fp_status); } diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 21c54ef561..be7aaa0965 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -72,7 +72,7 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env) if (irqs) { return ctz64(irqs); /* since non-zero */ } else { - return EXCP_NONE; /* indicates no pending interrupt */ + return RISCV_EXCP_NONE; /* indicates no pending interrupt */ } } #endif @@ -1069,5 +1069,5 @@ void riscv_cpu_do_interrupt(CPUState *cs) =20 env->two_stage_lookup =3D false; #endif - cs->exception_index =3D EXCP_NONE; /* mark handled to qemu */ + cs->exception_index =3D RISCV_EXCP_NONE; /* mark handled to qemu */ } --=20 2.31.0 From nobody Mon May 6 00:02:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290595; cv=none; d=zohomail.com; s=zohoarc; b=mhkg8v9A5LQ240hKGH2unkuUOeiFPkcGy5rKMnoAmDzfrVLZgv3RJ6n9WJ0jkgS7fzK0D6hY11KBiiRmtFarIig5+fxCs1BoK8yIhPYdd3siTXd06Tcx3kfPnLvtBujaSo2jZ+7f1DPVQjmUav3jgIohNSiEU/Bl/gW03MHfUw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290595; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WQLodL5MMDL7uI+H7/QAqm84avWCN7yWWuCgQLuQ+nk=; b=TmJkKkyy8iz+qtFU7Ud9ftHaRrRZ+SWIsVZ/fuhzH7I7oGkGNtocZh+2WcGmKw+tuvtUbZDRg+QjDLv1/MNaIXLbTjXu3/ddU5XODHp9RqRlriChORms8oS/JMtx8XGLNXa5r2ngpYZGe3L/pSNVzD4b+aJvORFIwD+DLxB1yHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617290595395127.76082548763566; Thu, 1 Apr 2021 08:23:15 -0700 (PDT) Received: from localhost ([::1]:44890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRzAA-0002fe-AM for importer@patchew.org; Thu, 01 Apr 2021 11:23:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6z-0006zx-4U; Thu, 01 Apr 2021 11:19:57 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:23965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6x-0004jK-1X; Thu, 01 Apr 2021 11:19:56 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:19:30 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:01:10 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip01.wdc.com with ESMTP; 01 Apr 2021 08:19:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290394; x=1648826394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dqwAJfuA1e/RYG4bU1etDZREYvBWEd7y8YmBWf0vHrM=; b=a9BG5EFtb5SeLSpz70l5xsV35nwm+7JGIqWOZTigMKyFsHFHTC3QwMZL xrygj9FG1MrKRU81CQeDEY9/w71AJ5Uml7cPz+VI/IG/Cm7LOMIL+3Y2U LIFqypYMHo+ETms/TbVMq9WYpN6V71+i7fgbOzDhmQk9T/yBxwn1PZ1Sk HJvABIQxShKFKny+1HyrrZP9UKd+765NLD/3E4YSTH3pCbuaAxaqpWZ5L mBt4N5yqtyv/QEsvbbPXyIE5bEMKzmx43BjjLHqWJXmjXp7ktpzJO6rTG 9MtjJv787JGROlSdj85P1JwrWl1QybiTYUJ/cIezdx+9qqYTmGkl0B70o Q==; IronPort-SDR: 0VdhvplYewhVYIVskOg80y0Ze61/F3DDcphblMoXgzCMG0ALh4o7xJWhZ5W/UqUOUH+i+oL09C 7W09GYOnaBibOTh+SruvsSDeRi3zCDTbd7Tz/HlZpxuHvjxCke/1YjzAIXTKD7jhot2BLwzQO4 ZIJGs2T8CJzM1Hvl1lxU1t8etQ9hKw+so8Ll7fWSgL5HrhaC1owo6cl+r6XIIeZdEzXlVcPITG l3woWzFMvvp8MZuch83KGB1izLgLSQur45a1ZpvGR2HXLrP59Utnavcrt+OPIbVA5bgE6k4NZl 9Jw= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="163455429" IronPort-SDR: Y8iy4SEk2pBx2k24kfovtrDt80z/RtTkDtjur8lW4DxU+OjYUgxTYe8ZQYrJTKlFis+wbABt1K d0mUaWfW9mZ7gCjb1D8X1/ajLbQJeI6NON98BTojrJu5QXUNJw9CH9fvVCUUbfZKSTOGILbKzC pFXkVlRzsAtNPtXxvASHYJepzkPvIQ+cZOFZ0gy7Wmkjn8gmvyaiZg3ynJuKshvZ0j9kU9ate3 8sujqiqXSKGg+FDCksCCf7wCJScGVyVFCpk2GgMFrUTRY78UrdI9LlEqPTGKVZfLrtzGD6G/E8 eghBGKstEsPezysg+nwRXgEZ IronPort-SDR: VRFgSuaY0KF1+9VoJboOvT3CstsMtNDemuCkw4KvUm74Zp8fFkmhMaAvb/GA3SzHH7S9hgW3KU Db8y3zIJkSc8xd+QmWItHBz9Z3oGMAImJnOXBBpIx5c2Nhk5bdorT10mMVbingUBOdfsQhwdRB CdnO0jV/28nPlizF8yA6qO72dfzMEHBF9gS0vB0NBs0K+4kR6/22bhpx1aNmPO46CW6wthw5jG jYRH1JxxjlqCcdSTaGsX2JlZ7xo3z67BTlT3MDKksTDan0iekXfvBzwSKcgcyAOluZ97oMGuR+ XFU= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 2/5] target/riscv: Use the RISCVException enum for CSR predicates Date: Thu, 1 Apr 2021 11:17:39 -0400 Message-Id: <187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: 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=216.71.154.42; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 3 +- target/riscv/csr.c | 80 +++++++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0a33d387ba..1291ddc381 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -473,7 +473,8 @@ static inline target_ulong riscv_csr_read(CPURISCVState= *env, int csrno) return val; } =20 -typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); +typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, + int csrno); typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, target_ulong *ret_value); typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d2585395bf..5dc2aa9845 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -35,29 +35,29 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations = *ops) } =20 /* Predicates */ -static int fs(CPURISCVState *env, int csrno) +static RISCVException fs(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) /* loose check condition for fcsr in vector extension */ if ((csrno =3D=3D CSR_FCSR) && (env->misa & RVV)) { - return 0; + return RISCV_EXCP_NONE; } if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif - return 0; + return RISCV_EXCP_NONE; } =20 -static int vs(CPURISCVState *env, int csrno) +static RISCVException vs(CPURISCVState *env, int csrno) { if (env->misa & RVV) { - return 0; + return RISCV_EXCP_NONE; } - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int ctr(CPURISCVState *env, int csrno) +static RISCVException ctr(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) CPUState *cs =3D env_cpu(env); @@ -65,7 +65,7 @@ static int ctr(CPURISCVState *env, int csrno) =20 if (!cpu->cfg.ext_counters) { /* The Counters extensions is not enabled */ - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 if (riscv_cpu_virt_enabled(env)) { @@ -73,25 +73,25 @@ static int ctr(CPURISCVState *env, int csrno) case CSR_CYCLE: if (!get_field(env->hcounteren, HCOUNTEREN_CY) && get_field(env->mcounteren, HCOUNTEREN_CY)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_TIME: if (!get_field(env->hcounteren, HCOUNTEREN_TM) && get_field(env->mcounteren, HCOUNTEREN_TM)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_INSTRET: if (!get_field(env->hcounteren, HCOUNTEREN_IR) && get_field(env->mcounteren, HCOUNTEREN_IR)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)= ) && get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))= ) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; } @@ -100,93 +100,101 @@ static int ctr(CPURISCVState *env, int csrno) case CSR_CYCLEH: if (!get_field(env->hcounteren, HCOUNTEREN_CY) && get_field(env->mcounteren, HCOUNTEREN_CY)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_TIMEH: if (!get_field(env->hcounteren, HCOUNTEREN_TM) && get_field(env->mcounteren, HCOUNTEREN_TM)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_INSTRETH: if (!get_field(env->hcounteren, HCOUNTEREN_IR) && get_field(env->mcounteren, HCOUNTEREN_IR)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNT= ER3H)) && get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTE= R3H))) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; } } } #endif - return 0; + return RISCV_EXCP_NONE; } =20 -static int ctr32(CPURISCVState *env, int csrno) +static RISCVException ctr32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 return ctr(env, csrno); } =20 #if !defined(CONFIG_USER_ONLY) -static int any(CPURISCVState *env, int csrno) +static RISCVException any(CPURISCVState *env, int csrno) { - return 0; + return RISCV_EXCP_NONE; } =20 -static int any32(CPURISCVState *env, int csrno) +static RISCVException any32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 return any(env, csrno); =20 } =20 -static int smode(CPURISCVState *env, int csrno) +static RISCVException smode(CPURISCVState *env, int csrno) { - return -!riscv_has_ext(env, RVS); + if (riscv_has_ext(env, RVS)) { + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int hmode(CPURISCVState *env, int csrno) +static RISCVException hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS) && riscv_has_ext(env, RVH)) { /* Hypervisor extension is supported */ if ((env->priv =3D=3D PRV_S && !riscv_cpu_virt_enabled(env)) || env->priv =3D=3D PRV_M) { - return 0; + return RISCV_EXCP_NONE; } else { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } } =20 - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int hmode32(CPURISCVState *env, int csrno) +static RISCVException hmode32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return 0; + return RISCV_EXCP_NONE; } =20 return hmode(env, csrno); =20 } =20 -static int pmp(CPURISCVState *env, int csrno) +static RISCVException pmp(CPURISCVState *env, int csrno) { - return -!riscv_feature(env, RISCV_FEATURE_PMP); + if (riscv_feature(env, RISCV_FEATURE_PMP)) { + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; } #endif =20 @@ -1313,8 +1321,8 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target= _ulong *ret_value, return -RISCV_EXCP_ILLEGAL_INST; } ret =3D csr_ops[csrno].predicate(env, csrno); - if (ret < 0) { - return ret; + if (ret !=3D RISCV_EXCP_NONE) { + return -ret; } =20 /* execute combined read/write operation if it exists */ --=20 2.31.0 From nobody Mon May 6 00:02:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290481; cv=none; d=zohomail.com; s=zohoarc; b=EqlMTnmpcH4WlIYuH4jzRel0KUGrWw5slmDy4f4+Y97OOzJH1b1qJeXMcMKhVWB1SjFyvRxyMrclKDDUQkCLtkh4e+CTbG77FDYUh5LczZL28U0MRejeuvNAJmtVw7eFYaDT2e/fKypV2uDhSAQRWm2fnH+WF6nIDJcshu/kqfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290481; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z7Z6ZTmV/tCO6SJdpB+oVwc03dPcq6OceyiqeT5lhsw=; b=ABOLuMTJra9BlEfb/nZ61KxGPpPn6vWeswRvzKVbPyaXw700JxDEC77UJTHTjR6gDF3oLlbPSWxxGVHrz8B5KEuwD/X63Zy6YSJ5XvEYbfjsLDZ1hjxjsfjIFYaoYDdWe20Z0A4cKXYR5DVsuS11gXzf3vrhOwJ7j/9bmUqC8rU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161729048176972.38149734476804; Thu, 1 Apr 2021 08:21:21 -0700 (PDT) Received: from localhost ([::1]:38628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRz8K-0008MO-31 for importer@patchew.org; Thu, 01 Apr 2021 11:21:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6s-0006qW-L8; Thu, 01 Apr 2021 11:19:50 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:23979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6p-0004py-P3; Thu, 01 Apr 2021 11:19:49 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:19:40 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:01:20 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Apr 2021 08:19:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290387; x=1648826387; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mMjeOjQVZu5SPDYkO3wbX1crsyX0v8qLJYG8eeT2HiQ=; b=FpicnZFNuthbwAul5a2X342AOmBDooAUnPc/C3vy/zdXgyUX+CYZK7p6 EwEqGZHeRuOlHcSAil63sf5l4gp/PwPUUBrQhcJcM7/pR2h4cbzLorHJH 15i0fWnnDCoEMQ9xRs1tx/Y9XaZdGw9bURkWU0HKeZHogs1Xygyb4FrU+ WIzDIoFDXR1Ri4Lmxy2BqWsQVb2XrBds2Od+SP6l5CtFrnRENrMOAKOt8 tGb7Jy8ZVxtzx8fslk3vAgLxGdI/ILtupQ3hM5iU6C0KQyh8Sb/Vu85Ih TCqHsnn9gRNv9AoaIZo/vRLCifLbm3WVBKYGtOuiQPcmGoC2U2vkoqqyz g==; IronPort-SDR: n9vkduRtfVqea0yUDAK/9+Ha7QdQfm66/NDo97XPVzIkLktS9aoLtNW4VZbctsNFZXRvPzR5yQ ZksvVwU3+4fYIWlmFZIqi3maaB90LWyT2+jc4CqhTG7PkqwTWkPLmApD15hSpjxivGZdXITXif FetjqlkQwbIkV42trMibBjhiyv0OC9KlsO7kBlF5uAYDEJQGyH83xG9hHEYwS4wgNwqllrBAoy cxaVWy+NXdm3gcmiQrEJmfyq+YG5JQGMXmTQg4TkfB4cV4MkbpCZl8l8dOfPDeM6xCGb2povzj ekI= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="163455441" IronPort-SDR: uA+ss2XwOlx/I2nBkJCysrXANf/0Lq3DDO0k/AfOsrhcUkW32R80hrleTme/bzebXFOiPbQyHs v94AiNd6k5DntcV83gVC4T4dPoE54MEQBYuuwdxGt9FZC8nTvR0swxUYmMUq5mqjN9NhzN291C 9Lg2dUC0qmOlQoduYh2caYb6fpPvHjFtFUyO7NWSC6+9BnJ8WF2wMhqOywmsrhaNb6ltYzLjn6 F8Pn2PTCRyZaeTmzVKSJdjPWaaDYsqQUvJyYQ5JEEYc0GhPeDgOyUJcC5eo6RVD9dFbpnycrZT kvbmHQKXqwGVtfHmTzPH6crL IronPort-SDR: rwPA0q/v/prZYUk4nVdRVK71e7LcPFbyNAa10cBPcWwoero3nWa9LCa5egFK908zjq7XncfVF9 8I3Z+KOT/T0nm8DDzct06/xLjjPHi+rtOlOARGMo7MXB5NtZsEEJRZ5ZhWpLPZY8Zt30NZd7lo 1NSzuSQaom9LPvtxcuwnQhROWLvWdtYj8U2mE+8B2KmOwx3ElovMqSn9/sU0wfadVquYs0+69N zgqZ4tXCHtE5keUWf9ee/4ejOLvWpaDZSQPhb3gL/ZMZ4dMf2mlfqkcU40P2OQr7PBfZYoYc5O /uQ= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 3/5] target/riscv: Fix 32-bit HS mode access permissions Date: Thu, 1 Apr 2021 11:17:48 -0400 Message-Id: X-Mailer: git-send-email 2.31.0 In-Reply-To: References: 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=216.71.154.42; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/csr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5dc2aa9845..a82a98061b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -181,7 +181,11 @@ static RISCVException hmode(CPURISCVState *env, int cs= rno) static RISCVException hmode32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return RISCV_EXCP_NONE; + if (riscv_cpu_virt_enabled(env)) { + return RISCV_EXCP_ILLEGAL_INST; + } else { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } } =20 return hmode(env, csrno); --=20 2.31.0 From nobody Mon May 6 00:02:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290496; cv=none; d=zohomail.com; s=zohoarc; b=A71q5+3mMpsK2pnH4djdG8WHE1rUgPjJgpz4nnoA+4/cezfOJ2iqNcBx0nXKc8e5DEM24ZgWJCxwyxRRWqAgvI8eU3Jbz9Sh37CqdSLzkRnWla/5r9rcyWMZkNwPpSeEVN9QoQ/Ne5y6GdFQupxuShrAtWAvb1T0xT3gWPgDNjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290496; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yy2tpBzvPFwQQStD0SL1KRHkXBbYMGYGnd3Fsl3leDE=; b=NUd45jedzwVQBPardqPXBjSgvGATdr65pMxQUJMBF4FLhhmJD/1JrlrBhjzj9J+oyVEjrzoBx/P2D/fERfy2ii9HjQxEM8f0R0WdRoF4S3OQVO20UO8OiVWw9w0aFdvB6Qnqylssv6Fgs2Z9Aq+VObseCnH33isqR2ll/nk9EG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617290496123902.3189098589379; Thu, 1 Apr 2021 08:21:36 -0700 (PDT) Received: from localhost ([::1]:39838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRz8Y-0000TE-St for importer@patchew.org; Thu, 01 Apr 2021 11:21:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz7A-00078L-IP; Thu, 01 Apr 2021 11:20:08 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:45353) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz75-0004zP-11; Thu, 01 Apr 2021 11:20:08 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:19:48 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 07:59:55 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Apr 2021 08:19:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290403; x=1648826403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EYo9f7SDlCNCdGevzHDoyzuvS/DbPHgRSssBU8sS0ac=; b=QkRAsvBiqQuEadsx+UOcsd+B/utPdN7Msw8Ww6KbXCR+8hcp/nt9/noB iIxFWvsJ9RqmLPn1rR2NhoI+WnE/Kij4rWnIBxdKh6O8nWKStT74RC7Wk 5yha9aaLqeVcfqIEbLMT04vxzh2vBwNSgfTe/2EQRQ8Zq++c7mTB0xhFi SLAy/z4oDu82XKZOU+kPWZkKkJ1yQTXrCmh+m6sFmLn4JGs1SEJ2Kp5kc m47OUl0fM0gejLaTUlo1cj32aRsX0tCXD3Wvy04WJQKy4kd3c1mcTsn8Q 2VYkpTFEf/lABFIbV5P4Sl36xCdZS/hulaYdJHD/PlDPOW790JanS23rR w==; IronPort-SDR: jwC9sikp3olDDp+GROheoe4UFnwrsXstZsqm3Q1SXCHifWud1A+5BBTMWac1thcHrY1zGGPxp6 cLWDW6iuhSKrL1Z3NIDRlJib/cX+EkuLdUcqq1n8ez4BzEd+PCw6qXSTHNTd1CYvTqu/uhAcUO 2LMrZbzAFbC/UmkJJVrbtH/tLG0NKbgwHLgll1ulUdGGSlt3SYbyNe0GmoM1MXrUNSEWHUu9eU U6eCi/lnnH2SpCGl3hB4wQfNBEaAIyjT2ENbX/kMFiuKX3ny+leBrDr/yysqlWN0y27LsSuygx HKU= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="274398272" IronPort-SDR: DjLcJkkpUHRl+TPeqh3avaQ0BxoqV0loozeQb6yS4R1xJzMrvJv8qwzO2WwaV2RruBzG+DZxY3 BiAEC819KTaNJk5o9JLJRCFYfj1REtjMH5kEbdVPZSFDkVRDt768vciEMRnW+3CEhZ85ntHcEK CKc++6aHZuVh0OiBQ0zQm/iEIMasgjvaE079OWWPjfTGWjvWx8c49Hd6Jt40gelAfsMhRhtK7c E9hFq72fGXmVMDoCK617RAeFotp1eNiAUt2Taj+ANBFcWtB+TNCGm3RbtCDLPJDAOt6afyTiQX +PNPBcKwcQ/99Z4Xz7ODwxK9 IronPort-SDR: pAA4CGu+RXdj2Fjtgg7JpPJmZRTS/PET+6g+ElXUZbyPWydmQbJpSVHb11BU0P3Bg5mUepGYGH AQBpMSHb4xVpch+B4FwBecQ3OdHrHSI5TGDVjKKlVQul867Iv8LAC0p+sZFu5SzpVmWmq64g7o OMaKfLgNj0SiTwoPhltNPF2bbnJdaivzktqemP/1DZ02HYKxbjndnlMqQwrUN0IEkyAnl8LNa2 qYHpuEjLLuxjA4UXeLISilS3euo2Vbaro6XbblrAe8qYUDzJehPTlu7ai+Um9NjSLE03CRmFfs w4A= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 4/5] target/riscv: Use the RISCVException enum for CSR operations Date: Thu, 1 Apr 2021 11:17:57 -0400 Message-Id: <8566c4c271723f27f3ae8fc2429f906a459f17ce.1617290165.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: 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=68.232.141.245; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 14 +- target/riscv/csr.c | 643 +++++++++++++++++++++++++++------------------ 2 files changed, 390 insertions(+), 267 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 1291ddc381..7b9b9da6b7 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -475,12 +475,14 @@ static inline target_ulong riscv_csr_read(CPURISCVSta= te *env, int csrno) =20 typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); -typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value); -typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, - target_ulong new_value); -typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value, target_ulong new_value, target_ulong write_ma= sk); +typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value); +typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, + target_ulong new_value); +typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, + target_ulong write_mask); =20 typedef struct { const char *name; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a82a98061b..9df65a609c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -203,57 +203,62 @@ static RISCVException pmp(CPURISCVState *env, int csr= no) #endif =20 /* User Floating-Point CSRs */ -static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_fflags(CPURISCVState *env, int csrno, + target_ulong *val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif *val =3D riscv_cpu_get_fflags(env); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_fflags(CPURISCVState *env, int csrno, + target_ulong val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } env->mstatus |=3D MSTATUS_FS; #endif riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT)); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_frm(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_frm(CPURISCVState *env, int csrno, + target_ulong *val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif *val =3D env->frm; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_frm(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_frm(CPURISCVState *env, int csrno, + target_ulong val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } env->mstatus |=3D MSTATUS_FS; #endif env->frm =3D val & (FSR_RD >> FSR_RD_SHIFT); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_fcsr(CPURISCVState *env, int csrno, + target_ulong *val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif *val =3D (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT) @@ -262,14 +267,15 @@ static int read_fcsr(CPURISCVState *env, int csrno, t= arget_ulong *val) *val |=3D (env->vxrm << FSR_VXRM_SHIFT) | (env->vxsat << FSR_VXSAT_SHIFT); } - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_fcsr(CPURISCVState *env, int csrno, + target_ulong val) { #if !defined(CONFIG_USER_ONLY) if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } env->mstatus |=3D MSTATUS_FS; #endif @@ -279,59 +285,68 @@ static int write_fcsr(CPURISCVState *env, int csrno, = target_ulong val) env->vxsat =3D (val & FSR_VXSAT) >> FSR_VXSAT_SHIFT; } riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vtype(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vtype(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vtype; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vl(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vl(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vl; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vxrm(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vxrm(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vxrm; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vxrm(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vxrm(CPURISCVState *env, int csrno, + target_ulong val) { env->vxrm =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vxsat(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vxsat(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vxsat; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vxsat(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vxsat(CPURISCVState *env, int csrno, + target_ulong val) { env->vxsat =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vstart(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vstart(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vstart; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vstart(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vstart(CPURISCVState *env, int csrno, + target_ulong val) { env->vstart =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 /* User Timers and Counters */ -static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_instret(CPURISCVState *env, int csrno, + target_ulong *val) { #if !defined(CONFIG_USER_ONLY) if (icount_enabled()) { @@ -342,10 +357,11 @@ static int read_instret(CPURISCVState *env, int csrno= , target_ulong *val) #else *val =3D cpu_get_host_ticks(); #endif - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_instreth(CPURISCVState *env, int csrno, + target_ulong *val) { #if !defined(CONFIG_USER_ONLY) if (icount_enabled()) { @@ -356,46 +372,50 @@ static int read_instreth(CPURISCVState *env, int csrn= o, target_ulong *val) #else *val =3D cpu_get_host_ticks() >> 32; #endif - return 0; + return RISCV_EXCP_NONE; } =20 #if defined(CONFIG_USER_ONLY) -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_time(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D cpu_get_host_ticks(); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_timeh(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D cpu_get_host_ticks() >> 32; - return 0; + return RISCV_EXCP_NONE; } =20 #else /* CONFIG_USER_ONLY */ =20 -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_time(CPURISCVState *env, int csrno, + target_ulong *val) { uint64_t delta =3D riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; =20 if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 *val =3D env->rdtime_fn(env->rdtime_fn_arg) + delta; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_timeh(CPURISCVState *env, int csrno, + target_ulong *val) { uint64_t delta =3D riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; =20 if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 *val =3D (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32; - return 0; + return RISCV_EXCP_NONE; } =20 /* Machine constants */ @@ -449,22 +469,26 @@ static const char valid_vm_1_10_64[16] =3D { }; =20 /* Machine Information Registers */ -static int read_zero(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_zero(CPURISCVState *env, int csrno, + target_ulong *val) { - return *val =3D 0; + *val =3D 0; + return RISCV_EXCP_NONE; } =20 -static int read_mhartid(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mhartid(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mhartid; - return 0; + return RISCV_EXCP_NONE; } =20 /* Machine Trap Setup */ -static int read_mstatus(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mstatus(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mstatus; - return 0; + return RISCV_EXCP_NONE; } =20 static int validate_vm(CPURISCVState *env, target_ulong vm) @@ -476,7 +500,8 @@ static int validate_vm(CPURISCVState *env, target_ulong= vm) } } =20 -static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mstatus(CPURISCVState *env, int csrno, + target_ulong val) { uint64_t mstatus =3D env->mstatus; uint64_t mask =3D 0; @@ -507,16 +532,18 @@ static int write_mstatus(CPURISCVState *env, int csrn= o, target_ulong val) mstatus =3D set_field(mstatus, MSTATUS_SD, dirty); env->mstatus =3D mstatus; =20 - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mstatush(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mstatush(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mstatus >> 32; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mstatush(CPURISCVState *env, int csrno, + target_ulong val) { uint64_t valh =3D (uint64_t)val << 32; uint64_t mask =3D MSTATUS_MPV | MSTATUS_GVA; @@ -527,26 +554,28 @@ static int write_mstatush(CPURISCVState *env, int csr= no, target_ulong val) =20 env->mstatus =3D (env->mstatus & ~mask) | (valh & mask); =20 - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_misa(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_misa(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->misa; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_misa(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_misa(CPURISCVState *env, int csrno, + target_ulong val) { if (!riscv_feature(env, RISCV_FEATURE_MISA)) { /* drop write to misa */ - return 0; + return RISCV_EXCP_NONE; } =20 /* 'I' or 'E' must be present */ if (!(val & (RVI | RVE))) { /* It is not, drop write to misa */ - return 0; + return RISCV_EXCP_NONE; } =20 /* 'E' excludes all other extensions */ @@ -554,7 +583,7 @@ static int write_misa(CPURISCVState *env, int csrno, ta= rget_ulong val) /* when we support 'E' we can do "val =3D RVE;" however * for now we just drop writes if 'E' is present. */ - return 0; + return RISCV_EXCP_NONE; } =20 /* Mask extensions that are not supported by this hart */ @@ -585,55 +614,63 @@ static int write_misa(CPURISCVState *env, int csrno, = target_ulong val) =20 env->misa =3D val; =20 - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_medeleg(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_medeleg(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->medeleg; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_medeleg(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_medeleg(CPURISCVState *env, int csrno, + target_ulong val) { env->medeleg =3D (env->medeleg & ~delegable_excps) | (val & delegable_= excps); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mideleg(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mideleg(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mideleg; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mideleg(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mideleg(CPURISCVState *env, int csrno, + target_ulong val) { env->mideleg =3D (env->mideleg & ~delegable_ints) | (val & delegable_i= nts); if (riscv_has_ext(env, RVH)) { env->mideleg |=3D VS_MODE_INTERRUPTS; } - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mie(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mie(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mie; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mie(CPURISCVState *env, int csrno, + target_ulong val) { env->mie =3D (env->mie & ~all_ints) | (val & all_ints); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mtvec(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mtvec; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mtvec(CPURISCVState *env, int csrno, + target_ulong val) { /* bits [1:0] encode mode; 0 =3D direct, 1 =3D vectored, 2 >=3D reserv= ed */ if ((val & 3) < 2) { @@ -641,92 +678,105 @@ static int write_mtvec(CPURISCVState *env, int csrno= , target_ulong val) } else { qemu_log_mask(LOG_UNIMP, "CSR_MTVEC: reserved mode not supported\n= "); } - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mcounteren(CPURISCVState *env, int csrno, target_ulong *va= l) +static RISCVException read_mcounteren(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mcounteren; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong va= l) +static RISCVException write_mcounteren(CPURISCVState *env, int csrno, + target_ulong val) { env->mcounteren =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 /* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ -static int read_mscounteren(CPURISCVState *env, int csrno, target_ulong *v= al) +static RISCVException read_mscounteren(CPURISCVState *env, int csrno, + target_ulong *val) { if (env->priv_ver < PRIV_VERSION_1_11_0) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } *val =3D env->mcounteren; - return 0; + return RISCV_EXCP_NONE; } =20 /* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ -static int write_mscounteren(CPURISCVState *env, int csrno, target_ulong v= al) +static RISCVException write_mscounteren(CPURISCVState *env, int csrno, + target_ulong val) { if (env->priv_ver < PRIV_VERSION_1_11_0) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } env->mcounteren =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 /* Machine Trap Handling */ -static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mscratch(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mscratch; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mscratch(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mscratch(CPURISCVState *env, int csrno, + target_ulong val) { env->mscratch =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mepc(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mepc(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mepc; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mepc(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mepc(CPURISCVState *env, int csrno, + target_ulong val) { env->mepc =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mcause(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mcause(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mcause; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mcause(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mcause(CPURISCVState *env, int csrno, + target_ulong val) { env->mcause =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mbadaddr(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mbadaddr(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mbadaddr; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mbadaddr(CPURISCVState *env, int csrno, + target_ulong val) { env->mbadaddr =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_mip(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_m= ask) { RISCVCPU *cpu =3D env_archcpu(env); /* Allow software control of delegable interrupts not claimed by hardw= are */ @@ -743,42 +793,47 @@ static int rmw_mip(CPURISCVState *env, int csrno, tar= get_ulong *ret_value, *ret_value =3D old_mip; } =20 - return 0; + return RISCV_EXCP_NONE; } =20 /* Supervisor Trap Setup */ -static int read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_sstatus(CPURISCVState *env, int csrno, + target_ulong *val) { target_ulong mask =3D (sstatus_v1_10_mask); *val =3D env->mstatus & mask; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_sstatus(CPURISCVState *env, int csrno, + target_ulong val) { target_ulong mask =3D (sstatus_v1_10_mask); target_ulong newval =3D (env->mstatus & ~mask) | (val & mask); return write_mstatus(env, CSR_MSTATUS, newval); } =20 -static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vsie(CPURISCVState *env, int csrno, + target_ulong *val) { /* Shift the VS bits to their S bit location in vsie */ *val =3D (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_sie(CPURISCVState *env, int csrno, + target_ulong *val) { if (riscv_cpu_virt_enabled(env)) { read_vsie(env, CSR_VSIE, val); } else { *val =3D env->mie & env->mideleg; } - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vsie(CPURISCVState *env, int csrno, + target_ulong val) { /* Shift the S bits to their VS bit location in mie */ target_ulong newval =3D (env->mie & ~VS_MODE_INTERRUPTS) | @@ -796,16 +851,18 @@ static int write_sie(CPURISCVState *env, int csrno, t= arget_ulong val) write_mie(env, CSR_MIE, newval); } =20 - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_stvec(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->stvec; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_stvec(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_stvec(CPURISCVState *env, int csrno, + target_ulong val) { /* bits [1:0] encode mode; 0 =3D direct, 1 =3D vectored, 2 >=3D reserv= ed */ if ((val & 3) < 2) { @@ -813,72 +870,83 @@ static int write_stvec(CPURISCVState *env, int csrno,= target_ulong val) } else { qemu_log_mask(LOG_UNIMP, "CSR_STVEC: reserved mode not supported\n= "); } - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_scounteren(CPURISCVState *env, int csrno, target_ulong *va= l) +static RISCVException read_scounteren(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->scounteren; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_scounteren(CPURISCVState *env, int csrno, target_ulong va= l) +static RISCVException write_scounteren(CPURISCVState *env, int csrno, + target_ulong val) { env->scounteren =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 /* Supervisor Trap Handling */ -static int read_sscratch(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_sscratch(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->sscratch; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_sscratch(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_sscratch(CPURISCVState *env, int csrno, + target_ulong val) { env->sscratch =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_sepc(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_sepc(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->sepc; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_sepc(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_sepc(CPURISCVState *env, int csrno, + target_ulong val) { env->sepc =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_scause(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_scause(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->scause; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_scause(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_scause(CPURISCVState *env, int csrno, + target_ulong val) { env->scause =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_sbadaddr(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_sbadaddr(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->sbadaddr; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_sbadaddr(CPURISCVState *env, int csrno, + target_ulong val) { env->sbadaddr =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_vsip(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_= mask) { /* Shift the S bits to their VS bit location in mip */ int ret =3D rmw_mip(env, 0, ret_value, new_value << 1, @@ -889,8 +957,9 @@ static int rmw_vsip(CPURISCVState *env, int csrno, targ= et_ulong *ret_value, return ret; } =20 -static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_sip(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_m= ask) { int ret; =20 @@ -906,32 +975,34 @@ static int rmw_sip(CPURISCVState *env, int csrno, tar= get_ulong *ret_value, } =20 /* Supervisor Protection and Translation */ -static int read_satp(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_satp(CPURISCVState *env, int csrno, + target_ulong *val) { if (!riscv_feature(env, RISCV_FEATURE_MMU)) { *val =3D 0; - return 0; + return RISCV_EXCP_NONE; } =20 if (env->priv =3D=3D PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } else { *val =3D env->satp; } =20 - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_satp(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_satp(CPURISCVState *env, int csrno, + target_ulong val) { if (!riscv_feature(env, RISCV_FEATURE_MMU)) { - return 0; + return RISCV_EXCP_NONE; } if (validate_vm(env, get_field(val, SATP_MODE)) && ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) { if (env->priv =3D=3D PRV_S && get_field(env->mstatus, MSTATUS_TVM)= ) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } else { if ((val ^ env->satp) & SATP_ASID) { tlb_flush(env_cpu(env)); @@ -939,11 +1010,12 @@ static int write_satp(CPURISCVState *env, int csrno,= target_ulong val) env->satp =3D val; } } - return 0; + return RISCV_EXCP_NONE; } =20 /* Hypervisor Extensions */ -static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hstatus(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->hstatus; if (!riscv_cpu_is_32bit(env)) { @@ -952,10 +1024,11 @@ static int read_hstatus(CPURISCVState *env, int csrn= o, target_ulong *val) } /* We only support little endian */ *val =3D set_field(*val, HSTATUS_VSBE, 0); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hstatus(CPURISCVState *env, int csrno, + target_ulong val) { env->hstatus =3D val; if (!riscv_cpu_is_32bit(env) && get_field(val, HSTATUS_VSXL) !=3D 2) { @@ -964,35 +1037,40 @@ static int write_hstatus(CPURISCVState *env, int csr= no, target_ulong val) if (get_field(val, HSTATUS_VSBE) !=3D 0) { qemu_log_mask(LOG_UNIMP, "QEMU does not support big endian guests.= "); } - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_hedeleg(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hedeleg(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->hedeleg; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hedeleg(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hedeleg(CPURISCVState *env, int csrno, + target_ulong val) { env->hedeleg =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_hideleg(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hideleg(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->hideleg; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hideleg(CPURISCVState *env, int csrno, + target_ulong val) { env->hideleg =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_hvip(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_= mask) { int ret =3D rmw_mip(env, 0, ret_value, new_value, write_mask & hvip_writable_mask); @@ -1002,8 +1080,9 @@ static int rmw_hvip(CPURISCVState *env, int csrno, ta= rget_ulong *ret_value, return ret; } =20 -static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_hip(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_m= ask) { int ret =3D rmw_mip(env, 0, ret_value, new_value, write_mask & hip_writable_mask); @@ -1013,103 +1092,119 @@ static int rmw_hip(CPURISCVState *env, int csrno,= target_ulong *ret_value, return ret; } =20 -static int read_hie(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hie(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mie & VS_MODE_INTERRUPTS; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hie(CPURISCVState *env, int csrno, + target_ulong val) { target_ulong newval =3D (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_M= ODE_INTERRUPTS); return write_mie(env, CSR_MIE, newval); } =20 -static int read_hcounteren(CPURISCVState *env, int csrno, target_ulong *va= l) +static RISCVException read_hcounteren(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->hcounteren; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hcounteren(CPURISCVState *env, int csrno, target_ulong va= l) +static RISCVException write_hcounteren(CPURISCVState *env, int csrno, + target_ulong val) { env->hcounteren =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_hgeie(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hgeie(CPURISCVState *env, int csrno, + target_ulong *val) { qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hgeie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hgeie(CPURISCVState *env, int csrno, + target_ulong val) { qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_htval(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_htval(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->htval; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_htval(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_htval(CPURISCVState *env, int csrno, + target_ulong val) { env->htval =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_htinst(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_htinst(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->htinst; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_htinst(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_htinst(CPURISCVState *env, int csrno, + target_ulong val) { - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_hgeip(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hgeip(CPURISCVState *env, int csrno, + target_ulong *val) { qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hgeip(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hgeip(CPURISCVState *env, int csrno, + target_ulong val) { qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_hgatp(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_hgatp(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->hgatp; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_hgatp(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_hgatp(CPURISCVState *env, int csrno, + target_ulong val) { env->hgatp =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_htimedelta(CPURISCVState *env, int csrno, target_ulong *va= l) +static RISCVException read_htimedelta(CPURISCVState *env, int csrno, + target_ulong *val) { if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 *val =3D env->htimedelta; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong va= l) +static RISCVException write_htimedelta(CPURISCVState *env, int csrno, + target_ulong val) { if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 if (riscv_cpu_is_32bit(env)) { @@ -1117,162 +1212,185 @@ static int write_htimedelta(CPURISCVState *env, i= nt csrno, target_ulong val) } else { env->htimedelta =3D val; } - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_htimedeltah(CPURISCVState *env, int csrno, target_ulong *v= al) +static RISCVException read_htimedeltah(CPURISCVState *env, int csrno, + target_ulong *val) { if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 *val =3D env->htimedelta >> 32; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_htimedeltah(CPURISCVState *env, int csrno, target_ulong v= al) +static RISCVException write_htimedeltah(CPURISCVState *env, int csrno, + target_ulong val) { if (!env->rdtime_fn) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 env->htimedelta =3D deposit64(env->htimedelta, 32, 32, (uint64_t)val); - return 0; + return RISCV_EXCP_NONE; } =20 /* Virtual CSR Registers */ -static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vsstatus(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vsstatus; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vsstatus(CPURISCVState *env, int csrno, + target_ulong val) { uint64_t mask =3D (target_ulong)-1; env->vsstatus =3D (env->vsstatus & ~mask) | (uint64_t)val; - return 0; + return RISCV_EXCP_NONE; } =20 static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val) { *val =3D env->vstvec; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vstvec(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vstvec(CPURISCVState *env, int csrno, + target_ulong val) { env->vstvec =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vsscratch(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vsscratch(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vsscratch; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vsscratch(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vsscratch(CPURISCVState *env, int csrno, + target_ulong val) { env->vsscratch =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vsepc(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vsepc(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vsepc; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vsepc(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vsepc(CPURISCVState *env, int csrno, + target_ulong val) { env->vsepc =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vscause(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vscause(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vscause; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vscause(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vscause(CPURISCVState *env, int csrno, + target_ulong val) { env->vscause =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vstval(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vstval(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vstval; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vstval(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vstval(CPURISCVState *env, int csrno, + target_ulong val) { env->vstval =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_vsatp(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_vsatp(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->vsatp; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_vsatp(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_vsatp(CPURISCVState *env, int csrno, + target_ulong val) { env->vsatp =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mtval2(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mtval2(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mtval2; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mtval2(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mtval2(CPURISCVState *env, int csrno, + target_ulong val) { env->mtval2 =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_mtinst(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_mtinst(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D env->mtinst; - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_mtinst(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_mtinst(CPURISCVState *env, int csrno, + target_ulong val) { env->mtinst =3D val; - return 0; + return RISCV_EXCP_NONE; } =20 /* Physical Memory Protection */ -static int read_pmpcfg(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D pmpcfg_csr_read(env, csrno - CSR_PMPCFG0); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_pmpcfg(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, + target_ulong val) { pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val); - return 0; + return RISCV_EXCP_NONE; } =20 -static int read_pmpaddr(CPURISCVState *env, int csrno, target_ulong *val) +static RISCVException read_pmpaddr(CPURISCVState *env, int csrno, + target_ulong *val) { *val =3D pmpaddr_csr_read(env, csrno - CSR_PMPADDR0); - return 0; + return RISCV_EXCP_NONE; } =20 -static int write_pmpaddr(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, + target_ulong val) { pmpaddr_csr_write(env, csrno - CSR_PMPADDR0, val); - return 0; + return RISCV_EXCP_NONE; } =20 #endif @@ -1331,18 +1449,21 @@ int riscv_csrrw(CPURISCVState *env, int csrno, targ= et_ulong *ret_value, =20 /* execute combined read/write operation if it exists */ if (csr_ops[csrno].op) { - return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_m= ask); + ret =3D csr_ops[csrno].op(env, csrno, ret_value, new_value, write_= mask); + if (ret !=3D RISCV_EXCP_NONE) { + return -ret; + } + return 0; } =20 /* if no accessor exists then return failure */ if (!csr_ops[csrno].read) { return -RISCV_EXCP_ILLEGAL_INST; } - /* read old value */ ret =3D csr_ops[csrno].read(env, csrno, &old_value); - if (ret < 0) { - return ret; + if (ret !=3D RISCV_EXCP_NONE) { + return -ret; } =20 /* write value if writable and write mask set, otherwise drop writes */ @@ -1350,8 +1471,8 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target= _ulong *ret_value, new_value =3D (old_value & ~write_mask) | (new_value & write_mask); if (csr_ops[csrno].write) { ret =3D csr_ops[csrno].write(env, csrno, new_value); - if (ret < 0) { - return ret; + if (ret !=3D RISCV_EXCP_NONE) { + return -ret; } } } --=20 2.31.0 From nobody Mon May 6 00:02:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290834; cv=none; d=zohomail.com; s=zohoarc; b=KZY3yjGz1FXJFynRopVoOG9QewEIZMDKjCGwsW8CdxOe/oNNboRRtzHtPkCHtTr6oAv1GOP5Rsqbsi3anw/35pdfwh6rgVKrG9l7f9a092Dw7R8fEGCrcQrb7K6Ca0X685anWo1bIeiX3fsHQE/3/U5DXYF+2e268l5JQOlZfm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290834; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QRRppx9RGLoq3DmTBhE+RU/yre/08g/FNCLaHxbVBug=; b=JCrUKgNIOcvACpIiLbJebhTsxTShbIqXbLIZyVyBPCur1SWqh1Oh+tKAeJdVJiRGIrD/uaqhZB2lQJDHanIHkKWwr028OoW2EBp9f4eps310/xi/SUeuyfLN5TPtiIXyIZyWO86YdA5/NO9P0Qzj4GZ3qJn4vP5eCeO0lGDW3e8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617290834039308.1865499523601; Thu, 1 Apr 2021 08:27:14 -0700 (PDT) Received: from localhost ([::1]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRzE0-0006UH-RH for importer@patchew.org; Thu, 01 Apr 2021 11:27:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz7Z-0007t3-Td; Thu, 01 Apr 2021 11:20:33 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:49467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz7X-0005Lp-L0; Thu, 01 Apr 2021 11:20:33 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:20:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:01:39 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Apr 2021 08:19:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290484; x=1648826484; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NvIACZsNCOtHYoAOlNCAlMIPm+x7eeAHMHw8T6QdPbE=; b=g8WqXl411VBg6CDmy6M9YPQjlSXvEFdNUYv55H97fBmcUOyQaeEIGXS7 8TlqgQa7kNQlYddxDpBTl0iBD1T4k8L1uwiMNPCp/R0YudVrLF70spQ3I LDRvN0RN3hqtn49PjGUbTTJD0x+t6e/haT68C54Qx/i+T6cTnnkLe3mrx 6FTDuyicHYA/zUuTV2M3gB+vN1O/Flpv1RKRB5Slfx1nLehigHZ5PtiTX QnEu0g/fUyHk7M9wqoRqU8jYaAxKiRGWfLEJzP1QkBEYOzMr3KN0ua/AK 03Ao8AmSwOawE/RaJI0zTbtOObeAFafopeJ0L3K7J0mAIOUGTazI21P1f g==; IronPort-SDR: hx/MqSebwali7UAcDoX/FvbOCSK1w1BLI+MazwS+i9OJVTfCbbyhaIAMQbi5N3zqqrAd51H5D3 jvVqeTuRxOe6jNU9/sO9hSzM3wMYuJE+bXZszo5QU8zep67dC7r3xMEG7lGBKRRBp7tb4DBWkI SIkjM2/6FycXIG4vevjfPyUYUDXvSZSbl+dy96WkH6uv4f02ikh39DkGM+VNhT8GxW76smM3u4 OhjS3XZCtJgvYov1tOSGD61TFjt6gBZ35OiVM9pCkRSyO0qu0N0sTgGMN2kAjwuiptogFPwlPx ePg= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="267973424" IronPort-SDR: UAHJcIGZfHeM8iD1zmyR9ixqRiPsw3RpAIKWTTluYsmKdB158maOJi4MEdxpRMB7v4I/QQVi+A 9m291CJ8Fk55AC4z1Ilb7VAfMUQCL8FIyMrAPIShJ2XtxGf+FV2rP5js3oXuoB7rTBUEYntWFZ jZpM/inNCsyWfs9iLrStDKgkScTszjGFUGiGLF1jygkGNNdfEBxaO1pF8dyxX/pTeO5t++bAW9 z0r2MQNHRU5YMVklSZNNuOx1CO9/Rg7E/FS9pdzCddFYT5RHVHLx7kHusdl7ls/HwUkLwqdUtW /Z+CybV9J9nK9e9V5v7RCcSI IronPort-SDR: ekHuxOxRrswirCdMx8ck1GsqE6E1LKXjvEllLEQSE09/z4qalA37YnpLdcPcL+D4PxMcIsQStU 1OVmeWtJPrv/IIxMt0rzLZotin7DK3e3ICvQezieOrOI8ePim/+JHuLcJcsuwHvSb3C/GU5Bc2 L5/dSPAqkjOwuZ3ksndE8Fpk1h3Jb+zjvdsv0iOY/mJTxYw+FmABhBKFIXOD1E/whbrZAlMV9G h4SBXg9BXFsTYn9SR/1kM2jCn5xPR2qjBKrLJRpOjKhMNtb9Y5Hb4tsNAFdzEbeJPCxzCz2n1l HSU= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 5/5] target/riscv: Use RISCVException enum for CSR access Date: Thu, 1 Apr 2021 11:18:07 -0400 Message-Id: <302b208f40373557fa11b351b5c9f43039ca8ea3.1617290165.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: 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=68.232.143.124; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 11 +++++++---- target/riscv/csr.c | 37 ++++++++++++++++++------------------- target/riscv/gdbstub.c | 8 ++++---- target/riscv/op_helper.c | 18 +++++++++--------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7b9b9da6b7..d3df8b9292 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -455,10 +455,13 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState= *env, target_ulong *pc, *pflags =3D flags; } =20 -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask); -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_val= ue, - target_ulong new_value, target_ulong write_mask); +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask= ); +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, + target_ulong write_mask); =20 static inline void riscv_csr_write(CPURISCVState *env, int csrno, target_ulong val) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9df65a609c..459db93c83 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1404,10 +1404,11 @@ static RISCVException write_pmpaddr(CPURISCVState *= env, int csrno, * csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value); */ =20 -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) { - int ret; + RISCVException ret; target_ulong old_value; RISCVCPU *cpu =3D env_archcpu(env); =20 @@ -1429,41 +1430,37 @@ int riscv_csrrw(CPURISCVState *env, int csrno, targ= et_ulong *ret_value, =20 if ((write_mask && read_only) || (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif =20 /* ensure the CSR extension is enabled. */ if (!cpu->cfg.ext_icsr) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 /* check predicate */ if (!csr_ops[csrno].predicate) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } ret =3D csr_ops[csrno].predicate(env, csrno); if (ret !=3D RISCV_EXCP_NONE) { - return -ret; + return ret; } =20 /* execute combined read/write operation if it exists */ if (csr_ops[csrno].op) { - ret =3D csr_ops[csrno].op(env, csrno, ret_value, new_value, write_= mask); - if (ret !=3D RISCV_EXCP_NONE) { - return -ret; - } - return 0; + return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_m= ask); } =20 /* if no accessor exists then return failure */ if (!csr_ops[csrno].read) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } /* read old value */ ret =3D csr_ops[csrno].read(env, csrno, &old_value); if (ret !=3D RISCV_EXCP_NONE) { - return -ret; + return ret; } =20 /* write value if writable and write mask set, otherwise drop writes */ @@ -1472,7 +1469,7 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target= _ulong *ret_value, if (csr_ops[csrno].write) { ret =3D csr_ops[csrno].write(env, csrno, new_value); if (ret !=3D RISCV_EXCP_NONE) { - return -ret; + return ret; } } } @@ -1482,17 +1479,19 @@ int riscv_csrrw(CPURISCVState *env, int csrno, targ= et_ulong *ret_value, *ret_value =3D old_value; } =20 - return 0; + return RISCV_EXCP_NONE; } =20 /* * Debugger support. If not in user mode, set env->debugger before the * riscv_csrrw call and clear it after the call. */ -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_val= ue, - target_ulong new_value, target_ulong write_mask) +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, + target_ulong write_mask) { - int ret; + RISCVException ret; #if !defined(CONFIG_USER_ONLY) env->debugger =3D true; #endif diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 5f96b7ea2a..ca78682cf4 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -71,7 +71,7 @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArr= ay *buf, int n) */ result =3D riscv_csrrw_debug(env, n - 32, &val, 0, 0); - if (result =3D=3D 0) { + if (result =3D=3D RISCV_EXCP_NONE) { return gdb_get_regl(buf, val); } } @@ -94,7 +94,7 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t = *mem_buf, int n) */ result =3D riscv_csrrw_debug(env, n - 32, NULL, val, -1); - if (result =3D=3D 0) { + if (result =3D=3D RISCV_EXCP_NONE) { return sizeof(target_ulong); } } @@ -108,7 +108,7 @@ static int riscv_gdb_get_csr(CPURISCVState *env, GByteA= rray *buf, int n) int result; =20 result =3D riscv_csrrw_debug(env, n, &val, 0, 0); - if (result =3D=3D 0) { + if (result =3D=3D RISCV_EXCP_NONE) { return gdb_get_regl(buf, val); } } @@ -122,7 +122,7 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_= t *mem_buf, int n) int result; =20 result =3D riscv_csrrw_debug(env, n, NULL, val, -1); - if (result =3D=3D 0) { + if (result =3D=3D RISCV_EXCP_NONE) { return sizeof(target_ulong); } } diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 1eddcb94de..3fc5e0505d 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -42,10 +42,10 @@ target_ulong helper_csrrw(CPURISCVState *env, target_ul= ong src, target_ulong csr) { target_ulong val =3D 0; - int ret =3D riscv_csrrw(env, csr, &val, src, -1); + RISCVException ret =3D riscv_csrrw(env, csr, &val, src, -1); =20 - if (ret < 0) { - riscv_raise_exception(env, -ret, GETPC()); + if (ret !=3D RISCV_EXCP_NONE) { + riscv_raise_exception(env, ret, GETPC()); } return val; } @@ -54,10 +54,10 @@ target_ulong helper_csrrs(CPURISCVState *env, target_ul= ong src, target_ulong csr, target_ulong rs1_pass) { target_ulong val =3D 0; - int ret =3D riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0); + RISCVException ret =3D riscv_csrrw(env, csr, &val, -1, rs1_pass ? src = : 0); =20 - if (ret < 0) { - riscv_raise_exception(env, -ret, GETPC()); + if (ret !=3D RISCV_EXCP_NONE) { + riscv_raise_exception(env, ret, GETPC()); } return val; } @@ -66,10 +66,10 @@ target_ulong helper_csrrc(CPURISCVState *env, target_ul= ong src, target_ulong csr, target_ulong rs1_pass) { target_ulong val =3D 0; - int ret =3D riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0); + RISCVException ret =3D riscv_csrrw(env, csr, &val, 0, rs1_pass ? src := 0); =20 - if (ret < 0) { - riscv_raise_exception(env, -ret, GETPC()); + if (ret !=3D RISCV_EXCP_NONE) { + riscv_raise_exception(env, ret, GETPC()); } return val; } --=20 2.31.0