From patchwork Wed Apr 25 23:45:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10364431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9183A6032C for ; Thu, 26 Apr 2018 00:13:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EC8C2900B for ; Thu, 26 Apr 2018 00:13:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 714D129011; Thu, 26 Apr 2018 00:13:48 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 B5BA52900B for ; Thu, 26 Apr 2018 00:13:47 +0000 (UTC) Received: from localhost ([::1]:39689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBUXj-0000qs-2Z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 20:13:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBU9S-0005Yh-6k for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBU9P-0005Qa-3v for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:42 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:44924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBU9O-0005QK-RZ for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:39 -0400 Received: by mail-pf0-x244.google.com with SMTP id q22so1645511pff.11 for ; Wed, 25 Apr 2018 16:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=36sKRkTlv1aMMhbl8TVkXB0dG88YepXdOut2BjBBZxo=; b=YKb/HqnQCjPG51bKcr7Np3dCYHOAeOeJI2C9/d8xa+8TkP9wtB8MbTQnmQA1wj9sFJ iOyHBDbZ1PIZ4++/bK5cHBMX4hZX94MCO1uooZ2ik2K8nVqti/tXrcfhpjoiiKkvSgTQ xCg7eu6va+WoTdwC+FbD3I0RaiXytF06ZwLLLfzLcLdBJ1On9mKBOltucefRVb+YM83J lE5XckyiGZtO7pSw9Xdg5mBBofalUl2nGB6Epl/2BfVIoxbwfgDt+94EyEEYjxCneaYF 7k47rL8YwMptFS2J48FFZCwRLUXUen9uoAu0w5502FfSEiWUii6sbBlwHe4HDu/Nqo7f 5Lsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=36sKRkTlv1aMMhbl8TVkXB0dG88YepXdOut2BjBBZxo=; b=J7JZy+2VD4YKhB7eVKVBecmL02Eb7QUxCxi2YOpWPYMzknsZh62KEgUMhknVatxqwO u7Pvuw0wdKrGyQlYP3coGuor1BUkbCcBKiqoRQM0/WKclyCrplq28roXPKW9+X354mYL e4gVWr1uS3bz56VmvVHoXMnnR7iyLW27MRN/xkPUbhyHxPDMxbWCeNX2nHBJrinl8qDH gPVJl+4gE33uT4Tye2EUlYsJuRN64qDb4pCyMkZ6CKf9fI2n9bpN/obzEhKd+dJjtTsq bmSdRfKniW8/1OlhA9hupeteIz22j2vUuF/u/1yJ2jDH9tPQH3lwydhutaCKxzFzTKKX z0Jg== X-Gm-Message-State: ALQs6tBUireWVXiP9iHjvrtVy9GHnC5k5hcDqsXd8l6ZAo6MCCjGl3WJ V2zLFk7Tg/Exi3WOaj6Me+8L+3t5NfY= X-Google-Smtp-Source: AB8JxZpC/rB2EzohNS2o8qxstsS1kSqwVgA5p73ttQfHZU8NYxK664M9IFdvkAJLwM33dmlRx9gR5A== X-Received: by 10.98.29.82 with SMTP id d79mr5090601pfd.230.1524700117821; Wed, 25 Apr 2018 16:48:37 -0700 (PDT) Received: from localhost.localdomain (122-58-167-38-fibre.bb.spark.co.nz. [122.58.167.38]) by smtp.gmail.com with ESMTPSA id e10sm29577549pfn.67.2018.04.25.16.48.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:48:37 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 11:45:28 +1200 Message-Id: <1524699938-6764-26-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1524699938-6764-1-git-send-email-mjc@sifive.com> References: <1524699938-6764-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v8 25/35] 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 , Michael Clark , Alistair Francis , patches@groups.riscv.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- target/riscv/Makefile.objs | 2 +- target/riscv/{helper.c => cpu_helper.c} | 34 ++++++++++++++++++++++++++++++++- target/riscv/op_helper.c | 33 -------------------------------- 3 files changed, 34 insertions(+), 35 deletions(-) rename target/riscv/{helper.c => cpu_helper.c} (95%) diff --git a/target/riscv/Makefile.objs b/target/riscv/Makefile.objs index abd0a7c..fcc5d34 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 47d116e..fb3f7ef 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,38 @@ 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_mip, new_mip; + + do { + old_mip = atomic_read(&env->mip); + new_mip = (old_mip & ~mask) | (value & mask); + } while (atomic_cmpxchg(&env->mip, old_mip, new_mip) != old_mip); + + if (new_mip && !old_mip) { + cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); + } else if (!new_mip && old_mip) { + cpu_reset_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); + } + + return old_mip; +} + +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 2a7f045..4b4d62b 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -640,38 +640,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_mip, new_mip; - - do { - old_mip = atomic_read(&env->mip); - new_mip = (old_mip & ~mask) | (value & mask); - } while (atomic_cmpxchg(&env->mip, old_mip, new_mip) != old_mip); - - if (new_mip && !old_mip) { - cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); - } else if (!new_mip && old_mip) { - cpu_reset_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); - } - - return old_mip; -} - -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)) { @@ -722,7 +690,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));