From nobody Tue Feb 10 12:13:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass 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; arc=pass (i=1 dmarc=pass fromdomain=wdc.com); dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=2; a=rsa-sha256; t=1639196882; cv=pass; d=zohomail.com; s=zohoarc; b=UpNXEHxBIUiCwGdw0l/H/SWPuOymauw2EEOX1ue6GT/ewo3kvLqz52UbrC+jKdjvsaRv4KFD+mUbe8I/JTt8esWtZHI8Lzl6eDtWgl2v3uiUQlbPgw2hH0pNSDTmYvOn47TM8vQNcPMhV6rmsts0UoPJuBoly2uhgor7Y1OWYo4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639196882; h=Content-Type: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=Vzo3UOPPDgIWXM2FkTKl/s9dkvjELReckMweQtVsTPA=; b=gjTcHtqCKVMqlKl4OLuqiG8cjOAfXq1KpeyG/Wx4ETtyORfWtTKcDeWMykL1+u0r5LU3NY6UTL2Q2jvdT+ASFh09N9ELf8rovy55A5IyL6Uqf4/5yTivCU9NZoMSCbe9vcEjW6GnHnYLQKo8KPPziH8YwYNf8Z+ChYFqSZ8y1+8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass 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; arc=pass (i=1 dmarc=pass fromdomain=wdc.com); dmarc=fail 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 1639196882115972.8497256480277; Fri, 10 Dec 2021 20:28:02 -0800 (PST) Received: from localhost ([::1]:51236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtzN-0004w6-1y for importer@patchew.org; Fri, 10 Dec 2021 23:28:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsC-0005K4-Lv; Fri, 10 Dec 2021 23:20:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts8-0001io-IR; Fri, 10 Dec 2021 23:20:36 -0500 Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:29 +0800 Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:27 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196432; x=1670732432; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=ojzk+qENhEgkfyUeBnglnjCzVeFnmug2KXqCTZ0Y7WI=; b=j/BU2vNBGG8mnNZfbGfYvh2d5eaMGfnERd2jyquCbEbblTfhHcrPf04E /4DfFI8YO1yVOGfb/cJmvPwR12Hkg9r9mDoBe+EBn4EnIijWDUXvHBySO 3jeonwqyRP7o1WB09wXzbnlKFf3lLQsB7DwiYLzEmQAUWVFr8wsbddw9X XHO8iZTMoG13vLZMQVeGv8VYaO9/QDAM9gszNhh0Fyftw5/4hLGYAdKHp WNFcGzKaWOej7m9q8+B8S8e3CjEMT/ywIyz+E05BOCc/q4UUW7zqFRqfR GVisW9tHmU5gjLlfTNeQmxaCR6f3kTD4xEjYnkitskqys1bYrpw0GWfOe g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834357" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffBqKoch+4lJKV69LvBqilv9DP7XktOhOmP1cX13s+5AFCusIDEGeDyfQIU6bX2Cos0fZ30J2TjJoUZjR56DxzaG7w/Lj4t4A8XG7YhPLe7hDjA5trZjPJLhdmEGj3eNqHeT6RTsEas2P2dVApPeElUCKbF4aZ81KgOew3tq5icIR27ptxxo/b5O/j9/k3kj1nwWewWZhl/pVIAx7hxF66QHWS/KOCg4cKOlsT3tskgZ+ov/89DwkOwjaWyKZcPOghBeoJxKMAZPIf6HOmxl/7mBfyOhERgGJU4WouOFpjJGZt1TVLjqVd8hQtSvc+slAgYsdTr/iwz1BMG7zWlhyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Vzo3UOPPDgIWXM2FkTKl/s9dkvjELReckMweQtVsTPA=; b=K4cRchO4X8oSS6v0FLien3e3A4cz6Pyp9YyH82il5KWmXAxtLDsaetZzHxwQWmADlr9Nj6EIoQikhLz9IavQsOXiuJ7PdgSFUCvr09nKwixSHYBfwPYFgQIMWyZgomQ1ky5P82666O24GT4gRkIvQwAYUIQgWsRieJMXiNUT4fR5fPlpJ+IzR0wzEnnLLmsFP2D9W3RgooGbZsVEpr+4RJEDMw83fcUkwHuolUtPw1vYy7IgloXGdF6mMv9DPUYcekEdPGYnM3KdMBEtvTNvpqEmTqfgCEcTjgjWGlhlTPQx09ZebeunqSe3K7+4yaY1ca2smLSLkb8MfXbWhyuO+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vzo3UOPPDgIWXM2FkTKl/s9dkvjELReckMweQtVsTPA=; b=yw9CdNpefQy/n24CoXZLhZ2eBP7mZljGd05p3u7CRNqXSo7fLv3W795oCAPcJ7Pyaw16Msl2xtYkhdfhCfewIThp1M6FhvdanOyIpY5d+G1YZzVn5YY/QopPHdCncO9k6hTWbubeNKTKX4hOmXpqdn7BGBqzNWtbDANkPt8FPqU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 10/23] target/riscv: Implement AIA CSRs for 64 local interrupts on RV32 Date: Sat, 11 Dec 2021 09:49:04 +0530 Message-Id: <20211211041917.135345-11-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87dfba4f-7543-45b2-8c83-08d9bc5d8f63 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JMG3AuDcfokCSVLFAcqPudveBXr087GbZFs8GhkZxgSYrtfSdCn9M88CHlUko97ULzwSybWEn5INRRuln6gBxuKmoKhhEuStbVoy+HFw/feeRsMenKv84ds3NBhWb721UpEXVx3NpuYSwAio9PR6joZoHvGUQtCzwLotTtqkNF3NJc9c4/zPQ3ZxylvUlzAy8C/bMOYjv2MCHsV+U3Rwvgdann5KNaOMqPttF1zvM6lMa/Om5IzqvD0RBls/zRzHwH+e0v40bEtBO3AFZhbr5tB06yEJzXBBGp0AsMwhyqmcjiT0tFS4aBj0uv6MBmPWSF2V+FbNfj5w4lSc9VuykjP058MwUrbqqs5zBjIDedcnzhfcVmrUost+xZH/lSOMjNZtpofZX/zY70lfkiNVmTlXlrB/HDV7pZ2a8ZSPoHt7apT0vyDmmrgq1a8d/QFtwAPaOw1V5VhJhuz/IDikfukQGKMtOq8k7veYuUVKVwUgxXTnJX8wpkFkV+QU3nL5vYGPshFf3kPtFGf4HIWmIjipHfmq+ei/tXzt3rduk9e30yAd9xH2KIb/3oxnD6MlMQ4zMAlx9akz0KMHatGH4NHcGRLRNy2hWz1FR8UjJ32QCxEyZEdyXcWeso9/eJlTt/ahnmgUP2CfgRr9QtSSfB3bAQQcDwX2ccWGE8h/t1q8+ATQyqA1NiSqrMn3WCTnhCclSz7huYHKxiO935YEEw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kPGZcqPRH0CK7AV2l7oyVgMAknsLZZdFsx6PSMS91gtTpMNMegUa6ciZJRlQ?= =?us-ascii?Q?l9QfvrN7XBDTw4HdYHCgIj0RFx2UIzOnuFb3unu2UZFHJdyBGjjV5GWtBGcR?= =?us-ascii?Q?pmThNpN4CZL8S3Ae/DBRVAbwjgqqjKZ8GG29Ngh1aJLzMTlUkNfKwLqbgA6j?= =?us-ascii?Q?nuQ0XacG35E6Wfed1h6c9vxB4jWLfBbzzxlqwniGOvJpy9hLY8bi0/GR0niJ?= =?us-ascii?Q?UNN7PIN7McHL1fONRk3Fu0lGceXxSu0Dce35xyMSoDw7OUKYXHDr1Vzvv5/9?= =?us-ascii?Q?WrDP1pj0Hg4Sk0f9dEDKIKoVhRFvc5iR2yjeKCz5iTOiEaGS3fJ1ulM4WCg2?= =?us-ascii?Q?bWeL+3twpJ/nsryTnD0jsgum1K29hgkTA+7uW+TkkIA4rHmEB0C6x4KFodoC?= =?us-ascii?Q?mtBSjPeLAuDSGoL309Gey94NszzzyFtCZ+gTT8q2MJV40PADYIwZqSAMfa5M?= =?us-ascii?Q?CMPWLfbPLH6PsvZ6Gqgqvlw46YpvXBNAQT5Omv+onmq0sZlI9i/IjzPoD93Q?= =?us-ascii?Q?0aVozkUi3raR5mnrL8iQv7joTixYAN5PW7tmOL1dEolR5YhTvEr0gINoGNPk?= =?us-ascii?Q?Pypu0p9MdYE0/xXh9AeLYQLSr5e9RTq8M0yyKx0sYcOir/9NnfqYCJ0uoQi/?= =?us-ascii?Q?1g+8BO3Zs4FIrjMgrpwyREXZw04vGg+7xfaM5RTXhiDyvEEldAdARzHjPxrI?= =?us-ascii?Q?0qJx4Nj1V43SMC7UaB1aVIeNjkA9aki6nvvblJf+o4wK7zFlfiAqZCFqFl30?= =?us-ascii?Q?QKS2mvqu3QfpqmUg31G+C5sZ9au+/7TgS75DDs76BFngHf5GDSFX+RMz3ELp?= =?us-ascii?Q?oRmoIsATbdCwFbNlpk97oJKke++k4rbnqpK/Mo6pGPUb1mzgBadSynL+4fpS?= =?us-ascii?Q?26Q1SYc37nMZ+nvT7MRHzM3EpyCdHZSZhkiDP9wFGG+b3tt6qe3+e0riY5CI?= =?us-ascii?Q?ePBb9J2bWr5Gh3IKpU8H6tCi5VNtSarpWhNQ00ipyIiXauPyNoW/I5iBS010?= =?us-ascii?Q?QVoIoA8Y8p+Wm6NWvnO2nVnfagZu1inhRjwhawwX35yi0LP9p/P2+gowh5Qk?= =?us-ascii?Q?crKmc1HVGIXgAMDPDXOOJVyEDZz91ycD55gyHui8faZNxshdpM/YpKrOPB8w?= =?us-ascii?Q?l1Eet+/f6fV29dAxF24hk5vKpbjme1yzf29u3OtXkTUEzw6keTmlKCTZVJMG?= =?us-ascii?Q?4ePO4sEbrFBBqsxwkA8Ktc7lPyt0IUYUFxgGl019PMjCgNi0u0obhcrI/Scs?= =?us-ascii?Q?oX+VngSteoRUVSRi+Ierx6kgksikVsUIRdpZpJ4L21+lrWEVFcfsWqayhJat?= =?us-ascii?Q?SgyM2SePJFGEXIQ/36ipFo53KUSQZDehZGBp/XJF7wUxjfCM8AZ6BxsNvFZS?= =?us-ascii?Q?GV7tePFhlqYgPGFyq+BgCg8/MgUp+jfMpnTe5H/GRiDLRssEqPLxzwVrq4d3?= =?us-ascii?Q?1r8ma1yQy/uON1WVZrbPPVUAkMdCmftOkapZXM5vh3SKOcqDr4u0pqVfF0GE?= =?us-ascii?Q?GSqVXRfzZiwKc1kuiAkKGIHzhDbOSmi9t06a0IWoxVj7bwawhrKmMSVcfsn5?= =?us-ascii?Q?JbZHzkQJqPVafnQP47fERmx5WH+iLZ/EeisRoVp+MN3wUtmlAlWPp525dQ2T?= =?us-ascii?Q?GVvewRTu+2PfaewPcuFggi0=3D?= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87dfba4f-7543-45b2-8c83-08d9bc5d8f63 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:27.6718 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Nlm4G/cus1al7SARdKZt3x4Y8fa0lUivCdVPxUisore3/ayPwfXmFFuArAPjp2xmQ8dEBY8s1b3/BegDpwZNbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 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=972e533d7=Anup.Patel@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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sharedspace.onmicrosoft.com) X-ZM-MESSAGEID: 1639196884302100001 Content-Type: text/plain; charset="utf-8" The AIA specification adds new CSRs for RV32 so that RISC-V hart can support 64 local interrupts on both RV32 and RV64. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 14 +- target/riscv/cpu_helper.c | 10 +- target/riscv/csr.c | 560 +++++++++++++++++++++++++++++++------- target/riscv/machine.c | 10 +- 4 files changed, 474 insertions(+), 120 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 69d9c42ad3..8b14fac9a9 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -160,12 +160,12 @@ struct CPURISCVState { */ uint64_t mstatus; =20 - target_ulong mip; + uint64_t mip; =20 - uint32_t miclaim; + uint64_t miclaim; =20 - target_ulong mie; - target_ulong mideleg; + uint64_t mie; + uint64_t mideleg; =20 target_ulong satp; /* since: priv-1.10.0 */ target_ulong stval; @@ -187,7 +187,7 @@ struct CPURISCVState { /* Hypervisor CSRs */ target_ulong hstatus; target_ulong hedeleg; - target_ulong hideleg; + uint64_t hideleg; target_ulong hcounteren; target_ulong htval; target_ulong htinst; @@ -414,8 +414,8 @@ void riscv_cpu_list(void); #ifndef CONFIG_USER_ONLY bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env); -int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts); -uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value= ); +int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts); +uint64_t riscv_cpu_update_mip(RISCVCPU *cpu, uint64_t mask, uint64_t value= ); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value = */ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), uint32_t arg); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 033feb3463..e387e9b1e1 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -503,7 +503,7 @@ bool riscv_cpu_two_stage_lookup(int mmu_idx) return mmu_idx & TB_FLAGS_PRIV_HYP_ACCESS_MASK; } =20 -int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts) +int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts) { CPURISCVState *env =3D &cpu->env; if (env->miclaim & interrupts) { @@ -514,11 +514,11 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_= t interrupts) } } =20 -uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) +uint64_t riscv_cpu_update_mip(RISCVCPU *cpu, uint64_t mask, uint64_t value) { CPURISCVState *env =3D &cpu->env; CPUState *cs =3D CPU(cpu); - uint32_t gein, vsgein =3D 0, old =3D env->mip; + uint64_t gein, vsgein =3D 0, old =3D env->mip; bool locked =3D false; =20 if (riscv_cpu_virt_enabled(env)) { @@ -1221,7 +1221,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) */ bool async =3D !!(cs->exception_index & RISCV_EXCP_INT_FLAG); target_ulong cause =3D cs->exception_index & RISCV_EXCP_INT_MASK; - target_ulong deleg =3D async ? env->mideleg : env->medeleg; + uint64_t deleg =3D async ? env->mideleg : env->medeleg; bool write_tval =3D false; target_ulong tval =3D 0; target_ulong htval =3D 0; @@ -1286,7 +1286,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) cause < TARGET_LONG_BITS && ((deleg >> cause) & 1)) { /* handle the trap in S-mode */ if (riscv_has_ext(env, RVH)) { - target_ulong hdeleg =3D async ? env->hideleg : env->hedeleg; + uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; =20 if (env->two_stage_lookup && write_tval) { /* diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e5234a1964..d9bb5ff649 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -153,6 +153,15 @@ static RISCVException any32(CPURISCVState *env, int cs= rno) =20 } =20 +static int aia_any32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return any32(env, csrno); +} + static RISCVException smode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS)) { @@ -162,6 +171,24 @@ static RISCVException smode(CPURISCVState *env, int cs= rno) return RISCV_EXCP_ILLEGAL_INST; } =20 +static int smode32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smode(env, csrno); +} + +static int aia_smode32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smode32(env, csrno); +} + static RISCVException hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS) && @@ -202,6 +229,15 @@ static RISCVException pointer_masking(CPURISCVState *e= nv, int csrno) return RISCV_EXCP_ILLEGAL_INST; } =20 +static int aia_hmode32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return hmode32(env, csrno); +} + static RISCVException pmp(CPURISCVState *env, int csrno) { if (riscv_feature(env, RISCV_FEATURE_PMP)) { @@ -415,15 +451,15 @@ static RISCVException read_timeh(CPURISCVState *env, = int csrno, =20 /* Machine constants */ =20 -#define M_MODE_INTERRUPTS (MIP_MSIP | MIP_MTIP | MIP_MEIP) -#define S_MODE_INTERRUPTS (MIP_SSIP | MIP_STIP | MIP_SEIP) -#define VS_MODE_INTERRUPTS (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) -#define HS_MODE_INTERRUPTS (MIP_SGEIP | VS_MODE_INTERRUPTS) +#define M_MODE_INTERRUPTS ((uint64_t)(MIP_MSIP | MIP_MTIP | MIP_MEIP)) +#define S_MODE_INTERRUPTS ((uint64_t)(MIP_SSIP | MIP_STIP | MIP_SEIP)) +#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) +#define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) =20 -static const target_ulong delegable_ints =3D S_MODE_INTERRUPTS | +static const uint64_t delegable_ints =3D S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS; -static const target_ulong vs_delegable_ints =3D VS_MODE_INTERRUPTS; -static const target_ulong all_ints =3D M_MODE_INTERRUPTS | S_MODE_INTERRUP= TS | +static const uint64_t vs_delegable_ints =3D VS_MODE_INTERRUPTS; +static const uint64_t all_ints =3D M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | HS_MODE_INTERRUPTS; #define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \ (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \ @@ -672,40 +708,107 @@ static RISCVException write_medeleg(CPURISCVState *e= nv, int csrno, return RISCV_EXCP_NONE; } =20 -static RISCVException read_mideleg(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_mideleg64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - *val =3D env->mideleg; - return RISCV_EXCP_NONE; -} + uint64_t mask =3D wr_mask & delegable_ints; + + if (ret_val) { + *ret_val =3D env->mideleg; + } + + env->mideleg =3D (env->mideleg & ~mask) | (new_val & mask); =20 -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 HS_MODE_INTERRUPTS; } + return RISCV_EXCP_NONE; } =20 -static RISCVException read_mie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_mideleg(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_ma= sk) { - *val =3D env->mie; - return RISCV_EXCP_NONE; + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mideleg64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; } =20 -static RISCVException write_mie(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_midelegh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, + target_ulong wr_mask) { - env->mie =3D (env->mie & ~all_ints) | (val & all_ints); + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mideleg64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + +static RISCVException rmw_mie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + uint64_t mask =3D wr_mask & all_ints; + + if (ret_val) { + *ret_val =3D env->mie; + } + + env->mie =3D (env->mie & ~mask) | (new_val & mask); + if (!riscv_has_ext(env, RVH)) { - env->mie &=3D ~MIP_SGEIP; + env->mie &=3D ~((uint64_t)MIP_SGEIP); } + return RISCV_EXCP_NONE; } =20 +static RISCVException rmw_mie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_mieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + static RISCVException read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) { @@ -796,17 +899,17 @@ static RISCVException write_mtval(CPURISCVState *env,= int csrno, return RISCV_EXCP_NONE; } =20 -static RISCVException rmw_mip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_m= ask) +static RISCVException rmw_mip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { RISCVCPU *cpu =3D env_archcpu(env); /* Allow software control of delegable interrupts not claimed by hardw= are */ - target_ulong mask =3D write_mask & delegable_ints & ~env->miclaim; - uint32_t gin, old_mip; + uint64_t old_mip, mask =3D wr_mask & delegable_ints & ~env->miclaim; + uint32_t gin; =20 if (mask) { - old_mip =3D riscv_cpu_update_mip(cpu, mask, (new_value & mask)); + old_mip =3D riscv_cpu_update_mip(cpu, mask, (new_val & mask)); } else { old_mip =3D env->mip; } @@ -816,13 +919,44 @@ static RISCVException rmw_mip(CPURISCVState *env, int= csrno, old_mip |=3D (env->hgeip & ((target_ulong)1 << gin)) ? MIP_VSEIP := 0; } =20 - if (ret_value) { - *ret_value =3D old_mip; + if (ret_val) { + *ret_val =3D old_mip; } =20 return RISCV_EXCP_NONE; } =20 +static RISCVException rmw_mip(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_miph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + /* Supervisor Trap Setup */ static RISCVException read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) @@ -842,45 +976,112 @@ static RISCVException write_sstatus(CPURISCVState *e= nv, int csrno, return write_mstatus(env, CSR_MSTATUS, newval); } =20 -static RISCVException read_vsie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_vsie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - /* Shift the VS bits to their S bit location in vsie */ - *val =3D (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; - return RISCV_EXCP_NONE; + RISCVException ret; + uint64_t rval, vsbits, mask =3D env->hideleg & VS_MODE_INTERRUPTS; + + /* Bring VS-level bits to correct position */ + vsbits =3D new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &=3D ~(VS_MODE_INTERRUPTS >> 1); + new_val |=3D vsbits << 1; + vsbits =3D wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &=3D ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |=3D vsbits << 1; + + ret =3D rmw_mie64(env, csrno, &rval, new_val, wr_mask & mask); + if (ret_val) { + rval &=3D mask; + vsbits =3D rval & VS_MODE_INTERRUPTS; + rval &=3D ~VS_MODE_INTERRUPTS; + *ret_val =3D rval | (vsbits >> 1); + } + + return ret; } =20 -static RISCVException read_sie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_vsie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - if (riscv_cpu_virt_enabled(env)) { - read_vsie(env, CSR_VSIE, val); - } else { - *val =3D env->mie & env->mideleg; + uint64_t rval; + RISCVException ret; + + ret =3D rmw_vsie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; } - return RISCV_EXCP_NONE; + + return ret; } =20 -static RISCVException write_vsie(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_vsieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - /* Shift the S bits to their VS bit location in mie */ - target_ulong newval =3D (env->mie & ~VS_MODE_INTERRUPTS) | - ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS); - return write_mie(env, CSR_MIE, newval); + uint64_t rval; + RISCVException ret; + + ret =3D rmw_vsie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; } =20 -static int write_sie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException rmw_sie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { + RISCVException ret; + uint64_t mask =3D env->mideleg & S_MODE_INTERRUPTS; + if (riscv_cpu_virt_enabled(env)) { - write_vsie(env, CSR_VSIE, val); + ret =3D rmw_vsie64(env, CSR_VSIE, ret_val, new_val, wr_mask); } else { - target_ulong newval =3D (env->mie & ~S_MODE_INTERRUPTS) | - (val & S_MODE_INTERRUPTS); - write_mie(env, CSR_MIE, newval); + ret =3D rmw_mie64(env, csrno, ret_val, new_val, wr_mask & mask); } =20 - return RISCV_EXCP_NONE; + if (ret_val) { + *ret_val &=3D mask; + } + + return ret; +} + +static RISCVException rmw_sie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_sie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_sieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_sie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; } =20 static RISCVException read_stvec(CPURISCVState *env, int csrno, @@ -973,38 +1174,111 @@ static RISCVException write_stval(CPURISCVState *en= v, int csrno, return RISCV_EXCP_NONE; } =20 +static RISCVException rmw_vsip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + uint64_t rval, vsbits, mask =3D env->hideleg & vsip_writable_mask; + + /* Bring VS-level bits to correct position */ + vsbits =3D new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &=3D ~(VS_MODE_INTERRUPTS >> 1); + new_val |=3D vsbits << 1; + vsbits =3D wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &=3D ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |=3D vsbits << 1; + + ret =3D rmw_mip64(env, csrno, &rval, new_val, wr_mask & mask); + if (ret_val) { + rval &=3D mask; + vsbits =3D rval & VS_MODE_INTERRUPTS; + rval &=3D ~VS_MODE_INTERRUPTS; + *ret_val =3D rval | (vsbits >> 1); + } + + return ret; +} + static RISCVException rmw_vsip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_= mask) + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - /* Shift the S bits to their VS bit location in mip */ - int ret =3D rmw_mip(env, csrno, ret_value, new_value << 1, - (write_mask << 1) & vsip_writable_mask & env->hidele= g); + uint64_t rval; + RISCVException ret; =20 - if (ret_value) { - *ret_value &=3D VS_MODE_INTERRUPTS; - /* Shift the VS bits to their S bit location in vsip */ - *ret_value >>=3D 1; + ret =3D rmw_vsip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; } + return ret; } =20 -static RISCVException rmw_sip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_m= ask) +static RISCVException rmw_vsiph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - int ret; + uint64_t rval; + RISCVException ret; + + ret =3D rmw_vsip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + +static RISCVException rmw_sip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + uint64_t mask =3D env->mideleg & sip_writable_mask; =20 if (riscv_cpu_virt_enabled(env)) { - ret =3D rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); + ret =3D rmw_vsip64(env, CSR_VSIP, ret_val, new_val, wr_mask); } else { - ret =3D rmw_mip(env, csrno, ret_value, new_value, - write_mask & env->mideleg & sip_writable_mask); + ret =3D rmw_mip64(env, csrno, ret_val, new_val, wr_mask & mask); } =20 - if (ret_value) { - *ret_value &=3D env->mideleg & S_MODE_INTERRUPTS; + if (ret_val) { + *ret_val &=3D env->mideleg & S_MODE_INTERRUPTS; + } + + return ret; +} + +static RISCVException rmw_sip(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_sip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; } + + return ret; +} + +static RISCVException rmw_siph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_sip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + return ret; } =20 @@ -1099,30 +1373,94 @@ static RISCVException write_hedeleg(CPURISCVState *= env, int csrno, return RISCV_EXCP_NONE; } =20 -static RISCVException read_hideleg(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_hideleg64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - *val =3D env->hideleg; + uint64_t mask =3D wr_mask & vs_delegable_ints; + + if (ret_val) { + *ret_val =3D env->hideleg & vs_delegable_ints; + } + + env->hideleg =3D (env->hideleg & ~mask) | (new_val & mask); return RISCV_EXCP_NONE; } =20 -static RISCVException write_hideleg(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_hideleg(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_ma= sk) { - env->hideleg =3D val & vs_delegable_ints; - return RISCV_EXCP_NONE; + uint64_t rval; + RISCVException ret; + + ret =3D rmw_hideleg64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_hidelegh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_m= ask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_hideleg64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + +static RISCVException rmw_hvip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + + ret =3D rmw_mip64(env, csrno, ret_val, new_val, + wr_mask & hvip_writable_mask); + if (ret_val) { + *ret_val &=3D VS_MODE_INTERRUPTS; + } + + return ret; } =20 static RISCVException rmw_hvip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_= mask) + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - int ret =3D rmw_mip(env, csrno, ret_value, new_value, - write_mask & hvip_writable_mask); + uint64_t rval; + RISCVException ret; =20 - if (ret_value) { - *ret_value &=3D VS_MODE_INTERRUPTS; + ret =3D rmw_hvip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_hviph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_hvip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; } + return ret; } =20 @@ -1139,18 +1477,19 @@ static RISCVException rmw_hip(CPURISCVState *env, i= nt csrno, return ret; } =20 -static RISCVException read_hie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_hie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - *val =3D env->mie & HS_MODE_INTERRUPTS; - return RISCV_EXCP_NONE; -} + uint64_t rval; + RISCVException ret; =20 -static RISCVException write_hie(CPURISCVState *env, int csrno, - target_ulong val) -{ - target_ulong newval =3D (env->mie & ~HS_MODE_INTERRUPTS) | (val & HS_M= ODE_INTERRUPTS); - return write_mie(env, CSR_MIE, newval); + ret =3D rmw_mie64(env, csrno, &rval, new_val, wr_mask & HS_MODE_INTERR= UPTS); + if (ret_val) { + *ret_val =3D rval & HS_MODE_INTERRUPTS; + } + + return ret; } =20 static RISCVException read_hcounteren(CPURISCVState *env, int csrno, @@ -1870,9 +2209,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Machine Trap Setup */ [CSR_MSTATUS] =3D { "mstatus", any, read_mstatus, write_m= status }, [CSR_MISA] =3D { "misa", any, read_misa, write_m= isa }, - [CSR_MIDELEG] =3D { "mideleg", any, read_mideleg, write_m= ideleg }, + [CSR_MIDELEG] =3D { "mideleg", any, NULL, NULL, rmw_mid= eleg }, [CSR_MEDELEG] =3D { "medeleg", any, read_medeleg, write_m= edeleg }, - [CSR_MIE] =3D { "mie", any, read_mie, write_m= ie }, + [CSR_MIE] =3D { "mie", any, NULL, NULL, rmw_mie= }, [CSR_MTVEC] =3D { "mtvec", any, read_mtvec, write_m= tvec }, [CSR_MCOUNTEREN] =3D { "mcounteren", any, read_mcounteren, write_m= counteren }, =20 @@ -1885,9 +2224,14 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MTVAL] =3D { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] =3D { "mip", any, NULL, NULL, rmw_mip }, =20 + /* Machine-Level High-Half CSRs (AIA) */ + [CSR_MIDELEGH] =3D { "midelegh", aia_any32, NULL, NULL, rmw_midelegh }, + [CSR_MIEH] =3D { "mieh", aia_any32, NULL, NULL, rmw_mieh }, + [CSR_MIPH] =3D { "miph", aia_any32, NULL, NULL, rmw_miph }, + /* Supervisor Trap Setup */ [CSR_SSTATUS] =3D { "sstatus", smode, read_sstatus, write_sst= atus }, - [CSR_SIE] =3D { "sie", smode, read_sie, write_sie= }, + [CSR_SIE] =3D { "sie", smode, NULL, NULL, rmw_sie = }, [CSR_STVEC] =3D { "stvec", smode, read_stvec, write_stv= ec }, [CSR_SCOUNTEREN] =3D { "scounteren", smode, read_scounteren, write_sco= unteren }, =20 @@ -1901,12 +2245,16 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Supervisor Protection and Translation */ [CSR_SATP] =3D { "satp", smode, read_satp, write_satp = }, =20 + /* Supervisor-Level High-Half CSRs (AIA) */ + [CSR_SIEH] =3D { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, + [CSR_SIPH] =3D { "siph", aia_smode32, NULL, NULL, rmw_siph }, + [CSR_HSTATUS] =3D { "hstatus", hmode, read_hstatus, writ= e_hstatus }, [CSR_HEDELEG] =3D { "hedeleg", hmode, read_hedeleg, writ= e_hedeleg }, - [CSR_HIDELEG] =3D { "hideleg", hmode, read_hideleg, writ= e_hideleg }, + [CSR_HIDELEG] =3D { "hideleg", hmode, NULL, NULL, rmw_= hideleg }, [CSR_HVIP] =3D { "hvip", hmode, NULL, NULL, rmw_= hvip }, [CSR_HIP] =3D { "hip", hmode, NULL, NULL, rmw_= hip }, - [CSR_HIE] =3D { "hie", hmode, read_hie, writ= e_hie }, + [CSR_HIE] =3D { "hie", hmode, NULL, NULL, rmw_= hie }, [CSR_HCOUNTEREN] =3D { "hcounteren", hmode, read_hcounteren, writ= e_hcounteren }, [CSR_HGEIE] =3D { "hgeie", hmode, read_hgeie, writ= e_hgeie }, [CSR_HTVAL] =3D { "htval", hmode, read_htval, writ= e_htval }, @@ -1918,7 +2266,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { =20 [CSR_VSSTATUS] =3D { "vsstatus", hmode, read_vsstatus, writ= e_vsstatus }, [CSR_VSIP] =3D { "vsip", hmode, NULL, NULL, rmw_= vsip }, - [CSR_VSIE] =3D { "vsie", hmode, read_vsie, writ= e_vsie }, + [CSR_VSIE] =3D { "vsie", hmode, NULL, NULL, rmw_= vsie }, [CSR_VSTVEC] =3D { "vstvec", hmode, read_vstvec, writ= e_vstvec }, [CSR_VSSCRATCH] =3D { "vsscratch", hmode, read_vsscratch, writ= e_vsscratch }, [CSR_VSEPC] =3D { "vsepc", hmode, read_vsepc, writ= e_vsepc }, @@ -1929,6 +2277,12 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MTVAL2] =3D { "mtval2", hmode, read_mtval2, writ= e_mtval2 }, [CSR_MTINST] =3D { "mtinst", hmode, read_mtinst, writ= e_mtinst }, =20 + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ + [CSR_HIDELEGH] =3D { "hidelegh", aia_hmode32, NULL, NULL, rmw_hi= delegh }, + [CSR_HVIPH] =3D { "hviph", aia_hmode32, NULL, NULL, rmw_hv= iph }, + [CSR_VSIEH] =3D { "vsieh", aia_hmode32, NULL, NULL, rmw_vs= ieh }, + [CSR_VSIPH] =3D { "vsiph", aia_hmode32, NULL, NULL, rmw_vs= iph }, + /* Physical Memory Protection */ [CSR_MSECCFG] =3D { "mseccfg", epmp, read_mseccfg, write_mseccfg }, [CSR_PMPCFG0] =3D { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index cffc444969..44dca84ded 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -84,7 +84,7 @@ static const VMStateDescription vmstate_hyper =3D { .fields =3D (VMStateField[]) { VMSTATE_UINTTL(env.hstatus, RISCVCPU), VMSTATE_UINTTL(env.hedeleg, RISCVCPU), - VMSTATE_UINTTL(env.hideleg, RISCVCPU), + VMSTATE_UINT64(env.hideleg, RISCVCPU), VMSTATE_UINTTL(env.hcounteren, RISCVCPU), VMSTATE_UINTTL(env.htval, RISCVCPU), VMSTATE_UINTTL(env.htinst, RISCVCPU), @@ -194,10 +194,10 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.resetvec, RISCVCPU), VMSTATE_UINTTL(env.mhartid, RISCVCPU), VMSTATE_UINT64(env.mstatus, RISCVCPU), - VMSTATE_UINTTL(env.mip, RISCVCPU), - VMSTATE_UINT32(env.miclaim, RISCVCPU), - VMSTATE_UINTTL(env.mie, RISCVCPU), - VMSTATE_UINTTL(env.mideleg, RISCVCPU), + VMSTATE_UINT64(env.mip, RISCVCPU), + VMSTATE_UINT64(env.miclaim, RISCVCPU), + VMSTATE_UINT64(env.mie, RISCVCPU), + VMSTATE_UINT64(env.mideleg, RISCVCPU), VMSTATE_UINTTL(env.satp, RISCVCPU), VMSTATE_UINTTL(env.stval, RISCVCPU), VMSTATE_UINTTL(env.medeleg, RISCVCPU), --=20 2.25.1