From patchwork Mon Jan 14 23:57:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="arKX/fuF"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="H0r6ZP4F"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dr8L0T3wz9s3q for ; Tue, 15 Jan 2019 11:00:50 +1100 (AEDT) Received: from localhost ([127.0.0.1]:46938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC9v-00051O-Sz for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 19:00:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC78-0003Lg-LV for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:57:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC77-0008Vv-4R for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:57:54 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37581) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC76-0008VI-Pc; Mon, 14 Jan 2019 18:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510273; x=1579046273; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=IonCrrBwRjNJSQbOSqo9wYC/kkq/iniDOOLQwPr/BWU=; b=arKX/fuFv+ks2cakizXiaaJPuq7++4URkVorT2RmSt7oez2vf/wWz8wX eg4+7ZR3kOhp2+eT11mTtKFapWdiXGl2d6xzFey+jTlQIGe1p1D+WeN8q ao0AFdi36GyU5hce/TMu0gAgVlT2Q356tcErQQxADSAtyDTyD2MAtTArl Z2z8p7ZvP2IZnxO90jpx7W7pKC/wgIB++D3o8ZOOV0HmumMMKck1aRp6U I3XjUZnyWsvz3/F0p0gIfcOLyYnP27mO5YXdq9w//gmSWwUghvrJynDPY f/qh1ppcf8AQseeyXIlNxzHatKjggIHemPNqgU9XKOg/dgV8VEzXXfJ5O Q==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="100549138" Received: from mail-by2nam03lp2058.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.58]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:57:51 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l9H7475fvlAWvRjNGS8I0qnLM0kuBeL6F2Lf+C24AGA=; b=H0r6ZP4FT3NS1y4PFu2bxeJn0AHD3YOpYXtjHv7UhD7T0QICoeUlGBAvFI5OJUMBdY00QOIWASirWQyYk9pg5qxEYPvyhRBFb55K2suxlVrnm06WzUOKkn4qvSDZmeTIBtyH1uRiQ91aI3Lw0YiwOD1QKGS837/h7GFHvt+eSUE= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:57:50 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:57:50 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 1/8] RISC-V: Split out mstatus_fs from tb_flags Thread-Index: AQHUrGT0FdAhRKkQwkqbBBZ1tlwNeQ== Date: Mon, 14 Jan 2019 23:57:50 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: MWHPR20CA0038.namprd20.prod.outlook.com (2603:10b6:300:ed::24) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:5vCwtVSpyRPGym9H6Emd6Nwd/nmmzDdNEQUIiCv7Q5o9FDYvDLTDSNRzWQc7OkB4LfpOsA/5eI8O4ZBWSePWjVDR4EmF5RRc6nydB5hWWNsoJjzDnwqPag0dAmT517gQNubbXb9Y+oZIfA7qkaUsjjTUg38mXo143q+dX91bGVCUDoZh/XqVvh7sz88aWzhspMt6xhkRg4T8bjwk4auxVMwBRUHWXW+xRofwcv4Av1S3Q8AtN8lrkMJvmmXevtVmlfHYJSZ3V0lJpGR/PrTgj2dvp2FYHf8JVYWSQAgrIkNFLIEitpeuGhsuGB3EUqdoZVUmz/2VyO1+vZa0dmQbdeeK/JTv59iyjNkpTYK3PyktqVMCxMr6W6B9hEb2T/s9764XP80WHWl+fkEA2tUPxSEBNFO/DwlXE3Hs9eu/AIOqT3bw8mt9swI793D/pOm3rww0XfmDhxG051lojCCjTw==; 5:GkpnmMaqt258aUUrCvrTGCjf/4TH8K2MWL8yGS1kBLaRF1SSqkErNqMr5q32Y2LlLwMRyQ3jxqqHMykwOjqdSBuZmjSxwXQSFEOCElZhdIOf3Mcj7jpRpzdLzbaWf8Clan/a/Xbq3GaAsKTpPplHcotKBzXTu374JFQU82/W3UgV7mu5DcgfiT/4S/1PNAAs5TPSjV8aQ6qQlPD6npZmqQ==; 7:TeR/yxeFoQZmuI2eTKtXena8EVxjUBJFxC/cXhhhoA1rLMcMmB5oqizD8L5LBEDfckUWJIx/DxhTF81UzHSGbuz151W1Z56f58Hr+XheF4/T1G5zX+fWiH5Jkx0mAJ2LJWfVsViO1RuQ2mNV21npiA== x-ms-office365-filtering-correlation-id: f2347940-e678-4e19-5c1e-08d67a7c1706 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(386003)(6506007)(68736007)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(26005)(446003)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: /p6q+66dO6SSDD94fKYsAz6LoUtuMyZEirniKqQ53ZnezsDEtwJH3hhN3KcJ5FEg5iU7kjiIWmNVMi7kl7y68YsfyWhGi7eaGA2/b+Hzl6GN/iCMwTx1gPIO0bENvnqwG5frtZRUDz4sGAmsI4a4KOjH7Df67nPdmPw4nLRc5qVHjzbXC1FU9VxbeBrx1Buy9VleL6KbJVLGhT6XSE7MLxM96RwHf+X+7DUtu791MX2HF/nS6A/gAvZK5WTcsiLo6n4wDas17gfH8Q2H1XHqXbqXIq9p1MOasyJreLjHqbEyTqma8oEknDHlCsBMk6gjUlCvl5407ko/5Le4RhJlcAjWaWiLz3JXdh+J3pq3yaQiHnChqUoVDHVxKO1Y7GfaOahmHKVJH/hl3ANPpdQQEBGrH3aQA3i7ZQazlR5+NlA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2347940-e678-4e19-5c1e-08d67a7c1706 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:57:49.8818 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.45 Subject: [Qemu-devel] [PATCH v1 1/8] RISC-V: Split out mstatus_fs from tb_flags X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Richard Henderson Signed-off-by: Michael Clark Reviewed-by: Michael Clark Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 6 +++--- target/riscv/translate.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 743f02c8b9..681341f5d5 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -275,8 +275,8 @@ void QEMU_NORETURN do_raise_exception_err(CPURISCVState *env, target_ulong cpu_riscv_get_fflags(CPURISCVState *env); void cpu_riscv_set_fflags(CPURISCVState *env, target_ulong); -#define TB_FLAGS_MMU_MASK 3 -#define TB_FLAGS_FP_ENABLE MSTATUS_FS +#define TB_FLAGS_MMU_MASK 3 +#define TB_FLAGS_MSTATUS_FS MSTATUS_FS static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, target_ulong *cs_base, uint32_t *flags) @@ -284,7 +284,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, *pc = env->pc; *cs_base = 0; #ifdef CONFIG_USER_ONLY - *flags = TB_FLAGS_FP_ENABLE; + *flags = TB_FLAGS_MSTATUS_FS; #else *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS); #endif diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 312bf298b3..3d07d651b6 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -44,7 +44,7 @@ typedef struct DisasContext { /* pc_succ_insn points to the instruction following base.pc_next */ target_ulong pc_succ_insn; uint32_t opcode; - uint32_t flags; + uint32_t mstatus_fs; uint32_t mem_idx; /* Remember the rounding mode encoded in the previous fp instruction, which we have already installed into env->fp_status. Or -1 for @@ -656,7 +656,7 @@ static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, { TCGv t0; - if (!(ctx->flags & TB_FLAGS_FP_ENABLE)) { + if (ctx->mstatus_fs == 0) { gen_exception_illegal(ctx); return; } @@ -686,7 +686,7 @@ static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1, { TCGv t0; - if (!(ctx->flags & TB_FLAGS_FP_ENABLE)) { + if (ctx->mstatus_fs == 0) { gen_exception_illegal(ctx); return; } @@ -945,7 +945,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, { TCGv t0 = NULL; - if (!(ctx->flags & TB_FLAGS_FP_ENABLE)) { + if (ctx->mstatus_fs == 0) { goto do_illegal; } @@ -1818,8 +1818,8 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) DisasContext *ctx = container_of(dcbase, DisasContext, base); ctx->pc_succ_insn = ctx->base.pc_first; - ctx->flags = ctx->base.tb->flags; ctx->mem_idx = ctx->base.tb->flags & TB_FLAGS_MMU_MASK; + ctx->mstatus_fs = ctx->base.tb->flags & TB_FLAGS_MSTATUS_FS; ctx->frm = -1; /* unknown rounding mode */ } From patchwork Mon Jan 14 23:57:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="nlDyFkKt"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="E//DsLfW"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43drDL1m8jz9s3l for ; Tue, 15 Jan 2019 11:04:18 +1100 (AEDT) Received: from localhost ([127.0.0.1]:47794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjCDG-0007by-RX for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 19:04:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC7K-0003X2-IB for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC7I-0000J4-GF for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:06 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC7I-0000Hi-7i; Mon, 14 Jan 2019 18:58:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510285; x=1579046285; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=i+lFi+aCAJEl9mmnqQ3ezawmHCqe3yek8lEo71ONyDg=; b=nlDyFkKt/cvTbglxaWYw63jhxhmK+7REUqaQQJGqT0Ruzc+K16ErVfWu lSqSx2CNnYYFgeHa6F+6fvDIYFFKNO7vd8FNSs8b6SW7z5J9f3nmt/UTB riuz13rWVG9fyZKr+rmZoG1AA+2paSknVOw4OJ5tDOCubAbeEScY61DBY 0vEVwEpbBXRjlx14ZhmXLSrbgHo3LLHBP6kAD28MchfcmKbCcjAbYBSXR fefhZAp5BuYozZHa8PMcMtC+yD77tCAc3LIM/acuxT5zEk+501QdwN/kh ye2Wfya5cCCYkufJkRzCwy3ohJdA837+iF8g+4xQvL0Z3gbtEqoF4icNT w==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765680" Received: from mail-by2nam03lp2059.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.59]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:03 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZhQpmcwdslTXA/zrPWJr/0tcictWCciVueDS5m1iYxE=; b=E//DsLfWtHZPKG5zalW1vobVo4sSO3P2u9OD4V5jPCxhKLCMQZVYyhAsz5ChtRBWIFHzMBCJlNd8LAT8Wjk0euOLpnrtvAzRyQZgYmNLcH+6+Uq9tpDXjT3BA5RhUrsQA5ybghmPUK63iq0IekKfpCsp1hR+t+XXQtia8owiHXw= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:57:59 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:57:59 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 2/8] RISC-V: Mark mstatus.fs dirty Thread-Index: AQHUrGT6TH7Q+oyNaU+G4s+WsxRZzQ== Date: Mon, 14 Jan 2019 23:57:59 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: MWHPR20CA0026.namprd20.prod.outlook.com (2603:10b6:300:ed::12) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:vpswrbZqLFhZRu9yVigepWRH/UuA354R41WiutrXxAoop5+jyCRTNTckjlc6LltO5yq7SY8UDcKEKf44EDi2Ah/YsNJ4+ZRyPMS2F9ufZalzjli8t0DkxhyzJCY3RBnk9odomEKjJCOm9MroPH4jkjcTo83XF34wblTf3jRAoEJId2lOVa2lc00w4CVjug4D64AYcK0krsOxfhej45AHc/DVb/2MztRzfmbCnPrbtpQ+C11KwQ0QewJ4wxkQWcqio9CfE4cXV3QQE4EogjsZFrg11WzucDRoXNkVvqRPx0PMuDt02y82Zg6yWnLpDaWfURa2vvKB/hvJtjMjAwQsoinL5Kh/CYvgykcTSG3MQPyIg0r1m5bmx8QUnYzT7eCJYXZ9xUr27gcWgAEp8MosGJQy5xF6wT4LXEi9wxdfhNKzChQ2vUPc0Au11gdjBOe7a4W2jDyZj9gbp2BCBdFJqQ==; 5:nSMAsRXnrIjtm/H/TrE3EJkAzy9328HeOvAPaLJgVxJvxkoKZOu1GQ4aFL0eBdMwZ3BEG4Qi9MQ3MI27hnT5VcBXPeP5tP5sCWJb5CPpgp+HCjbozvt3xBnfs+HlS27DexiVom3bOGneImrw/Wkhk3E3lDwmHuiS6dzJstJuclDo+qT7GSI6K7WVuVbf0ro4rann7g2VZZmxwHjhO12FqQ==; 7:ZfKgwEVnlqNmzNM8e3NTWzOIt1Q+TVYkFP0zmMmsOGkz2gLlkAKU++etW9TeVyxgElPKeSw0C4xRrzWXEcIFMEroupeIbDUT5EL3O11O9i4iowudIW/OLjp398YDkx+R4zJH5rA5wYq47ySAbG64+A== x-ms-office365-filtering-correlation-id: c5519a06-e579-4483-69c6-08d67a7c1c74 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(14444005)(386003)(6506007)(68736007)(966005)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(6306002)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(26005)(446003)(86362001)(14143004); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 1XbFwOu43z78wY5wdf6qqmuhgoI5qh7H+QQrILOsz0oOV0eVQiuvIm0XKL09ty+P9JXeKGTjU4OHn7yBh/EI52LhRVMddoJO4UKWojPpKraZze9rDXitnLd7uQ6JN2TlQ0hVEAVZRvN3h5FTiA0a0d5hqX7EFvjzD03oa5+trrl3aq70MM7khwyMaK6C3nhXu8zXE9FGR1huY/L+ThB/8r6rXqkc7h503qpzAImzMO94hcdpRjuT38xlaeiruYsIzzPipXYcj4Tv6WKChXGAI0Co88+AJ0VnHvMUSicU1Lmcr+dc2oFuQxhC3rgj/WVfjCPoRz2YlRtbvWoiW3/+ol8TMGZunFK7BGVnB6t5VV/MNp4p3IinT5QgFBZzy3RNHEh8FWMk9sQYSfN2ge/klkjbztumA2cSP41oULKyuC8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5519a06-e579-4483-69c6-08d67a7c1c74 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:57:58.9917 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 2/8] RISC-V: Mark mstatus.fs dirty X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Modifed from Richard Henderson's patch [1] to integrate with the new control and status register implementation. [1] https://lists.nongnu.org/archive/html/qemu-devel/2018-03/msg07034.html Note: the f* CSRs already mark mstatus.FS dirty using env->mstatus |= mstatus.FS so the bug in the first spin of this patch has been fixed in a prior commit. Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Richard Henderson Signed-off-by: Michael Clark Reviewed-by: Michael Clark Signed-off-by: Alistair Francis Co-authored-by: Richard Henderson Co-authored-by: Michael Clark --- target/riscv/csr.c | 12 ------------ target/riscv/translate.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5e7e7d16b8..5714147689 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -317,18 +317,6 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) mstatus = (mstatus & ~mask) | (val & mask); - /* Note: this is a workaround for an issue where mstatus.FS - does not report dirty after floating point operations - that modify floating point state. This workaround is - technically compliant with the RISC-V Privileged - specification as it is legal to return only off, or dirty. - at the expense of extra floating point save/restore. */ - - /* FP is always dirty or off */ - if (mstatus & MSTATUS_FS) { - mstatus |= MSTATUS_FS; - } - int dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) | ((mstatus & MSTATUS_XS) == MSTATUS_XS); mstatus = set_field(mstatus, MSTATUS_SD, dirty); diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 3d07d651b6..0581b3c1f7 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -651,6 +651,31 @@ static void gen_store(DisasContext *ctx, uint32_t opc, int rs1, int rs2, tcg_temp_free(dat); } +#ifndef CONFIG_USER_ONLY +/* The states of mstatus_fs are: + * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty + * We will have already diagnosed disabled state, + * and need to turn initial/clean into dirty. + */ +static void mark_fs_dirty(DisasContext *ctx) +{ + TCGv tmp; + if (ctx->mstatus_fs == MSTATUS_FS) { + return; + } + /* Remember the state change for the rest of the TB. */ + ctx->mstatus_fs = MSTATUS_FS; + + tmp = tcg_temp_new(); + tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); + tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); + tcg_temp_free(tmp); +} +#else +static inline void mark_fs_dirty(DisasContext *ctx) { } +#endif + static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, int rs1, target_long imm) { @@ -679,6 +704,8 @@ static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, break; } tcg_temp_free(t0); + + mark_fs_dirty(ctx); } static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1, @@ -944,6 +971,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, int rs2, int rm) { TCGv t0 = NULL; + bool fp_output = true; if (ctx->mstatus_fs == 0) { goto do_illegal; @@ -1006,6 +1034,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } gen_set_gpr(rd, t0); tcg_temp_free(t0); + fp_output = false; break; case OPC_RISC_FCVT_W_S: @@ -1035,6 +1064,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } gen_set_gpr(rd, t0); tcg_temp_free(t0); + fp_output = false; break; case OPC_RISC_FCVT_S_W: @@ -1085,6 +1115,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } gen_set_gpr(rd, t0); tcg_temp_free(t0); + fp_output = false; break; case OPC_RISC_FMV_S_X: @@ -1177,6 +1208,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } gen_set_gpr(rd, t0); tcg_temp_free(t0); + fp_output = false; break; case OPC_RISC_FCVT_W_D: @@ -1206,6 +1238,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } gen_set_gpr(rd, t0); tcg_temp_free(t0); + fp_output = false; break; case OPC_RISC_FCVT_D_W: @@ -1254,6 +1287,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, default: goto do_illegal; } + fp_output = false; break; #if defined(TARGET_RISCV64) @@ -1271,7 +1305,11 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, tcg_temp_free(t0); } gen_exception_illegal(ctx); - break; + return; + } + + if (fp_output) { + mark_fs_dirty(ctx); } } From patchwork Mon Jan 14 23:58:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="VVE9kZ9F"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="ILJWLBjD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dr6569Hrz9s2P for ; Tue, 15 Jan 2019 10:58:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:46467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC83-0003gU-SG for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 18:58:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC7Z-0003f4-AT for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC7T-0000Ua-AY for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:17 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59843) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC7P-0000Qi-8c; Mon, 14 Jan 2019 18:58:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510292; x=1579046292; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=3smbf5frSpe93gHGpJPlYqSXqqqaOmk52V7Ej3pj3TE=; b=VVE9kZ9F52n+eiLE9TTwWviLNo63ui7YcjOz5qqj7MB+mqYvU6niSSoX TqHl55d+K0vOK7jUM0ej8rAl1h/2qin4rBxAP8k7Ylg+SJy787QZKd6q0 Ya8AfF6QWxZmrj8tOSu+y5T6XBAsa1RGk/ep2chqZh8jIfUwu+cxxWLpd KoX7xUfgDpF/QEMhlMMibg0hcNqZH+idwcIjP3yOYdXXoPbYV9OhoOmHh rPGvzzdGuyaVUNBzT/NPy51lbrqq2uzS00f9yOa7qJQuDoEKtjFiCWRc4 4DBfiaWcuck5wb00NRTKsmK+d5PTsEIEVi1c8IoDeP20LWYlzW8cfPYN7 g==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765684" Received: from mail-by2nam03lp2056.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.56]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:10 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NoHUUstuZPomDehsTxgZ2TwkLQHHELr1TcsjGvKIYGM=; b=ILJWLBjD7nwfH6l/e8Uu6WNitiO/8VUE8hO3OxoIMFXkBpRnZsexd0MAulKYCSFigouGVEVluOv44QZ+a6tm1wQ4c4wtxZ+tQrAdCzTo95DAyVQ5d+YKbAV1fghUaD2nWjEyK8+OinR8ZRk+8l/1BJyD3turSv5OXgqEzDZgQnc= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:58:08 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:58:08 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 3/8] RISC-V: Implement mstatus.TSR/TW/TVM Thread-Index: AQHUrGT/ENV0Pl66UUaKSb8PwPK3aA== Date: Mon, 14 Jan 2019 23:58:08 +0000 Message-ID: <1fb62bc8ef624c022bcf5553b8e8d9512b328823.1547510220.git.alistair.francis@wdc.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: MWHPR20CA0036.namprd20.prod.outlook.com (2603:10b6:300:ed::22) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:c3DRqO6s7BEAKKkAmoz7njZKQZSscEShYiT0+heYhTeHSwcLaUE+Z5awUpiu0sLlW5imNFP7fQ499GhzFZSqev/4pyi2Q5F8TMW4X2fAWBs9/9gFNt7zlshKYYMeVFeCUS8paAnlnOoHbB6TOkDCUH77wTgFxyyD61NZdX3tC0w5tm1da/ng6Nq4v2kHFmNLB7l/VtIqztT2EVTupifc16azfdHv3yIll7eOSuLoAwlfoOzHh6Jc4iIwujtmFz/6Ug2oKbKGfmYg0sBD2UaqdiLlGRH/vZj+yVYUfetHH1kqEXZC61dqDkV3keF6PLAALAUf9udJ+ri2JtTKzPbuuH/qfACPvOEr+iyzRhWrcF7Vol/h7olH3iI0qljk7Pos+U3xN7SQ7UUS7yWCtSFYnj5VqoflfXUqcGckx/pXRfBanHayvmJFcQCm4Lriy5/WNOfcEzR59pttoz0BYtjong==; 5:fUHJ9bEkUVAdKRsK2yeG1Hnvjh1Sopl1krgjWCZeUV594k3U+dWfP0MW/THp9odoWmUvA9SvO9FH70kETolt6eTejtiE4ehMgya4EGyLhTHM2+WcbvTh12xDkFj2MYVuoP8i777h3zv9r4jX35drPAT5H7X5orASJb6NhlJUBJqlwivkqM+0zknSx325Qhlbs3VgLm3bPona/ixXxVZXWQ==; 7:0702MQEgtNIb46nOzxbUtkAy7HWAOLEzWAvvAxx9We7BJ7U+TXw5R5ZdkIJB69eT/1GXBB+b8mFN5UpHWbuOJGIzs3porotZBTcPcHnOMCBXcA3wPKg98XdMEgBzwn+5op6t0LB9eNvnGfQRKHWRVw== x-ms-office365-filtering-correlation-id: d8a5ec49-f9dc-4a16-cab9-08d67a7c21e9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(14444005)(386003)(6506007)(68736007)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(26005)(446003)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 12DCLRFWGq7vyXK6Z7R6MJ9Lqs6WrDXJoCam+iRftvDgth6opVRX7CihQCoTUm7s0FxEAeesLAIOt2f3acOlvD9E4MfVHtffvQ+0M0WouLWyuBF9AS2h+x9ec1SRNLJ6MHUEqYaSQexEpIFdnKjZ5C0UEQCRderHpAmbkQgg7zkYFx5Wa5VHjWwRPgxsyIG10rn6u0WbMKA+7qwEdBv46XDh8ee3CcDo1AFTrFIK0MF4SmNma/X6477vvcnUvPMJ0UlZyTd0Nrcks2xXSo5894hDFr/tEiBZJKYAKZcixCFv1nFYF6gsMJrbhJ4kumg6AJIfjyNDDUCBxELT9sg79bzWCXv0pFoAR52eT06uSxmysbgn3lNcYJbV1D8w3nXnjAO6DDGEM2GnzTIpJvVHq3i7T45yBq1v9Y3/jOb7QKA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8a5ec49-f9dc-4a16-cab9-08d67a7c21e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:58:08.1495 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 3/8] RISC-V: Implement mstatus.TSR/TW/TVM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Clark This adds the necessary minimum to support S-mode virtualization for priv ISA >= v1.10 Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Matthew Suozzo Signed-off-by: Michael Clark Signed-off-by: Alistair Francis Co-authored-by: Matthew Suozzo Co-authored-by: Michael Clark --- target/riscv/csr.c | 17 +++++++++++++---- target/riscv/op_helper.c | 25 +++++++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5714147689..390d3a9a56 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -305,7 +305,8 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) } mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM | - MSTATUS_MPP | MSTATUS_MXR; + MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR | + MSTATUS_TW; } /* silenty discard mstatus.mpp writes for unsupported modes */ @@ -642,7 +643,11 @@ static int read_satp(CPURISCVState *env, int csrno, target_ulong *val) if (!riscv_feature(env, RISCV_FEATURE_MMU)) { *val = 0; } else if (env->priv_ver >= PRIV_VERSION_1_10_0) { - *val = env->satp; + if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { + return -1; + } else { + *val = env->satp; + } } else { *val = env->sptbr; } @@ -663,8 +668,12 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) validate_vm(env, get_field(val, SATP_MODE)) && ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) { - tlb_flush(CPU(riscv_env_get_cpu(env))); - env->satp = val; + if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { + return -1; + } else { + tlb_flush(CPU(riscv_env_get_cpu(env))); + env->satp = val; + } } return 0; } diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 81bd1a77ea..77c79ba36e 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -82,6 +82,11 @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) do_raise_exception_err(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } + if (env->priv_ver >= PRIV_VERSION_1_10_0 && + get_field(env->mstatus, MSTATUS_TSR)) { + do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + } + target_ulong mstatus = env->mstatus; target_ulong prev_priv = get_field(mstatus, MSTATUS_SPP); mstatus = set_field(mstatus, @@ -125,16 +130,28 @@ void helper_wfi(CPURISCVState *env) { CPUState *cs = CPU(riscv_env_get_cpu(env)); - cs->halted = 1; - cs->exception_index = EXCP_HLT; - cpu_loop_exit(cs); + if (env->priv == PRV_S && + env->priv_ver >= PRIV_VERSION_1_10_0 && + get_field(env->mstatus, MSTATUS_TW)) { + do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + } else { + cs->halted = 1; + cs->exception_index = EXCP_HLT; + cpu_loop_exit(cs); + } } void helper_tlb_flush(CPURISCVState *env) { RISCVCPU *cpu = riscv_env_get_cpu(env); CPUState *cs = CPU(cpu); - tlb_flush(cs); + if (env->priv == PRV_S && + env->priv_ver >= PRIV_VERSION_1_10_0 && + get_field(env->mstatus, MSTATUS_TVM)) { + do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + } else { + tlb_flush(cs); + } } #endif /* !CONFIG_USER_ONLY */ From patchwork Mon Jan 14 23:58:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="cJGSSI6R"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="QVsOhkyT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dr6y6jp0z9s3l for ; Tue, 15 Jan 2019 10:59:38 +1100 (AEDT) Received: from localhost ([127.0.0.1]:46627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC8m-00044s-UA for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 18:59:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC85-00041D-8R for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC83-0000zQ-D9 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:53 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59875) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC7x-0000px-8k; Mon, 14 Jan 2019 18:58:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510326; x=1579046326; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=9uv5XLEJUqNzKvmM/cSQcNjMJc0kPMeYCKDCfhDB+U4=; b=cJGSSI6R0DU6PpxIBdPxVQVUQUW4VsH5GeTlmmPhBF+K809kgErzBItD LTViCBtmm7uccAzCcb28so50bUzkDNzISTmYpSinllW8QKNX7yfV+3q1p 3G1kNvRhYzbOypzxZ1BINtn9uS5ZTqiAufAXDxEbBdhngpC2BXA9Jjwr7 texe5peBKn8NryTtbmwx0r7GgPE5BMLTkmQrnnY6RC0V+sp+pap1tN8+H omXK7ZkCsgJWRH/HBpw7+NflP/8uQAUmalQZGehfJkqPgqYp11UNfuD3m dnr31lia1GpfhzIh9Sl+6F5irlLsHk+X0EcosE5mW8RJIxH/pE7anQjoI g==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765700" Received: from mail-by2nam03lp2053.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.53]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:40 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kfSSrjzTL3Z6RoPiXSM2DgcZrSahpqsjykiwt/RlHJ4=; b=QVsOhkyTG7QfP2REEktFCX9PEH5h/YXloyf4RlXUMrvQRiCO27an5EEH4GiV3Dy70MDOki6ejvXcnMYk75ktr++40aiTT/LbwFQ96eH9Sdw5WDvjTxjqQmwBqcVZaqEpZBFbB728k2jd5WNLz0svJKG2Tzy4LBvkjhl3GyGcNqE= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:58:23 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:58:23 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 4/8] RISC-V: Use riscv prefix consistently on cpu helpers Thread-Index: AQHUrGUI8St4cjPcB0C3qAWLtO8Hug== Date: Mon, 14 Jan 2019 23:58:23 +0000 Message-ID: <20ba320ced470eed0f16b39e01b1bf8c24dbd3c4.1547510220.git.alistair.francis@wdc.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: MWHPR20CA0032.namprd20.prod.outlook.com (2603:10b6:300:ed::18) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:WkaOWrIDG8zMouPuQ2FePezmZ0/Mf2nyIL2+r9RbtKZpuy2Hqas7fGBhG3pPnZ0M8yTqu2bi1XU72NPTycHhHKXbYaDwTMossmqJQZBQCAxR1EDaWa8IrvfWVk3UYk1dyTQjXy4Dx5gq91sUrji69yYSz6GbExgRhnC1GrKOn7E3cXb0UZfGTMkqPGaiLYchltjIk++vKacRxl7QK7WWqd6Mgsh7eVDxDRObNp0NI5QBkA+YKs5bktWJltn8Ev0HM1wkfTkoTKIy2ycc+y8nNo1FdtfJ5UqNIIGNS6pd3yJwxRI+qdGMtbGt70Gg7eLagPyGOjRhz7lcsFdr9ak60V2SXoCCNhGgIQ1frxiEC+ilTeK/Ii+p2dunizbUILBPWECh4t2ojE8ZjcgS/15xvK5NIV0S6Zd5IAvbjkvnla80HYjv+cbWKqSEzgnna6WqXlK8O02J6l2YX1FwMzPTFg==; 5:WE5qUmEPjxu3ZcqW351bm/D3PNmBMl9RlgvPgWGiai7UwkslB6DEd92c4XDWxZpnWqlKUyUt8jtebbqswc79x6rfhpiLOZc8sVufh3yw+O0ukIG5ySDtPC9uj1puCaRZR1GAGMil09uhOa49XWmBNPfLprPEo+DRjnEriubKex4m989OztaZRCRo1yDEmtGpMqeQOZrBkVBkMra/143ikg==; 7:nNMWjWgt6DWt0GbM6wmIQwff/DngBppOBq4c7SUnR1cCevZBfTppZw6qVAFQzOeq2X03FyJiQTqY6txiglg+cWlZhIuFvDIZESKw2WERyTHXK507dgnHx4ZlqBEMc3+j/Rfu3z85ex8XImXLzvaFrw== x-ms-office365-filtering-correlation-id: 7c1c98e6-8038-42e9-f7fe-08d67a7c2a7c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(14444005)(386003)(6506007)(68736007)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(30864003)(26005)(446003)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UEwh1+D/cSzllbK9cuftNDX+kNfSz5QCfR0dfK1GRT3nM73sZ5yOe2oDYxPC/AqaHE+0b/P1F2hMYR75kigCIGPv4hvBV76De4HH2JjL3RMD812AG08WdRjCe/dfa0nF0cTMIPPadnJtw3erIKONrsGgh6W64iepVBNGSr5bnd6opPCQObMskxS8ZI4S2mwVK/S2RyKHngYYE1P73uYvpW2WJNjSU4YfNd958kmOUSCuyO9VM0JmwhrQ8U0zE+5OcgXtrAIHmmKkMBCW80hKzBK4Nj9mNUG055oQVBVNsayg7J7Y3oEMSVW1oPHHcYJVSmmmGHv6r97krSmX8Q6RskhqYhlcJx2wtxIfhI75NpwmjnFAuO6iqeg4NRBdD8v2L7bomfFufw6lFMSDZKYBs1bqeKGlf55b0GflUj2aF8Y= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c1c98e6-8038-42e9-f7fe-08d67a7c2a7c X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:58:22.5368 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 4/8] RISC-V: Use riscv prefix consistently on cpu helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Clark * Add riscv prefix to raise_exception function * Add riscv prefix to CSR read/write functions * Add riscv prefix to signal handler function * Add riscv prefix to get fflags function * Remove redundant declaration of riscv_cpu_init and rename cpu_riscv_init to riscv_cpu_init * rename riscv_set_mode to riscv_cpu_set_mode Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Michael Clark Signed-off-by: Alistair Francis Reviewed-by: Richard Henderson --- linux-user/riscv/signal.c | 4 ++-- target/riscv/cpu.h | 21 ++++++++++----------- target/riscv/cpu_helper.c | 10 +++++----- target/riscv/csr.c | 8 ++++---- target/riscv/fpu_helper.c | 6 +++--- target/riscv/op_helper.c | 28 ++++++++++++++-------------- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index f598d41891..83ecc6f799 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -83,7 +83,7 @@ static void setup_sigcontext(struct target_sigcontext *sc, CPURISCVState *env) __put_user(env->fpr[i], &sc->fpr[i]); } - uint32_t fcsr = csr_read_helper(env, CSR_FCSR); /*riscv_get_fcsr(env);*/ + uint32_t fcsr = riscv_csr_read(env, CSR_FCSR); __put_user(fcsr, &sc->fcsr); } @@ -159,7 +159,7 @@ static void restore_sigcontext(CPURISCVState *env, struct target_sigcontext *sc) uint32_t fcsr; __get_user(fcsr, &sc->fcsr); - csr_write_helper(env, fcsr, CSR_FCSR); + riscv_csr_write(env, CSR_FCSR, fcsr); } static void restore_ucontext(CPURISCVState *env, struct target_ucontext *uc) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 681341f5d5..a97435bd7b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -256,7 +256,7 @@ int riscv_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, char *riscv_isa_string(RISCVCPU *cpu); void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf); -#define cpu_signal_handler cpu_riscv_signal_handler +#define cpu_signal_handler riscv_cpu_signal_handler #define cpu_list riscv_cpu_list #define cpu_mmu_index riscv_cpu_mmu_index @@ -264,16 +264,15 @@ void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf); uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */ #endif -void riscv_set_mode(CPURISCVState *env, target_ulong newpriv); +void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv); void riscv_translate_init(void); -RISCVCPU *cpu_riscv_init(const char *cpu_model); -int cpu_riscv_signal_handler(int host_signum, void *pinfo, void *puc); -void QEMU_NORETURN do_raise_exception_err(CPURISCVState *env, - uint32_t exception, uintptr_t pc); +int riscv_cpu_signal_handler(int host_signum, void *pinfo, void *puc); +void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env, + uint32_t exception, uintptr_t pc); -target_ulong cpu_riscv_get_fflags(CPURISCVState *env); -void cpu_riscv_set_fflags(CPURISCVState *env, target_ulong); +target_ulong riscv_cpu_get_fflags(CPURISCVState *env); +void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); #define TB_FLAGS_MMU_MASK 3 #define TB_FLAGS_MSTATUS_FS MSTATUS_FS @@ -293,13 +292,13 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); -static inline void csr_write_helper(CPURISCVState *env, target_ulong val, - int csrno) +static inline void riscv_csr_write(CPURISCVState *env, int csrno, + target_ulong val) { riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS)); } -static inline target_ulong csr_read_helper(CPURISCVState *env, int csrno) +static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) { target_ulong val = 0; riscv_csrrw(env, csrno, &val, 0, 0); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index f257050f12..f49e98ed59 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -93,7 +93,7 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) return old; } -void riscv_set_mode(CPURISCVState *env, target_ulong newpriv) +void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) { if (newpriv > PRV_M) { g_assert_not_reached(); @@ -366,7 +366,7 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, g_assert_not_reached(); } env->badaddr = addr; - do_raise_exception_err(env, cs->exception_index, retaddr); + riscv_raise_exception(env, cs->exception_index, retaddr); } /* called by qemu's softmmu to fill the qemu tlb */ @@ -378,7 +378,7 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size, if (ret == TRANSLATE_FAIL) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; - do_raise_exception_err(env, cs->exception_index, retaddr); + riscv_raise_exception(env, cs->exception_index, retaddr); } } @@ -530,7 +530,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) s = set_field(s, MSTATUS_SPP, env->priv); s = set_field(s, MSTATUS_SIE, 0); env->mstatus = s; - riscv_set_mode(env, PRV_S); + riscv_cpu_set_mode(env, PRV_S); } else { /* No need to check MTVEC for misaligned - lower 2 bits cannot be set */ env->pc = env->mtvec; @@ -555,7 +555,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) s = set_field(s, MSTATUS_MPP, env->priv); s = set_field(s, MSTATUS_MIE, 0); env->mstatus = s; - riscv_set_mode(env, PRV_M); + riscv_cpu_set_mode(env, PRV_M); } /* TODO yield load reservation */ #endif diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 390d3a9a56..e2bd374f09 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -90,7 +90,7 @@ static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) return -1; } #endif - *val = cpu_riscv_get_fflags(env); + *val = riscv_cpu_get_fflags(env); return 0; } @@ -102,7 +102,7 @@ static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) } env->mstatus |= MSTATUS_FS; #endif - cpu_riscv_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT)); + riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT)); return 0; } @@ -136,7 +136,7 @@ static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) return -1; } #endif - *val = (cpu_riscv_get_fflags(env) << FSR_AEXC_SHIFT) + *val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT) | (env->frm << FSR_RD_SHIFT); return 0; } @@ -150,7 +150,7 @@ static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) env->mstatus |= MSTATUS_FS; #endif env->frm = (val & FSR_RD) >> FSR_RD_SHIFT; - cpu_riscv_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT); + riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT); return 0; } diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index 01b45ca0ae..b4f818a646 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -22,7 +22,7 @@ #include "exec/exec-all.h" #include "exec/helper-proto.h" -target_ulong cpu_riscv_get_fflags(CPURISCVState *env) +target_ulong riscv_cpu_get_fflags(CPURISCVState *env) { int soft = get_float_exception_flags(&env->fp_status); target_ulong hard = 0; @@ -36,7 +36,7 @@ target_ulong cpu_riscv_get_fflags(CPURISCVState *env) return hard; } -void cpu_riscv_set_fflags(CPURISCVState *env, target_ulong hard) +void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong hard) { int soft = 0; @@ -73,7 +73,7 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm) softrm = float_round_ties_away; break; default: - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } set_float_rounding_mode(softrm, &env->fp_status); diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 77c79ba36e..b7dc18a41e 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -25,7 +25,7 @@ #include "exec/helper-proto.h" /* Exceptions processing helpers */ -void QEMU_NORETURN do_raise_exception_err(CPURISCVState *env, +void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env, uint32_t exception, uintptr_t pc) { CPUState *cs = CPU(riscv_env_get_cpu(env)); @@ -36,7 +36,7 @@ void QEMU_NORETURN do_raise_exception_err(CPURISCVState *env, void helper_raise_exception(CPURISCVState *env, uint32_t exception) { - do_raise_exception_err(env, exception, 0); + riscv_raise_exception(env, exception, 0); } target_ulong helper_csrrw(CPURISCVState *env, target_ulong src, @@ -44,7 +44,7 @@ target_ulong helper_csrrw(CPURISCVState *env, target_ulong src, { target_ulong val = 0; if (riscv_csrrw(env, csr, &val, src, -1) < 0) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } return val; } @@ -54,7 +54,7 @@ target_ulong helper_csrrs(CPURISCVState *env, target_ulong src, { target_ulong val = 0; if (riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0) < 0) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } return val; } @@ -64,7 +64,7 @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src, { target_ulong val = 0; if (riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0) < 0) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } return val; } @@ -74,17 +74,17 @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src, target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) { if (!(env->priv >= PRV_S)) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } target_ulong retpc = env->sepc; if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) { - do_raise_exception_err(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } if (env->priv_ver >= PRIV_VERSION_1_10_0 && get_field(env->mstatus, MSTATUS_TSR)) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } target_ulong mstatus = env->mstatus; @@ -95,7 +95,7 @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) get_field(mstatus, MSTATUS_SPIE)); mstatus = set_field(mstatus, MSTATUS_SPIE, 0); mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U); - riscv_set_mode(env, prev_priv); + riscv_cpu_set_mode(env, prev_priv); env->mstatus = mstatus; return retpc; @@ -104,12 +104,12 @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb) { if (!(env->priv >= PRV_M)) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } target_ulong retpc = env->mepc; if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) { - do_raise_exception_err(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC()); } target_ulong mstatus = env->mstatus; @@ -120,7 +120,7 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb) get_field(mstatus, MSTATUS_MPIE)); mstatus = set_field(mstatus, MSTATUS_MPIE, 0); mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U); - riscv_set_mode(env, prev_priv); + riscv_cpu_set_mode(env, prev_priv); env->mstatus = mstatus; return retpc; @@ -133,7 +133,7 @@ void helper_wfi(CPURISCVState *env) if (env->priv == PRV_S && env->priv_ver >= PRIV_VERSION_1_10_0 && get_field(env->mstatus, MSTATUS_TW)) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } else { cs->halted = 1; cs->exception_index = EXCP_HLT; @@ -148,7 +148,7 @@ void helper_tlb_flush(CPURISCVState *env) if (env->priv == PRV_S && env->priv_ver >= PRIV_VERSION_1_10_0 && get_field(env->mstatus, MSTATUS_TVM)) { - do_raise_exception_err(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } else { tlb_flush(cs); } From patchwork Mon Jan 14 23:58:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="KJNqnCFh"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="TgrfvgeZ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dr6w4Tnfz9s3l for ; Tue, 15 Jan 2019 10:59:36 +1100 (AEDT) Received: from localhost ([127.0.0.1]:46617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC8k-00042X-Hx for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 18:59:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC84-00040q-Px for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC83-000107-UK for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:52 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59875) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC83-0000px-Mj; Mon, 14 Jan 2019 18:58:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510332; x=1579046332; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=c3lyJ/gc57nf1eRT/PN/b9MIOi/YCRIibqg9bz587N8=; b=KJNqnCFhh/bInLqc8gYr6URadhI0r6lra+edPuPuQ023scCAjvdxjWrf w7zVC13JLT70vTt4QJ6Jpbr+1QtCpOTErUScHysGM2wiDMFQ64Ho31YGL NU1GSgspyuGKIOjiGcHTJwd9SYeT+vafeCvdf+xiAegz3NBrO97YBHR5q 3JeppFhcZtY6CMkEoVseFRvTw/RheLGe59hfswUgD/JCZGrFiGKEo7G0y ET1GJLbLNNij1RrFS7na6YpzeC/P68kG5SuijxeNVotiqJQ7+uQsNBwjT Irp5GpCDb6MZ9rHGr4NoOzDqqt/DTvd5re/m2cppZU3+xo5fEkCo4bbvl A==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765701" Received: from mail-by2nam03lp2050.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.50]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:40 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K7YngWmC9bMswtFfX9dNO6ols6xIz894i6CpoCE42Es=; b=TgrfvgeZtlhgE4WlOXToG5z96rgpPNj1IV2F3swwjie95SFJyzAmx5Yahr8S3c/XfZ0WTlIS6e0RmSPutsKxTNhFeqc08nzRc7cM9Z1uNTOmN03ksff6SBFxBRYqWhA3KGa5lDpkmzCKOZqJw6f+akZdIsG2SHQlG1M/V4Zjs9A= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:58:38 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:58:38 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 5/8] RISC-V: Add priv_ver to DisasContext Thread-Index: AQHUrGUO+jH3VkYhVk+duCHz9kzzew== Date: Mon, 14 Jan 2019 23:58:32 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: MWHPR20CA0037.namprd20.prod.outlook.com (2603:10b6:300:ed::23) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:3CTf25qQyE3WrivxnMmTAM6hCWJYKVvLdj6d205K2vevmmSQA9FLV5ahGl673BCgRo9u+eO4z7fbs0TFjm3WCRy5ZYnGimd3OyUxc4bRC4wacamHPWTSQNPqoY/ynchGaNATfWUHdIdQ+cnJ3XijXP8nmvXfjaCpOr6d/hA0DJ8zCEv/RCakzttVcGeeQGW0Y/rgoqreufXgScVgPymqBlT/p03oO37fdMd0UDIX4Fq+3KfSe9BPjutvu/+GbrUDLpy5LwpqGXIRnZZlHSzA4X6jh/OgLBdRV59ztcE6EItHTf1poG0Gd8D2Ry67vupT3otr7bNy6Q7TP6Y726XyRI9ABfUokgA1PYfnj3nnDJFvvL8etQVDSjG2Vla8ziReZ2jWD+psX9INljhtvU9+UKWVhkd4wRLgHYtrh6RtLCv5XOEOdkJRDjLbxACprz/vrUKHEHeCiiS/mUy+ESNH3Q==; 5:SxNv6V+2bvwJTZSDaEIdVdoiRTE4rVqh7ToFx79e/4FaG58N60WtI1yPbQRgx7TuWpF9rT6WXjv96gyzhFKqv6tNA/byBo/6knQfkGTqmxFih2Sz8z1wJHzzdKLzNATsNl+vKEBNR4njL29iOEqYJVS+KQxW+2Uey0gAMSj+2z+xOhpxriL1idwWuV30veV5TKDNPF0kx5TO0T1mFc0K9Q==; 7:0Il6KfecVEkEgISDvaidpKMCaOmICvJRH280rK+Av4JNOLPYzbXRPTGhM8sgJJhQlLuudJsm8twwPIJlC7p3MciLQ2xbsUH3MyL60RrbFKuB7TX0TEy2IfdU2JUi+CynYZP1SKSxZyEoQIXPw+1y/w== x-ms-office365-filtering-correlation-id: a69aa210-4af8-48ca-59e8-08d67a7c306e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(14444005)(386003)(6506007)(68736007)(5660300001)(6666004)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(26005)(446003)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: OK5hAHwyiuqpQ/17ec5W3KPTUS7ADO9biETyJ7pFrerOtEilxrDYHdaJNqrT/09R3SX6pYmWkFRHZLJx8f214fwewfomUGL5gCa9L9uLxRmhzdDCOcTQ2sHP/wouxgHv7+OitJhsqOvgo7J8v5J+AIdsT4aHimkgjIYF6CTLlqrAgwlIL0RYYdHMWXTaKYe+q3uNIKSqhpyAwWIgkAQXa9O60mUdYpln/16JTi/YFUueLhquv2I3IztLwFSRuOywLdejhzikKKM9g6FlxF/4MdkAF6yVYPXIJBh/c0YM5buJ1o4QICw9BjKpvfzy1Th1o+vzJvZrSMy+9tICRn2Z6vp+Ob6CsFdVr0TWmZlmD9B7gKLVgANl69vKLrtN/FzqjIQCIS6c0f0gd3WPQpC0Brm3vr95qQ4LLx1jGOmcx94= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a69aa210-4af8-48ca-59e8-08d67a7c306e X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:58:32.5064 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 5/8] RISC-V: Add priv_ver to DisasContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The gen methods should access state from DisasContext. Add priv_ver field to the DisasContext struct. Signed-off-by: Alistair Francis Reviewed-by: Richard Henderson --- target/riscv/translate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 0581b3c1f7..833adf1d6f 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -43,6 +43,7 @@ typedef struct DisasContext { DisasContextBase base; /* pc_succ_insn points to the instruction following base.pc_next */ target_ulong pc_succ_insn; + target_ulong priv_ver; uint32_t opcode; uint32_t mstatus_fs; uint32_t mem_idx; @@ -1330,7 +1331,7 @@ static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc, #ifndef CONFIG_USER_ONLY /* Extract funct7 value and check whether it matches SFENCE.VMA */ if ((opc == OPC_RISC_ECALL) && ((csr >> 5) == 9)) { - if (env->priv_ver == PRIV_VERSION_1_10_0) { + if (ctx->priv_ver == PRIV_VERSION_1_10_0) { /* sfence.vma */ /* TODO: handle ASID specific fences */ gen_helper_tlb_flush(cpu_env); @@ -1384,7 +1385,7 @@ static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc, gen_helper_wfi(cpu_env); break; case 0x104: /* SFENCE.VM */ - if (env->priv_ver <= PRIV_VERSION_1_09_1) { + if (ctx->priv_ver <= PRIV_VERSION_1_09_1) { gen_helper_tlb_flush(cpu_env); } else { gen_exception_illegal(ctx); @@ -1851,13 +1852,15 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx) } } -static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) +static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *ctx = container_of(dcbase, DisasContext, base); + CPURISCVState *env = cpu->env_ptr; ctx->pc_succ_insn = ctx->base.pc_first; ctx->mem_idx = ctx->base.tb->flags & TB_FLAGS_MMU_MASK; ctx->mstatus_fs = ctx->base.tb->flags & TB_FLAGS_MSTATUS_FS; + ctx->priv_ver = env->priv_ver; ctx->frm = -1; /* unknown rounding mode */ } From patchwork Mon Jan 14 23:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="nTlbXIqB"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="BRcISSa1"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43dr9h4L3Nz9s3l for ; Tue, 15 Jan 2019 11:02:00 +1100 (AEDT) Received: from localhost ([127.0.0.1]:47245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjCB4-0005tx-EJ for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 19:01:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC8B-000483-Kr for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:59:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC89-000150-Jt for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:59 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC89-000149-9u; Mon, 14 Jan 2019 18:58:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510338; x=1579046338; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=W9L5R39R0MQWtU0aHerpCKljBbajS3kTwbt5m4z4c1E=; b=nTlbXIqBkRXf4/++vl9+Dbwtm99xCXcbgYquUYAAxshPCdfLJICeMKz8 y3yrjAKdAbBvuYmtjjQtx9kTgFwm4gCA2INU7h7RkV28fF8hMoYwHswPF RCqS198YX3AVhEqEEwNvIW+b+7cbZqUji6WlgRN3NNxZedjj74zynBugx Y+4m+obV8JR2FT9X/ZcGwC04iPte5nppbR73//4jq21kx6liFc50BR1yJ p7DQTdZMM8gOxfgqRtFiWnT/ZRGTH0t5dgN/+fY2i3de87Eet5gZf97/c 1bOLol/9HbvNQvkeIqEK/BnrtCNFhggHqnHH5NBpBOvbrdD05pmCNW59d A==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765702" Received: from mail-by2nam03lp2052.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.52]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:44 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jMLnnavIH/gWrIdauhL6v40BNi4I3RfAb62TC3oO/HA=; b=BRcISSa17hDc3f2GmajTHNVZ9BFjAWI/BfCIFnAwexKotYnFsUNMsAQ+++wDf1Fy7o/TuIII5ZTqi8iiIgHvHLGKrU5Uf0RTAjYj3N48bq5svzjPqjBZaZjWRBDX3F3pEcLgmDkc0SNqiPUdQ+bYfOFWd0HU0bjU22vVZ6F3g6M= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:58:42 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:58:42 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 6/8] RISC-V: Add misa to DisasContext Thread-Index: AQHUrGUT1PMTupKzSUSZnY/bECbtaw== Date: Mon, 14 Jan 2019 23:58:42 +0000 Message-ID: <2425e4ccd5ad76fa9dbedfc7c2b33918a222aabd.1547510220.git.alistair.francis@wdc.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: BYAPR07CA0004.namprd07.prod.outlook.com (2603:10b6:a02:bc::17) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:mA5PN5YhzTkt0cl97qHuCZC6M42Kxvof2QZ/TNhktxWxorby3bLRAIsT50o6SgdT1aMXIq5/0ZByv6b4uV35iujJlV/AJfUzI2nQzfs+viEjR+CssQ1e0/kt5e0BZ0vsjRGhIej3+4DSMlrll0cF8/JUXqn8xwEVdMW7BVL95aIRrmryq+4doVcQmkhTC0FL5SMjzhHNJ5I63gtpC3n6cw6NsktUP/jAzbj+zjwdmvBzlC7kFi2MZeax8ZEu00S2qll/m1TKAt0ZYevoXQdy/vrJi0J3xZmUWgzfcP+YuoUSNOfwaSV/K/tS9/ac1Tv8CVqgRUCK8RARyATc0tP8UQvQlwXAwlQaPj/wPZxlCP2GU7Y1qLy14MWqCi76uXp+liiOXmpdWaPZmQcNp3EF2DXR18+HzD8AyXKaYIPyL3oJBUV8tzilyGNTEbUUJcsieFNIUnEqS/DUncGxJe4rvg==; 5:LjmI18DWfto/MiMVPpnnWyVH4V/yWRd0Ra9D/vUsZtxd6aK/R+4hofmB8teBMeiwuCEdqDs78yB7tPbukXiESoPwil9TRHEaK6VVMrr5VuU3HP0hGCKuz4YaR1Rzh6ZcS2KyP5zwDqO7KBA5FZvRfw6uZTXFvC22DNlSpBFm3jFynHkS3yLk9/iVeZVdsIfuhx3OVUbRXbkLFVJpnczTVQ==; 7:D/kklJIsP79mC+urYVdY86vrq8qKdOmiDyjS2OKN54GEjzha8EiZ1FQO/jsKCFjpA2hLNZo/6+wLLWMOrgAjOVEENJ6taVH0dwKS6p2sgcDw64tpdPBRf1T744lwvWGF3J4PyK5KR3hdutR3cc262A== x-ms-office365-filtering-correlation-id: 46e4170a-7731-4c3a-04ce-08d67a7c3605 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(14444005)(386003)(6506007)(68736007)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(26005)(446003)(86362001)(357404004); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ytw+fN2f1zUmzzetONC54B2O5YnkCPBZrec59WxdnFYE/y1Z7Ro9h1TLuqtAJn/IhY9HqF2rw0pnYR+ObxnFPO9lLpJ6vw8LKHV3sO82fVOm9iHazSDoP27mwc0a94MhQ3XD+ZBmDI57/PlDGRQRAwQjZ8EB3I36fnkelLydaox9QveFs3n+Lm4+CqycoYuVJzF+/ax8dRoLXnXk4w41cObjIaI4Kpr4YiGjmq6iULW+YAtmtT+KYA4iYZ4pBZFv10ZNAP42nsgdKkd7tWSaYfVMq2Rb+Hj/EwJS0jo0xeO8jYYtjfW7lJt4XGTcj/QisqCfGfjU+5BIBESgigB3NNiXRcSQNONxgkt9sOeTeYobt7tXb+qWMBwAPTJv4oc31Kjzg14ukh4tX/ReGVQ9//J4atRGJyC684r66ChNvcw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46e4170a-7731-4c3a-04ce-08d67a7c3605 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:58:41.8714 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 6/8] RISC-V: Add misa to DisasContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Clark gen methods should access state from DisasContext. Add misa field to the DisasContext struct and remove CPURISCVState argument from all gen methods. Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Alistair Francis Cc: Emilio G. Cota Signed-off-by: Michael Clark Reviewed-by: Richard Henderson Signed-off-by: Alistair Francis --- target/riscv/translate.c | 75 +++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 833adf1d6f..7ebea308b4 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -46,6 +46,7 @@ typedef struct DisasContext { target_ulong priv_ver; uint32_t opcode; uint32_t mstatus_fs; + uint32_t misa; uint32_t mem_idx; /* Remember the rounding mode encoded in the previous fp instruction, which we have already installed into env->fp_status. Or -1 for @@ -75,6 +76,11 @@ static const int tcg_memop_lookup[8] = { #define CASE_OP_32_64(X) case X #endif +static inline bool has_ext(DisasContext *ctx, uint32_t ext) +{ + return ctx->misa & ext; +} + static void generate_exception(DisasContext *ctx, int excp) { tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); @@ -506,14 +512,13 @@ static void gen_arith_imm(DisasContext *ctx, uint32_t opc, int rd, tcg_temp_free(source1); } -static void gen_jal(CPURISCVState *env, DisasContext *ctx, int rd, - target_ulong imm) +static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) { target_ulong next_pc; /* check misaligned: */ next_pc = ctx->base.pc_next + imm; - if (!riscv_has_ext(env, RVC)) { + if (!has_ext(ctx, RVC)) { if ((next_pc & 0x3) != 0) { gen_exception_inst_addr_mis(ctx); return; @@ -527,8 +532,8 @@ static void gen_jal(CPURISCVState *env, DisasContext *ctx, int rd, ctx->base.is_jmp = DISAS_NORETURN; } -static void gen_jalr(CPURISCVState *env, DisasContext *ctx, uint32_t opc, - int rd, int rs1, target_long imm) +static void gen_jalr(DisasContext *ctx, uint32_t opc, int rd, int rs1, + target_long imm) { /* no chaining with JALR */ TCGLabel *misaligned = NULL; @@ -540,7 +545,7 @@ static void gen_jalr(CPURISCVState *env, DisasContext *ctx, uint32_t opc, tcg_gen_addi_tl(cpu_pc, cpu_pc, imm); tcg_gen_andi_tl(cpu_pc, cpu_pc, (target_ulong)-2); - if (!riscv_has_ext(env, RVC)) { + if (!has_ext(ctx, RVC)) { misaligned = gen_new_label(); tcg_gen_andi_tl(t0, cpu_pc, 0x2); tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0x0, misaligned); @@ -565,8 +570,8 @@ static void gen_jalr(CPURISCVState *env, DisasContext *ctx, uint32_t opc, tcg_temp_free(t0); } -static void gen_branch(CPURISCVState *env, DisasContext *ctx, uint32_t opc, - int rs1, int rs2, target_long bimm) +static void gen_branch(DisasContext *ctx, uint32_t opc, int rs1, int rs2, + target_long bimm) { TCGLabel *l = gen_new_label(); TCGv source1, source2; @@ -603,7 +608,7 @@ static void gen_branch(CPURISCVState *env, DisasContext *ctx, uint32_t opc, gen_goto_tb(ctx, 1, ctx->pc_succ_insn); gen_set_label(l); /* branch taken */ - if (!riscv_has_ext(env, RVC) && ((ctx->base.pc_next + bimm) & 0x3)) { + if (!has_ext(ctx, RVC) && ((ctx->base.pc_next + bimm) & 0x3)) { /* misaligned */ gen_exception_inst_addr_mis(ctx); } else { @@ -1314,8 +1319,8 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, } } -static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc, - int rd, int rs1, int csr) +static void gen_system(DisasContext *ctx, uint32_t opc, int rd, int rs1, + int csr) { TCGv source1, csr_store, dest, rs1_pass, imm_rs1; source1 = tcg_temp_new(); @@ -1361,7 +1366,7 @@ static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc, gen_exception_illegal(ctx); break; case 0x102: /* SRET */ - if (riscv_has_ext(env, RVS)) { + if (has_ext(ctx, RVS)) { gen_helper_sret(cpu_pc, cpu_env, cpu_pc); tcg_gen_exit_tb(NULL, 0); /* no chaining */ ctx->base.is_jmp = DISAS_NORETURN; @@ -1506,7 +1511,7 @@ static void decode_RV32_64C0(DisasContext *ctx) } } -static void decode_RV32_64C1(CPURISCVState *env, DisasContext *ctx) +static void decode_RV32_64C1(DisasContext *ctx) { uint8_t funct3 = extract32(ctx->opcode, 13, 3); uint8_t rd_rs1 = GET_C_RS1(ctx->opcode); @@ -1526,7 +1531,7 @@ static void decode_RV32_64C1(CPURISCVState *env, DisasContext *ctx) GET_C_IMM(ctx->opcode)); #else /* C.JAL(RV32) -> jal x1, offset[11:1] */ - gen_jal(env, ctx, 1, GET_C_J_IMM(ctx->opcode)); + gen_jal(ctx, 1, GET_C_J_IMM(ctx->opcode)); #endif break; case 2: @@ -1605,22 +1610,22 @@ static void decode_RV32_64C1(CPURISCVState *env, DisasContext *ctx) break; case 5: /* C.J -> jal x0, offset[11:1]*/ - gen_jal(env, ctx, 0, GET_C_J_IMM(ctx->opcode)); + gen_jal(ctx, 0, GET_C_J_IMM(ctx->opcode)); break; case 6: /* C.BEQZ -> beq rs1', x0, offset[8:1]*/ rs1s = GET_C_RS1S(ctx->opcode); - gen_branch(env, ctx, OPC_RISC_BEQ, rs1s, 0, GET_C_B_IMM(ctx->opcode)); + gen_branch(ctx, OPC_RISC_BEQ, rs1s, 0, GET_C_B_IMM(ctx->opcode)); break; case 7: /* C.BNEZ -> bne rs1', x0, offset[8:1]*/ rs1s = GET_C_RS1S(ctx->opcode); - gen_branch(env, ctx, OPC_RISC_BNE, rs1s, 0, GET_C_B_IMM(ctx->opcode)); + gen_branch(ctx, OPC_RISC_BNE, rs1s, 0, GET_C_B_IMM(ctx->opcode)); break; } } -static void decode_RV32_64C2(CPURISCVState *env, DisasContext *ctx) +static void decode_RV32_64C2(DisasContext *ctx) { uint8_t rd, rs2; uint8_t funct3 = extract32(ctx->opcode, 13, 3); @@ -1654,7 +1659,7 @@ static void decode_RV32_64C2(CPURISCVState *env, DisasContext *ctx) if (extract32(ctx->opcode, 12, 1) == 0) { if (rs2 == 0) { /* C.JR -> jalr x0, rs1, 0*/ - gen_jalr(env, ctx, OPC_RISC_JALR, 0, rd, 0); + gen_jalr(ctx, OPC_RISC_JALR, 0, rd, 0); } else { /* C.MV -> add rd, x0, rs2 */ gen_arith(ctx, OPC_RISC_ADD, rd, 0, rs2); @@ -1662,11 +1667,11 @@ static void decode_RV32_64C2(CPURISCVState *env, DisasContext *ctx) } else { if (rd == 0) { /* C.EBREAK -> ebreak*/ - gen_system(env, ctx, OPC_RISC_ECALL, 0, 0, 0x1); + gen_system(ctx, OPC_RISC_ECALL, 0, 0, 0x1); } else { if (rs2 == 0) { /* C.JALR -> jalr x1, rs1, 0*/ - gen_jalr(env, ctx, OPC_RISC_JALR, 1, rd, 0); + gen_jalr(ctx, OPC_RISC_JALR, 1, rd, 0); } else { /* C.ADD -> add rd, rd, rs2 */ gen_arith(ctx, OPC_RISC_ADD, rd, rd, rs2); @@ -1698,7 +1703,7 @@ static void decode_RV32_64C2(CPURISCVState *env, DisasContext *ctx) } } -static void decode_RV32_64C(CPURISCVState *env, DisasContext *ctx) +static void decode_RV32_64C(DisasContext *ctx) { uint8_t op = extract32(ctx->opcode, 0, 2); @@ -1707,15 +1712,15 @@ static void decode_RV32_64C(CPURISCVState *env, DisasContext *ctx) decode_RV32_64C0(ctx); break; case 1: - decode_RV32_64C1(env, ctx); + decode_RV32_64C1(ctx); break; case 2: - decode_RV32_64C2(env, ctx); + decode_RV32_64C2(ctx); break; } } -static void decode_RV32_64G(CPURISCVState *env, DisasContext *ctx) +static void decode_RV32_64G(DisasContext *ctx) { int rs1; int rs2; @@ -1750,13 +1755,13 @@ static void decode_RV32_64G(CPURISCVState *env, DisasContext *ctx) break; case OPC_RISC_JAL: imm = GET_JAL_IMM(ctx->opcode); - gen_jal(env, ctx, rd, imm); + gen_jal(ctx, rd, imm); break; case OPC_RISC_JALR: - gen_jalr(env, ctx, MASK_OP_JALR(ctx->opcode), rd, rs1, imm); + gen_jalr(ctx, MASK_OP_JALR(ctx->opcode), rd, rs1, imm); break; case OPC_RISC_BRANCH: - gen_branch(env, ctx, MASK_OP_BRANCH(ctx->opcode), rs1, rs2, + gen_branch(ctx, MASK_OP_BRANCH(ctx->opcode), rs1, rs2, GET_B_IMM(ctx->opcode)); break; case OPC_RISC_LOAD: @@ -1827,7 +1832,7 @@ static void decode_RV32_64G(CPURISCVState *env, DisasContext *ctx) } break; case OPC_RISC_SYSTEM: - gen_system(env, ctx, MASK_OP_SYSTEM(ctx->opcode), rd, rs1, + gen_system(ctx, MASK_OP_SYSTEM(ctx->opcode), rd, rs1, (ctx->opcode & 0xFFF00000) >> 20); break; default: @@ -1836,19 +1841,19 @@ static void decode_RV32_64G(CPURISCVState *env, DisasContext *ctx) } } -static void decode_opc(CPURISCVState *env, DisasContext *ctx) +static void decode_opc(DisasContext *ctx) { /* check for compressed insn */ if (extract32(ctx->opcode, 0, 2) != 3) { - if (!riscv_has_ext(env, RVC)) { + if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { ctx->pc_succ_insn = ctx->base.pc_next + 2; - decode_RV32_64C(env, ctx); + decode_RV32_64C(ctx); } } else { ctx->pc_succ_insn = ctx->base.pc_next + 4; - decode_RV32_64G(env, ctx); + decode_RV32_64G(ctx); } } @@ -1861,6 +1866,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) ctx->mem_idx = ctx->base.tb->flags & TB_FLAGS_MMU_MASK; ctx->mstatus_fs = ctx->base.tb->flags & TB_FLAGS_MSTATUS_FS; ctx->priv_ver = env->priv_ver; + ctx->misa = env->misa; ctx->frm = -1; /* unknown rounding mode */ } @@ -1891,14 +1897,13 @@ static bool riscv_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } - static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPURISCVState *env = cpu->env_ptr; ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); - decode_opc(env, ctx); + decode_opc(ctx); ctx->base.pc_next = ctx->pc_succ_insn; if (ctx->base.is_jmp == DISAS_NEXT) { From patchwork Mon Jan 14 23:58:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="j/p/Nm1e"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="IS8oPDYF"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43drBj0KH5z9s3l for ; Tue, 15 Jan 2019 11:02:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:47445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjCBu-0006aI-Vu for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 19:02:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC8B-00048O-V3 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:59:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC8A-00015M-5x for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:58:59 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:59886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC89-000149-Sm; Mon, 14 Jan 2019 18:58:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510338; x=1579046338; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=U57ej2EV16jeBMGHTlBMwvQO6MLx3MGdO57+fyJAVPc=; b=j/p/Nm1eh5jYgFLh2g1XGXenUWQht35q4BgMIUxgPOihYZ8+0lcvdalQ r6OhXNbDUcBA29utD2cgKAVtW9VwzU6tu3JpRrMTC8o3Se0Q8jcz1n3EC oJwemCpxoZu1FyZP16YjfMhyEGB4u2ou/gvVwdD4J9iYueY4Y80CoPe9N EBCg5cXpqUUX0IrTdVl+uVquTbGw5cEtZzWha76G0IYETL5Sg19EOfTzd wW0pJ09EPoiQ0aSYrSTL8scJRgWTWNAu36PwICi8Xrnq8SZF7I26ea/Ic dyzbgVnMFHJw2jQ/gupFFKy4GIvq3tKstcICNFZfl3440NGIcfAjSOfxk Q==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="98765708" Received: from mail-by2nam03lp2057.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([104.47.42.57]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:58:54 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lAXWIF0dsaz+FRsaMV6pCIigXrjfnetwUwp0+J+yZBo=; b=IS8oPDYFQWcE4DCiV4cW54L28qKguJzBVny27xqj+lAFPpETWCEZwMXAFdpqw09lP1ibIRTNdmnP6IiSrlQzIwXyec2GlQzfYwGBH1gbWdeEjG/DeWgOT+WeLP8SgPDssFuuNmYDw1quAvwtv16MCP7fIsal12pG9Evb2+8Ek00= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0895.namprd04.prod.outlook.com (10.174.174.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:58:51 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:58:51 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 7/8] RISC-V: Add misa.MAFD checks to translate Thread-Index: AQHUrGUZxXuSgjbK/UyW7FD8EZ+YYw== Date: Mon, 14 Jan 2019 23:58:51 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: BYAPR07CA0030.namprd07.prod.outlook.com (2603:10b6:a02:bc::43) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0895; 6:6Fn5D0mUvQAdKngnbn+FDcMF+jKy5RJJ8SI7aNlYw8i1+fJtLH+Excel8AbHJxr+8jRAJ8As+HBJvDGpf/2OQUaJSf+y0P83fDrgbDmKrMqYrB/FZIBN1V8BK5g+ZfvDoFHjS1WdifOfZ87fo/I+ftZv8GgsxiWco+Skcqw37BU/yKIzkHq3nEBG+CPHABT5rlglA8baPEL7VIFANin+xCIwxuO4ZAZZJpiJYgh8faOTd2f1nSXUtxwky9DMohajo8YZHedvytuNhZFV0Bmxh+cpp1HdKRyLvqOS4QM6r8vu4s0Uf7pEdD1U1sBqT4ineRDVkwklX8YbLsSTCNU40rRllBZwluqXqa/+xwmS5OB+s7SvBGGqTCcH/OE1KxV4UXg3Imi5F1/x9LbeYjzJbAyduU63u+JiQfBj+vfb9raGVzmpUJOuQOaVSJEkX0b/HdqWg1VXWhJ4qctUh/gpvg==; 5:+ht2Aio2M4pfiinRpTg5LZidyuEMqj94XaEPvroQKbpfk0HFH5p9bNfNC2qqMZR2I1KbTpTDKxukX6x8+gfomM6s61OWQjo4UxxrCeL/W1dWUwBkvmqFeiPYd4Xm1wvlR8E58JEg/gedhiDRNUJcqQ5Bc6EGuzi/kwYxDnvDVxo1HMOnuy7wkQKZdTojf0uIucgB5XB9lybCImPQQnducw==; 7:CethL/f/A2E3tPMLfisXHHlQdwBel3rWgR43L22MTOszcWBhHwvEa1Z1abwK9D3m0FE9B2Kza4rFq4f593ashSVYYe9S/BaBZhdqmbUZ/psjt5/iPo71yLg5tyDpoEXP5Ji4jzSGi9OOA45SWRcVnA== x-ms-office365-filtering-correlation-id: ceb137c1-a409-4a6e-63bb-08d67a7c3b85 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0895; x-ms-traffictypediagnostic: MWHPR04MB0895: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(136003)(376002)(366004)(396003)(346002)(199004)(189003)(81156014)(118296001)(256004)(99286004)(72206003)(386003)(6506007)(68736007)(5660300001)(81166006)(4326008)(2501003)(8676002)(44832011)(105586002)(2906002)(8936002)(486006)(106356001)(71190400001)(7736002)(71200400001)(50226002)(110136005)(316002)(52116002)(54906003)(14454004)(53936002)(186003)(39060400002)(66066001)(6512007)(76176011)(6486002)(36756003)(478600001)(53946003)(25786009)(2616005)(6436002)(6116002)(476003)(97736004)(3846002)(305945005)(102836004)(11346002)(30864003)(26005)(446003)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0895; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: k+z74vlxkYGpsa8Q1s9usN8gT5T0X0mdcoP1i1fE5CNXU8syxjU4kxiC4cYi6KbovWCsu6TW6Jkq28UFOos4NuPJ7iZWRBWUi8CZV0/kKCb+uX+KEzAdLGOfILjHWExWw20OPqGgD47dLYjy+2GGq1IwsRmRm59ib9YjcRHQ4cBwd1Lyzqp0L7Udxiap13yVshoiwyRFSMtrMjmw3lHN8FDif4b/UtnJJ0RERIznDvZdTmnM9EJwiCoowAClcaW2xvKd9FlgkTEUFu+02quuV2P1rAsbQ/z3pr9smmEPTWlAhvCsowkwQXr9IEBc0Y3XzT7KA45ER3Xf/CNRzljZstdKAXbIOnu2pxLa0/yoroblSKpfZlJUjOEMiOryW49miHlDA8KLNZyMZwYGMedCpUccsB34SvZCEJj44TjB02Y= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: ceb137c1-a409-4a6e-63bb-08d67a7c3b85 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:58:51.1043 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0895 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v1 7/8] RISC-V: Add misa.MAFD checks to translate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Clark Add misa checks for M, A, F and D extensions and if they are not present generate illegal instructions. This improves emulation accurary for harts with a limited set of extensions. Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Alistair Francis Cc: Emilio G. Cota Signed-off-by: Michael Clark Signed-off-by: Alistair Francis Reviewed-by: Richard Henderson --- target/riscv/translate.c | 158 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 7ebea308b4..8593c2170a 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -291,24 +291,42 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, tcg_gen_and_tl(source1, source1, source2); break; CASE_OP_32_64(OPC_RISC_MUL): + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_mul_tl(source1, source1, source2); break; case OPC_RISC_MULH: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_muls2_tl(source2, source1, source1, source2); break; case OPC_RISC_MULHSU: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } gen_mulhsu(source1, source1, source2); break; case OPC_RISC_MULHU: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_mulu2_tl(source2, source1, source1, source2); break; #if defined(TARGET_RISCV64) case OPC_RISC_DIVW: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_ext32s_tl(source1, source1); tcg_gen_ext32s_tl(source2, source2); /* fall through to DIV */ #endif case OPC_RISC_DIV: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } /* Handle by altering args to tcg_gen_div to produce req'd results: * For overflow: want source1 in source1 and 1 in source2 * For div by zero: want -1 in source1 and 1 in source2 -> -1 result */ @@ -340,11 +358,17 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, break; #if defined(TARGET_RISCV64) case OPC_RISC_DIVUW: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_ext32u_tl(source1, source1); tcg_gen_ext32u_tl(source2, source2); /* fall through to DIVU */ #endif case OPC_RISC_DIVU: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } cond1 = tcg_temp_new(); zeroreg = tcg_const_tl(0); resultopt1 = tcg_temp_new(); @@ -364,11 +388,17 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, break; #if defined(TARGET_RISCV64) case OPC_RISC_REMW: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_ext32s_tl(source1, source1); tcg_gen_ext32s_tl(source2, source2); /* fall through to REM */ #endif case OPC_RISC_REM: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } cond1 = tcg_temp_new(); cond2 = tcg_temp_new(); zeroreg = tcg_const_tl(0); @@ -396,11 +426,17 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, break; #if defined(TARGET_RISCV64) case OPC_RISC_REMUW: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } tcg_gen_ext32u_tl(source1, source1); tcg_gen_ext32u_tl(source2, source2); /* fall through to REMU */ #endif case OPC_RISC_REMU: + if (!has_ext(ctx, RVM)) { + goto do_illegal; + } cond1 = tcg_temp_new(); zeroreg = tcg_const_tl(0); resultopt1 = tcg_temp_new(); @@ -418,6 +454,7 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1, tcg_temp_free(zeroreg); tcg_temp_free(resultopt1); break; + do_illegal: default: gen_exception_illegal(ctx); return; @@ -698,13 +735,20 @@ static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, switch (opc) { case OPC_RISC_FLW: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEUL); /* RISC-V requires NaN-boxing of narrower width floating point values */ tcg_gen_ori_i64(cpu_fpr[rd], cpu_fpr[rd], 0xffffffff00000000ULL); break; case OPC_RISC_FLD: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEQ); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -730,11 +774,18 @@ static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1, switch (opc) { case OPC_RISC_FSW: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEUL); break; case OPC_RISC_FSD: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEQ); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -898,15 +949,22 @@ static void gen_fp_fmadd(DisasContext *ctx, uint32_t opc, int rd, { switch (opc) { case OPC_RISC_FMADD_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmadd_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; case OPC_RISC_FMADD_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmadd_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -918,15 +976,22 @@ static void gen_fp_fmsub(DisasContext *ctx, uint32_t opc, int rd, { switch (opc) { case OPC_RISC_FMSUB_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmsub_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; case OPC_RISC_FMSUB_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmsub_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -938,15 +1003,22 @@ static void gen_fp_fnmsub(DisasContext *ctx, uint32_t opc, int rd, { switch (opc) { case OPC_RISC_FNMSUB_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fnmsub_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; case OPC_RISC_FNMSUB_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fnmsub_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -958,15 +1030,22 @@ static void gen_fp_fnmadd(DisasContext *ctx, uint32_t opc, int rd, { switch (opc) { case OPC_RISC_FNMADD_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fnmadd_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; case OPC_RISC_FNMADD_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fnmadd_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2], cpu_fpr[rs3]); break; + do_illegal: default: gen_exception_illegal(ctx); break; @@ -985,30 +1064,51 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, switch (opc) { case OPC_RISC_FADD_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fadd_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FSUB_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fsub_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FMUL_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmul_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FDIV_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fdiv_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FSQRT_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fsqrt_s(cpu_fpr[rd], cpu_env, cpu_fpr[rs1]); break; case OPC_RISC_FSGNJ_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } gen_fsgnj(ctx, rd, rs1, rs2, rm, INT32_MIN); break; case OPC_RISC_FMIN_S: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } /* also handles: OPC_RISC_FMAX_S */ switch (rm) { case 0x0: @@ -1024,6 +1124,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FEQ_S: /* also handles: OPC_RISC_FLT_S, OPC_RISC_FLE_S */ + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } t0 = tcg_temp_new(); switch (rm) { case 0x0: @@ -1045,6 +1148,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FCVT_W_S: /* also OPC_RISC_FCVT_WU_S, OPC_RISC_FCVT_L_S, OPC_RISC_FCVT_LU_S */ + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } t0 = tcg_temp_new(); switch (rs2) { case 0: /* FCVT_W_S */ @@ -1075,6 +1181,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FCVT_S_W: /* also OPC_RISC_FCVT_S_WU, OPC_RISC_FCVT_S_L, OPC_RISC_FCVT_S_LU */ + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } t0 = tcg_temp_new(); gen_get_gpr(t0, rs1); switch (rs2) { @@ -1104,6 +1213,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FMV_X_S: /* also OPC_RISC_FCLASS_S */ + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } t0 = tcg_temp_new(); switch (rm) { case 0: /* FMV */ @@ -1125,6 +1237,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, break; case OPC_RISC_FMV_S_X: + if (!has_ext(ctx, RVF)) { + goto do_illegal; + } t0 = tcg_temp_new(); gen_get_gpr(t0, rs1); #if defined(TARGET_RISCV64) @@ -1137,22 +1252,37 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, /* double */ case OPC_RISC_FADD_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fadd_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FSUB_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fsub_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FMUL_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fmul_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FDIV_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fdiv_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); break; case OPC_RISC_FSQRT_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } gen_set_rm(ctx, rm); gen_helper_fsqrt_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1]); break; @@ -1162,6 +1292,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FMIN_D: /* also OPC_RISC_FMAX_D */ + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } switch (rm) { case 0: gen_helper_fmin_d(cpu_fpr[rd], cpu_env, cpu_fpr[rs1], cpu_fpr[rs2]); @@ -1175,6 +1308,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, break; case OPC_RISC_FCVT_S_D: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } switch (rs2) { case 1: gen_set_rm(ctx, rm); @@ -1186,6 +1322,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, break; case OPC_RISC_FCVT_D_S: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } switch (rs2) { case 0: gen_set_rm(ctx, rm); @@ -1198,6 +1337,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FEQ_D: /* also OPC_RISC_FLT_D, OPC_RISC_FLE_D */ + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } t0 = tcg_temp_new(); switch (rm) { case 0: @@ -1219,6 +1361,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FCVT_W_D: /* also OPC_RISC_FCVT_WU_D, OPC_RISC_FCVT_L_D, OPC_RISC_FCVT_LU_D */ + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } t0 = tcg_temp_new(); switch (rs2) { case 0: @@ -1249,6 +1394,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FCVT_D_W: /* also OPC_RISC_FCVT_D_WU, OPC_RISC_FCVT_D_L, OPC_RISC_FCVT_D_LU */ + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } t0 = tcg_temp_new(); gen_get_gpr(t0, rs1); switch (rs2) { @@ -1278,6 +1426,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, case OPC_RISC_FMV_X_D: /* also OPC_RISC_FCLASS_D */ + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } switch (rm) { #if defined(TARGET_RISCV64) case 0: /* FMV */ @@ -1298,6 +1449,9 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, #if defined(TARGET_RISCV64) case OPC_RISC_FMV_D_X: + if (!has_ext(ctx, RVD)) { + goto do_illegal; + } t0 = tcg_temp_new(); gen_get_gpr(t0, rs1); tcg_gen_mov_tl(cpu_fpr[rd], t0); @@ -1797,6 +1951,9 @@ static void decode_RV32_64G(DisasContext *ctx) GET_STORE_IMM(ctx->opcode)); break; case OPC_RISC_ATOMIC: + if (!has_ext(ctx, RVA)) { + goto do_illegal; + } gen_atomic(ctx, MASK_OP_ATOMIC(ctx->opcode), rd, rs1, rs2); break; case OPC_RISC_FMADD: @@ -1835,6 +1992,7 @@ static void decode_RV32_64G(DisasContext *ctx) gen_system(ctx, MASK_OP_SYSTEM(ctx->opcode), rd, rs1, (ctx->opcode & 0xFFF00000) >> 20); break; + do_illegal: default: gen_exception_illegal(ctx); break; From patchwork Mon Jan 14 23:59:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1024885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="FgFoM+sG"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="hk2cv2rJ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43drBs2hPLz9s3l for ; Tue, 15 Jan 2019 11:03:01 +1100 (AEDT) Received: from localhost ([127.0.0.1]:47466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjCC3-0006fV-8H for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2019 19:02:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjC8I-0004H6-Mc for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:59:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjC8H-0001Cc-Cx for qemu-devel@nongnu.org; Mon, 14 Jan 2019 18:59:06 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjC8H-0001BK-1X; Mon, 14 Jan 2019 18:59:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547510345; x=1579046345; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=joXh3drRDsTOwGAsL9gR9z4Qal2LJiFZ37ieDgxbQAs=; b=FgFoM+sGWuX3Msi54irIAn0W1SdgTRmygBiVaSQGiclfAtmqjj9awxUb rnOEg9/tX71VSqtUkAtqmjtl/RDDwL0TSSUy3o0H8gxz8xfJjQCyoVBR+ JTrd31k2F3glWr7f8L0UvAfh5zDkOeXBnrxySti5QAjPJSMiYtuQaQChq 5Jc0FEt/ryz86G3KN+8GfyAZRItc5d2PwECT/J1BQVjKCDhWJ79gwgh8w Huioby3/d2R9Ck7SfkfIwMbqqYjy7Ul9xgIlTDJ5dEEt1BpRIjxZhLJK7 2zmjLDIqRsLu7We/bMJv+DJYNvpxSmLs2Dd3ZmxX+AvbsPrYzNz2sA+LE A==; X-IronPort-AV: E=Sophos;i="5.56,479,1539619200"; d="scan'208";a="103705301" Received: from mail-bn3nam04lp2054.outbound.protection.outlook.com (HELO NAM04-BN3-obe.outbound.protection.outlook.com) ([104.47.46.54]) by ob1.hgst.iphmx.com with ESMTP; 15 Jan 2019 07:59:03 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tKwr9XkSU1jGyi83rA9Fj4Nkve83qEa3RWeGvrIuElo=; b=hk2cv2rJ7g2LJqwb3hOviOecW0x2OK+14HDlzqpcJIR9pcaYmxel3XmkSSDrNqlao/Gt6JPFFTo8ju+6Vwnka8HkURQQ4pOeXLX6bs9QEsjXKBFPbp8E8FMQljV7FHtX68tp4wuB+RNN39S8By5bhAxJ2hhqMqaChsm1MctcnVY= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB1024.namprd04.prod.outlook.com (10.174.250.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Mon, 14 Jan 2019 23:59:01 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::10e5:e75d:3272:2d33%7]) with mapi id 15.20.1516.019; Mon, 14 Jan 2019 23:59:01 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v1 8/8] RISC-V: Add misa runtime write support Thread-Index: AQHUrGUeBB1wDhZlAU2feZRCNUR/qQ== Date: Mon, 14 Jan 2019 23:59:00 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: BYAPR07CA0015.namprd07.prod.outlook.com (2603:10b6:a02:bc::28) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.170] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB1024; 6:NMxCI+APpyGZqJvSmkQhrBBIFNFgDLqyYvShJbq2XGYkZHxynt5xcCW7A6xRUmUxo3ZLYRx4KCAfmBzwfrygqw+490vWCRERU3lktVd4YSAqqUsIei+tdICkkCxJY4EnieiP8i9+GTejGtxSPxZFCsEwduH3xuyZzcu/viSaMsMCHlSrC1ZWg22UuGmXBBFVD2QrhORlnLqws9a5cGYk7HI8qKWbFu4P5JzdQ0Y/eASHWvTMq/8h6TR/DSfAQpey4p0RVVAeiXIZkYPB5/mHTIxvDZe4l+I8TqIiCOxskknK4a4UpcFagMDRP4oHiNeZTdaTpO8BcuAPWR5lUcFbK1kRZZ/iN/MLPDgUdLbEy9OQSlcnNfmjCgiqziYwNVeI9PxHcPt2Gel3QriZdzJCagrl6v+D57bWAifcwUUC8bWv1OT0MlyYL8+RVjjFbhtqQIU82KcgouKmtzkU8TRSgw==; 5:umJ0qInNxrXloV9743hDx4o9wgOzd8c8/dwBbdfNT4mzn9OT+fpBl2iV++cca0NSkiGVMFdacuzbt5p92UelLBLNsFcZ5vrVpt0gfmdOIY+ivwoOUKL2X+fvIsU8cOcA/89M1bExcmkhHvnhueyayOPVeH5VvWzgg598oFfsQbrgRirKfaaXj0tdoPD1YYXY+79zHl4alH4VLm0tl9TJqQ==; 7:2MNIYi8um9p2Lzz/Ac9MGrRZQ4Jq1eoBOmFgOY1jWVl3bL7IqArpEJM4BtgwHZkKedu8IpqNMR14QigcXBVcykiyC1QWcReBhGcPo+PAfslAqyi7A6w92NplAIlAHEKwP2eGvzWllCVnUQSJ3bjWSg== x-ms-office365-filtering-correlation-id: 07579fc3-7ece-4a55-126a-08d67a7c411a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB1024; x-ms-traffictypediagnostic: MWHPR04MB1024: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 0917DFAC67 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(376002)(396003)(346002)(136003)(39860400002)(189003)(199004)(97736004)(6506007)(186003)(26005)(3846002)(316002)(102836004)(6116002)(386003)(14454004)(36756003)(72206003)(99286004)(50226002)(2906002)(81156014)(81166006)(478600001)(305945005)(76176011)(66066001)(8936002)(8676002)(54906003)(110136005)(7736002)(52116002)(106356001)(71200400001)(105586002)(53936002)(6512007)(71190400001)(6436002)(256004)(14444005)(68736007)(6486002)(39060400002)(5660300001)(4326008)(86362001)(11346002)(486006)(446003)(44832011)(25786009)(2501003)(2616005)(118296001)(476003); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB1024; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UzXTCvXnuDLRGijoIS+lVALXEbD8UGeJABLz5YQm+sf5yE3gnKBrzmMc3eSznipUm+ePIJKHCM7KfOdqGXH2aVufqusuTu8XrQSA63qWctIt2PbSQyVGpqsM3kRCXMYXoQdXWHud5Mh0v4N8Ay1EJ4k5nlcqyyUyZl9Gb0K0SMkTRlLBAzGB0+93Vm2ekbS5gOJh6r7c60O8gTfB2XFsZuU6VJo9OVugPciKmglx95xEBB3QSpKvacoCSjqM69oeaNG6vxVjV1MDrDU8DwdwR9Hny7sLCOPIGGB+v31u7hd5LsH/aAxQAohS1A0s0Ks4fb95JnaMXBHl1siRp7638TLXKd5qsmsXonPwx4P19FUVhWcerBbLVUmZKVY+I+xeF8L4fwdvrcyZehb4D1Jy8jRfIGUB6yurOJljRPbhHL4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07579fc3-7ece-4a55-126a-08d67a7c411a X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2019 23:59:00.4663 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1024 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.153.141 Subject: [Qemu-devel] [PATCH v1 8/8] RISC-V: Add misa runtime write support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alistair23@gmail.com" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Michael Clark This patch adds support for writing misa. misa is validated based on rules in the ISA specification. 'E' is mutually exclusive with all other extensions. 'D' depends on 'F' so 'D' bit is dropped if 'F' is not present. A conservative approach to consistency is taken by flushing the translation cache on misa writes. misa_mask is added to the CPU struct to store the original set of extensions. Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Alistair Francis Signed-off-by: Michael Clark Signed-off-by: Alistair Francis Reviewed-by: Palmer Dabbelt --- target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 4 ++- target/riscv/cpu_bits.h | 11 +++++++++ target/riscv/csr.c | 54 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 28d7e5302f..cc3ddc0ae4 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -88,7 +88,7 @@ typedef struct RISCVCPUInfo { static void set_misa(CPURISCVState *env, target_ulong misa) { - env->misa = misa; + env->misa_mask = env->misa = misa; } static void set_versions(CPURISCVState *env, int user_ver, int priv_ver) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index a97435bd7b..5c2aebf132 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -86,7 +86,8 @@ so a cpu features bitfield is required, likewise for optional PMP support */ enum { RISCV_FEATURE_MMU, - RISCV_FEATURE_PMP + RISCV_FEATURE_PMP, + RISCV_FEATURE_MISA }; #define USER_VERSION_2_02_0 0x00020200 @@ -118,6 +119,7 @@ struct CPURISCVState { target_ulong user_ver; target_ulong priv_ver; target_ulong misa; + target_ulong misa_mask; uint32_t features; diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 5439f4719e..7afcb2468d 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -311,10 +311,21 @@ #define MSTATUS32_SD 0x80000000 #define MSTATUS64_SD 0x8000000000000000ULL +#define MISA32_MXL 0xC0000000 +#define MISA64_MXL 0xC000000000000000ULL + +#define MXL_RV32 1 +#define MXL_RV64 2 +#define MXL_RV128 3 + #if defined(TARGET_RISCV32) #define MSTATUS_SD MSTATUS32_SD +#define MISA_MXL MISA32_MXL +#define MXL_VAL MXL_RV32 #elif defined(TARGET_RISCV64) #define MSTATUS_SD MSTATUS64_SD +#define MISA_MXL MISA64_MXL +#define MXL_VAL MXL_RV64 #endif /* sstatus CSR bits */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e2bd374f09..e72fcf1265 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -332,6 +332,58 @@ static int read_misa(CPURISCVState *env, int csrno, target_ulong *val) return 0; } +static int write_misa(CPURISCVState *env, int csrno, target_ulong val) +{ + if (!riscv_feature(env, RISCV_FEATURE_MISA)) { + /* drop write to misa */ + return 0; + } + + /* 'I' or 'E' must be present */ + if (!(val & (RVI | RVE))) { + /* It is not, drop write to misa */ + return 0; + } + + /* 'E' excludes all other extensions */ + if (val & RVE) { + /* when we support 'E' we can do "val = RVE;" however + * for now we just drop writes if 'E' is present. + */ + return 0; + } + + /* Mask extensions that are not supported by this hart */ + val &= env->misa_mask; + + /* Mask extensions that are not supported by QEMU */ + val &= (RVI | RVE | RVM | RVA | RVF | RVD | RVC | RVS | RVU); + + /* 'D' depends on 'F', so clear 'D' if 'F' is not present */ + if ((val & RVD) && !(val & RVF)) { + val &= ~RVD; + } + + /* Suppress 'C' if next instruction is not aligned + * TODO: this should check next_pc + */ + if ((val & RVC) && (GETPC() & ~3) != 0) { + val &= ~RVC; + } + + /* misa.MXL writes are not supported by QEMU */ + val = (env->misa & MISA_MXL) | (val & ~MISA_MXL); + + /* flush translation cache */ + if (val != env->misa) { + tb_flush(CPU(riscv_env_get_cpu(env))); + } + + env->misa = val; + + return 0; +} + static int read_medeleg(CPURISCVState *env, int csrno, target_ulong *val) { *val = env->medeleg; @@ -810,7 +862,7 @@ static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Machine Trap Setup */ [CSR_MSTATUS] = { any, read_mstatus, write_mstatus }, - [CSR_MISA] = { any, read_misa }, + [CSR_MISA] = { any, read_misa, write_misa }, [CSR_MIDELEG] = { any, read_mideleg, write_mideleg }, [CSR_MEDELEG] = { any, read_medeleg, write_medeleg }, [CSR_MIE] = { any, read_mie, write_mie },