From patchwork Mon Oct 8 18:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10631257 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 55CE8174A for ; Mon, 8 Oct 2018 18:29:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49AF32943B for ; Mon, 8 Oct 2018 18:29:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D2B029733; Mon, 8 Oct 2018 18:29:32 +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 A16742943B for ; Mon, 8 Oct 2018 18:29:31 +0000 (UTC) Received: from localhost ([::1]:47791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9aHb-00080s-0O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Oct 2018 14:29:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9aDp-0004aF-2E for qemu-devel@nongnu.org; Mon, 08 Oct 2018 14:25:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9aDl-0007bY-Lx for qemu-devel@nongnu.org; Mon, 08 Oct 2018 14:25:37 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:49701) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9aDk-0007Vf-7l for qemu-devel@nongnu.org; Mon, 08 Oct 2018 14:25:33 -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=1539023132; x=1570559132; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Mvv4j0zFn1+JvLZ9WYxIZYky2d/FfgepaGHEFn7gZPI=; b=nkprQr6kdbuBpWG0P5yb6X1lkJXWJZ0XkcfT+WAGZzMHa0THKHcgLn5k 3iHiOsvooiCuXCaHuttkwoy31nvqEBtBli5y6taWW0/DP3VrOGpzXC5y3 IQRMQS1BOZV/gs4e5G+bIevB3WbuZAhPPpdsNJOp5ryvhwm6AcEMU1q21 H0bY8jHdeN9OlaZo9ZLjEWsqnwJC/r0snIISbyWfpeQxUE238a1kMQVHW AOAcKvdZJLIXXcWr6jMlm+mkMpn5yK7lFoY7pEVE3/XUmeHBdAyhXYUjE l7xTR+f3k2INZ403EEk5tvWmBK8UZJIUqKjWJC4UNzvh/o1u204sC/o5R w==; X-IronPort-AV: E=Sophos;i="5.54,357,1534780800"; d="scan'208";a="96068098" Received: from mail-co1nam05lp0079.outbound.protection.outlook.com (HELO NAM05-CO1-obe.outbound.protection.outlook.com) ([216.32.181.79]) by ob1.hgst.iphmx.com with ESMTP; 09 Oct 2018 02:25:28 +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=xAKhuuHl6HPCrT2Qd4H3f+ZCP6Tp2apu/M6nApzv02o=; b=eNGv0oy99x2Y6i8tjzMA2KZOPhLgVXLq2ZCmSGbKkjv7l2HqxFhbYvlEx8XPVTuVSuI204fRIo+8wHZmwuQWwDLWDIWaKDP/OeW4wLxQN3L8j5PalpSE1HgVbQRWvxD3pyDQLMTbnPqbEM8E6xS8pHdfUeCMmsWJSPszZKaCJZc= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0609.namprd04.prod.outlook.com (10.173.49.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.23; Mon, 8 Oct 2018 18:25:27 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::f94c:102e:8dce:7c02]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::f94c:102e:8dce:7c02%6]) with mapi id 15.20.1207.024; Mon, 8 Oct 2018 18:25:27 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "mjc@sifive.com" Thread-Topic: [PATCH v1 2/5] RISC-V: Move non-ops from op_helper to cpu_helper Thread-Index: AQHUXzRJN8oZEYjenkGXJp6qJXsjnQ== Date: Mon, 8 Oct 2018 18:25:27 +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.17.1 x-clientproxiedby: BYAPR07CA0056.namprd07.prod.outlook.com (2603:10b6:a03:60::33) 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.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0609; 6:93wa9aI5Vuq22eWLhWRpjody5mZI8a+UnpfJzsG6IP+XI8EpUhPAadpHedUEeRKu1sRkBnn4InCA4IMQ7ogyGwITVO5r87i4b4hSITOX/wUzSb2tJ5XhZ93wtYPRz4hijQN0V7fmNsa/qGEQiS3elKicRN9lMqhNKZYsxC2EXcnz3Gq0syzAzJvJOeW4sbcxrqyVJ/zAfVCbk4v+dNw9U7cfFYD9UbUDL2HlyEQXikjUdw9AuCGf4bFu5V1JWBOVKSK8xRpKERA4yXoOr1CTp53C7NsP2Z1tKsRLobmPLU3Sm3RgyQoa2b2foSXHdBoe0EFfW95kf6Q9mC5gPpLzou7F5kQidVG7B+SNk45zC/C3lJISVFhCX3e5LVp4JJqAP0MFj5hZB2fbQc4cTGBALWubc1icClKjIPEtzzmeEeqSErBzb+tcG7rFhUdFbrQsKQf3Cu+ZD56OCjGYZXnpgw==; 5:JPBdx+IYEvTTnA506c2omhpwS9kiIUXGbgDj46Km6co7lVhaNuymZXWt8b4u69Bb9vjNWDfegqCr59p3R8qfVmI6we0TKMwFJYsLDg5S+IqHDeorLLSwfZB8A5xkDqOWs/BKMqCJU4Gpe38oFIqhxbssu/qtrEF77vPskLf8ALs=; 7:JYXquuoKEvyTQTNzD6DKdB5NkA364yD/GONNPvfeKQY4vrvMmh0Qj/DNROMUHOrFi1+6Y+nauHSkpCUvgpRBusMynQdrhie7aZ20p8AJB7bnPERRXxLxQeYtR5F5fYRuDr4y6t/jT3TboOjslv/e9LMKNzj53saG5E/Ec3XZB4ZmEjjRMQfk991JCwCGlzUtPv1PcWP6EbD6tHZOjKv5ckq+k/3RNXYuK+96LpfIeRMPw/KnX6z7sAzdiStTRkzn x-ms-office365-filtering-correlation-id: 2f0eefe4-6d4e-40d8-c8b6-08d62d4b6b70 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0609; x-ms-traffictypediagnostic: MWHPR04MB0609: 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)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(201708071742011)(7699051); SRVR:MWHPR04MB0609; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0609; x-forefront-prvs: 081904387B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(376002)(366004)(39860400002)(346002)(199004)(189003)(118296001)(106356001)(105586002)(14454004)(86362001)(575784001)(44832011)(478600001)(71200400001)(72206003)(486006)(39060400002)(97736004)(5250100002)(2501003)(476003)(316002)(25786009)(4326008)(2616005)(2900100001)(71190400001)(446003)(36756003)(102836004)(2906002)(26005)(186003)(11346002)(110136005)(256004)(6116002)(3846002)(7736002)(99286004)(66066001)(305945005)(8936002)(6486002)(54906003)(50226002)(6436002)(8676002)(53936002)(76176011)(81166006)(14444005)(68736007)(52116002)(6512007)(81156014)(5660300001)(6506007)(386003); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0609; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-microsoft-antispam-message-info: sJA14VdIcpoLG9qRdg1bPEJTeWSQpg7OyVh/mxp5OOkpw/me8PaaB1vP6vCdgtl2Isg4wcQkG2yxKM/764sQUnMwLYBLbr2hogBh4IVJlDPUeJWElUEFROMKmmdpAAw/qaZ5614e2Zg1sFoQZ8iKrXfb4SzBxxSup8oscj7+/n94TeDug/7lwAnGrOmzORktXEtH/v8aFupsZ8+ESEgSlZ5fRcS2mWUjL/WGcYUZ5KSkHxBKHDZVnu2UKorUcqa1uq1Epb6MSUQJw2RlZki5l0CAhdRskjMSwuq2x36YuvIqf5oHjZ7+3k+7gs0pxMyLEhE2EWMpCPUpvj2aK9RXSJNtvYUeUPsMIXjvSI6hhek= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f0eefe4-6d4e-40d8-c8b6-08d62d4b6b70 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Oct 2018 18:25:27.1767 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0609 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 2/5] 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: "alistair23@gmail.com" , 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 --- 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));