From patchwork Thu Oct 11 20:32:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10637403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE0D7112B for ; Thu, 11 Oct 2018 20:38:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F74D2C111 for ; Thu, 11 Oct 2018 20:38:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9375A2C115; Thu, 11 Oct 2018 20:38:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EC4AE2C111 for ; Thu, 11 Oct 2018 20:38:57 +0000 (UTC) Received: from localhost ([::1]:37016 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhjV-0003KF-06 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 16:38:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhd3-0006tA-W3 for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAhcw-0006jy-5t for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:15 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:29185) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gAhcs-0006dE-CE for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539289926; x=1570825926; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=VvQPYZu0+9THdTrOuQqbqUtLtGJ24OhETy/v1CVbi1Y=; b=CcABWS2WUZYg+SpLVs5XmQeMKVwF9Ll17aYlq/Cme0LSfblOc5ff4nht QzO947VzA7FsLU0VgqUEc/BBa8Duj9C429jkPvWo4NfrInB+ESx7Kd3Vy gc8zaI1Rqco7kQ9TdvO3uae2kPgz/fM2w6wVyFpW6AotsN8Mqjj8mVXfk kx9wnWPi2hQCKZS6Ak+ZAc0mnU9X29+a23vHy70jSANFYS4HxZRaw2fJP XWyCXy66nDBcSjZXXqNpKTk7Jv/l8VdhkdAV+JjcCBYpX7rk1QOgqMRcr 2romc1p65WjDY4aY+AUDXiSFH2rW8dwpgjqL1kjL2Zc3bShjLIE5mAVUO Q==; X-IronPort-AV: E=Sophos;i="5.54,369,1534780800"; d="scan'208";a="91781679" Received: from mail-bl2nam02lp0080.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.80]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 04:32: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=VvQPYZu0+9THdTrOuQqbqUtLtGJ24OhETy/v1CVbi1Y=; b=iEB4+Sy/sJ9b+xNXT4mLOuPh+oWZsNmpWRW3yDksWrdrTX7NER6dZ8q2Up8j+ceVf8eobfj78NQwVUQhxM7fnrWcV2qptDWjE8rGMXdAR6oPwpilxfIOh2N7J7JJyva9aT4Gl332hf2EeLmbMpXcg1hSIPSvPgOduzXGw9ZKWMY= Received: from CY4PR04MB0392.namprd04.prod.outlook.com (10.173.188.145) by CY4PR04MB1224.namprd04.prod.outlook.com (10.173.193.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.26; Thu, 11 Oct 2018 20:32:01 +0000 Received: from CY4PR04MB0392.namprd04.prod.outlook.com ([fe80::ddab:bdc2:6bc7:6d22]) by CY4PR04MB0392.namprd04.prod.outlook.com ([fe80::ddab:bdc2:6bc7:6d22%6]) with mapi id 15.20.1228.020; Thu, 11 Oct 2018 20:32:01 +0000 From: Alistair Francis To: "peter.maydell@linaro.org" Thread-Topic: [PULL 07/10] RISC-V: Move non-ops from op_helper to cpu_helper Thread-Index: AQHUYaF38jKt3mieUUiTUPFngtFv+A== Date: Thu, 11 Oct 2018 20:32:01 +0000 Message-ID: <20181011203115.18666-8-alistair.francis@wdc.com> References: <20181011203115.18666-1-alistair.francis@wdc.com> In-Reply-To: <20181011203115.18666-1-alistair.francis@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SG2PR01CA0126.apcprd01.prod.exchangelabs.com (2603:1096:4:40::30) To CY4PR04MB0392.namprd04.prod.outlook.com (2603:10b6:903:b1::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR04MB1224; 6:gBmmP2XSUAqm+2225Xe6d+m0X4i+Jkq8Y5cDhGAE2mj0HOhZBdSbe9FUqOHZ8T55aGvsqYhYhKQjVu0PfT+NL9uidG84ryRhNDjsGbdykHL2Bo0JRiSEQgdnHgzJq3ejxveJyMQZFmJKyOUte/Tc2lP8hR63LbUDNeH6Ihu1b3zBdauWY9E7JK85qAyJiO+VRrm0dY1YlHgfvos97lXUlFtKRhCwEv69AOwy8pAt08vEwzgFPzWZZeJIZ+5KgYdvru63oseXyGWlb8N7NKtIehCYYof5pQGSdRevG+fGSW8bdwm0dmqy/YxCCuWlVqQUxBwekfPWOLPMA4hx/cdmCbIDvO9AFOefTaK9ol19cB3YOvD9XBBdbWF4vsV2W+jcz+Qphp4iHJ98RamaacSgA7ahZqD/uqef/XBbArSseQnk/nc+nS92TglHg+FGgP2rrl58gTDf+Umlsty+UBdoAg==; 5:KoIePT4BS+r9h7VhqhzzQIkmmMeXXqfglA3nAoGUHXgSa7i+nVxn2oux9sXHOvXj5qwo6qgPn7R4dJWweJQoKXDh1M1W6SmYvbj9exopMqcb7jnItz/BIEeidz+kpgZx192WJ7LQKBeJihYkq1bgVyX5A/GXXb0f/4ItKZ9hJ94=; 7:SS8fmiopGWfRRLjRss4tnRakbJaA1KoOst+79di6M9IhdAtAC07QUkySCsrVbhESofwxlPdBbf4oSiIKcf6/ibG69DZdLbKrSowsxOPpUWZZkA3XDk0OEnO94XpJxa+mIiRzvO54rcLbcQk8szhbbsLOUWeyBhJmyoF10tXQFLI5a6iPz9Fjx+E+Ouw0yhP0zBeHJLyY8iw0K9lVVeZ2bxz/SuaUxJRDqtmxsNrSLxyi0EkyfuEmQ+gW4tbTSE/T x-ms-office365-filtering-correlation-id: a39a5547-50a8-4189-7270-08d62fb89941 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:CY4PR04MB1224; x-ms-traffictypediagnostic: CY4PR04MB1224: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201708071742011)(7699051); SRVR:CY4PR04MB1224; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB1224; x-forefront-prvs: 08220FA8D6 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(979002)(396003)(346002)(376002)(39860400002)(366004)(136003)(199004)(189003)(81156014)(8936002)(68736007)(36756003)(575784001)(6506007)(86362001)(14444005)(7736002)(6916009)(8676002)(105586002)(76176011)(2906002)(256004)(81166006)(50226002)(54906003)(5660300001)(5640700003)(6486002)(1076002)(4326008)(52116002)(486006)(11346002)(2900100001)(102836004)(2501003)(99286004)(2616005)(6436002)(478600001)(72206003)(44832011)(476003)(186003)(97736004)(2351001)(25786009)(71190400001)(53936002)(3846002)(14454004)(386003)(106356001)(316002)(6512007)(446003)(305945005)(71200400001)(26005)(66066001)(6116002)(5250100002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB1224; H:CY4PR04MB0392.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-microsoft-antispam-message-info: 8C4fp81+6F0cqkb/TO/42Aonyp8rq241kDFIu4SrrW9Or4GhwPnXEIyND1lnEIs6+8AhRBcGJbdqMBRJvUjEsQVbJkX0qir/vlXOtm5W3UJCD1T/oJvQrpU0PSpPXR9WVjYU6/W+QiGW+sA6kAJ7vUo3cw0BGiVC8cbAxkLwO8p0PyJPr4T4jHjyXB49UvtBLW4RfOzLYfCJ8JQurHg3byVBCGdEtkHWQJ27uT6SGZ29QIjUZ/1Ikpo/ijYXqRK+zQEqf80eX9plcREv1E6FxmEN1vokidHaQvwz8xjIxk1tOTSjquHvW9pI9AprJ3psixMGgdcM6S0BtbmVQL7nzFLKDfKk4c1HUEcOHa2rLWg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <95DF030B253B324994C2EB395FCE8B05@namprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a39a5547-50a8-4189-7270-08d62fb89941 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2018 20:32:01.6018 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB1224 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PULL 07/10] RISC-V: Move non-ops from op_helper to cpu_helper 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: Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , "qemu-devel@nongnu.org" , Michael Clark , Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Michael Clark This patch makes op_helper.c contain only instruction operation helpers used by translate.c and moves any unrelated cpu helpers into cpu_helper.c. No logic is changed by this patch. Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Michael Clark Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Palmer Dabbelt Signed-off-by: Alistair Francis --- target/riscv/Makefile.objs | 2 +- target/riscv/{helper.c => cpu_helper.c} | 35 ++++++++++++++++++++++++- target/riscv/op_helper.c | 34 ------------------------ 3 files changed, 35 insertions(+), 36 deletions(-) rename target/riscv/{helper.c => cpu_helper.c} (95%) diff --git a/target/riscv/Makefile.objs b/target/riscv/Makefile.objs index abd0a7cde3..fcc5d34c1f 100644 --- a/target/riscv/Makefile.objs +++ b/target/riscv/Makefile.objs @@ -1 +1 @@ -obj-y += translate.o op_helper.o helper.o cpu.o fpu_helper.o gdbstub.o pmp.o +obj-y += translate.o op_helper.o cpu_helper.o cpu.o fpu_helper.o gdbstub.o pmp.o diff --git a/target/riscv/helper.c b/target/riscv/cpu_helper.c similarity index 95% rename from target/riscv/helper.c rename to target/riscv/cpu_helper.c index 63b3386b76..86f9f4730c 100644 --- a/target/riscv/helper.c +++ b/target/riscv/cpu_helper.c @@ -1,5 +1,5 @@ /* - * RISC-V emulation helpers for qemu. + * RISC-V CPU helpers for qemu. * * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu * Copyright (c) 2017-2018 SiFive, Inc. @@ -72,6 +72,39 @@ bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request) #if !defined(CONFIG_USER_ONLY) +/* iothread_mutex must be held */ +uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) +{ + CPURISCVState *env = &cpu->env; + uint32_t old, new, cmp = atomic_read(&env->mip); + + do { + old = cmp; + new = (old & ~mask) | (value & mask); + cmp = atomic_cmpxchg(&env->mip, old, new); + } while (old != cmp); + + if (new && !old) { + cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); + } else if (!new && old) { + cpu_reset_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); + } + + return old; +} + +void riscv_set_mode(CPURISCVState *env, target_ulong newpriv) +{ + if (newpriv > PRV_M) { + g_assert_not_reached(); + } + if (newpriv == PRV_H) { + newpriv = PRV_U; + } + /* tlb_flush is unnecessary as mode is contained in mmu_idx */ + env->priv = newpriv; +} + /* get_physical_address - get the physical address for this virtual address * * Do a page table walk to obtain the physical address corresponding to a diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index d0883d329b..495390ab1c 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -654,39 +654,6 @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src, #ifndef CONFIG_USER_ONLY -/* iothread_mutex must be held */ -uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) -{ - CPURISCVState *env = &cpu->env; - uint32_t old, new, cmp = atomic_read(&env->mip); - - do { - old = cmp; - new = (old & ~mask) | (value & mask); - cmp = atomic_cmpxchg(&env->mip, old, new); - } while (old != cmp); - - if (new && !old) { - cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); - } else if (!new && old) { - cpu_reset_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); - } - - return old; -} - -void riscv_set_mode(CPURISCVState *env, target_ulong newpriv) -{ - if (newpriv > PRV_M) { - g_assert_not_reached(); - } - if (newpriv == PRV_H) { - newpriv = PRV_U; - } - /* tlb_flush is unnecessary as mode is contained in mmu_idx */ - env->priv = newpriv; -} - target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) { if (!(env->priv >= PRV_S)) { @@ -737,7 +704,6 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb) return retpc; } - void helper_wfi(CPURISCVState *env) { CPUState *cs = CPU(riscv_env_get_cpu(env));