From patchwork Wed May 23 00:15:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10419803 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 D9C3D6032C for ; Wed, 23 May 2018 00:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8BA428CC9 for ; Wed, 23 May 2018 00:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCB7B28E57; Wed, 23 May 2018 00:22:05 +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 1D04028CC9 for ; Wed, 23 May 2018 00:22:05 +0000 (UTC) Received: from localhost ([::1]:58517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHXY-0003bM-CE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 May 2018 20:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHTG-0008IO-0L for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLHTC-0000tg-Oo for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:37 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:35877) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fLHTC-0000tL-II for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:34 -0400 Received: by mail-pf0-x241.google.com with SMTP id w129-v6so9555566pfd.3 for ; Tue, 22 May 2018 17:17:34 -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=NCsbTT4J2weSJu+y1g3YLD+VmlO2WMnLT7XNbnMRm0A=; b=NbLTzwqmcnN8ZnuejVTgbIsMErj9QcypaARN1OwMbz0XTvGQl11qY4rNXKPMckWPWK VXzCQPgDr17rWekZx2VQEhlKWaXLx0HgnbgwGSJ3qMnQxG+Toy2vScxmpJslMUJg2EPN 1ZX8y5TbVfeoAGWUIVKhoFowwDRlYLCKw/+T9fKVEX85TmR2zKbDXac/xVSa9ldkAk2C YSCCPz7pat+1UwxQB+qzvyLhZvV/bu3x8WMwF9vErMM+04Iu90ysmCAO41j50E/nuFLD hbIdbDS9m1no4MipuV1VBbCKzWoTVOqDpcX/gl8uAb6xJ2yFF/i3SLoDj2yYRklF1Nhw i4wA== 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=NCsbTT4J2weSJu+y1g3YLD+VmlO2WMnLT7XNbnMRm0A=; b=jXMNXot+Z7a0THl6rZJXdvPi4mmmN47Ks28tv4Rc8BQl1jNVEuLNWlT3c6F95KtMR/ 8CEPwQVnC90Pyefhs1qdMvZzb9N1/ZP28d4Ir37ZfBPwX5d7mljhivXaRMMvlt7gYGM2 PFreQ2V6acMRSlx8Fz3ntgYLEunuwz1nf6jnZ6ZCKYSw4WzkawljFB+a1JeEbxeaN01y SlDzPNI+jOUUp5o4su8hh8s5n7/0eyu7EBLUn+C/tDABzlEg6QFKTRbQWHgX6tpls4xP uZ3qNBN8GJy6TAdarUeZrZyu3KTNr45vGIBJbtMDDzBeoSAjf+7xnUVd+EYr04jdnEcS 4V0A== X-Gm-Message-State: ALKqPwcXNnhHWlqVbWZlhY7JqpB6C6ubzATmirJOJKnjwGsjwjcyp3XI u12VS7qq5meRYCujF4DHsqTWzLImfFM= X-Google-Smtp-Source: AB8JxZryLbnLG4jmAQ3Q307oqYnaXOExfFyWbYv11Bpz2npKCktkW7xo3SyejMcasxJscPdbawfFhw== X-Received: by 2002:a63:4d2:: with SMTP id 201-v6mr472834pge.129.1527034653633; Tue, 22 May 2018 17:17:33 -0700 (PDT) Received: from localhost.localdomain (122-58-167-22-fibre.bb.spark.co.nz. [122.58.167.22]) by smtp.gmail.com with ESMTPSA id j1-v6sm28935626pfh.95.2018.05.22.17.17.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 May 2018 17:17:33 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 23 May 2018 12:15:00 +1200 Message-Id: <1527034517-7851-14-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1527034517-7851-1-git-send-email-mjc@sifive.com> References: <1527034517-7851-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::241 Subject: [Qemu-devel] [PATCH v1 13/30] 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: Matthew Suozzo , 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 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 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 b4452388ff02..509215327243 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -313,7 +313,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 */ @@ -654,7 +655,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; } @@ -675,8 +680,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 81bd1a77ea90..77c79ba36e0b 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 */