From patchwork Wed Apr 25 23:45:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10364409 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 1714060546 for ; Thu, 26 Apr 2018 00:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0624128F96 for ; Thu, 26 Apr 2018 00:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE81028FC2; Thu, 26 Apr 2018 00:04:27 +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 35C9B28F96 for ; Thu, 26 Apr 2018 00:04:26 +0000 (UTC) Received: from localhost ([::1]:39638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBUOf-0002FN-Fh for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 20:04:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBU9o-0005vT-3K for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBU9m-0005bv-P3 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:04 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:46984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBU9m-0005b2-HC for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:02 -0400 Received: by mail-pg0-x244.google.com with SMTP id z4so1558794pgu.13 for ; Wed, 25 Apr 2018 16:49:02 -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=aI3BivjFBLG1vHiBfjWYV3Ovq/X93VcFRBeSrrOCFvY=; b=h3k71J1wV2FuRSNoZNYAoAgnt17x+kSMfClYynRC89O3BXkI+CPTbLtvEs6Njwirt7 fk/aX6fKxi9b5lKaoJX5XjrbOI7Y+Y+4ZFf+38a6vtC4CprYleNDr/bWnlTGL/EkYThI gk/HJ904lbt3oLyi+4wIHMXhQCq6UQKKRdU90EgeQ5hsGHGzvqa0wV9Tfrk1iqsC6hcm ykEaleeAKiWlxanEz0FsMhQAhy6gHRtBlSOFTF5eKk+6GHln2UhDHVNm+mkGNN4fjLPA jESFSwU3b0rRXmB2VVY2IbwMx90M7VhSR+gKMQXGzIIu8ROENnF4Ci22JjjF2ZWa02si jyZA== 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=aI3BivjFBLG1vHiBfjWYV3Ovq/X93VcFRBeSrrOCFvY=; b=lpcZj8073JalBO4wQ9J1WVCYG5IAzG8bErQcgAPz4kQfc9doJRPzZZvD0Nt4FRhG/e YTsLYRRFTDMgIg7H+IOLdSzZHCHLlvDGHIBvo/LDYCKq49/7HCKv0sw0uRB9dq2u+0TC w/Lzr2bgqe7hqfXDBhH7pRDwKsei4WmfPiYwJs+eNOumvgw9bp8gkfrFR8kgtnrTZzVX 2ch4bmRHWUtIZzRYmVHtIyA/bo59mlU7bm5t0HkKUa0zODdpcrzgFyv+v7bysXpjSHmS Jf5/3t9VmTzVZuGeH9F36cjAvjD+25Qx7W+SB1F8IhxqD/JnMJ5wVg45UGjdSjoVCZvP +jXQ== X-Gm-Message-State: ALQs6tAFyWtmK8+Jwaf+ZR+vH/W7UbGxpM9+MevZZAGyRPZDrgT+LNoy nlr1zdIsgKGJduIwf3H9OXPvKKHEnF4= X-Google-Smtp-Source: AB8JxZoDi8r18cunndteI/h5vPx49bR8qIHC6IMfFiqDxe5+1KHZEf3jtpAy31sswCJ30laaumQYIw== X-Received: by 2002:a17:902:b90c:: with SMTP id bf12-v6mr9581949plb.37.1524700141537; Wed, 25 Apr 2018 16:49:01 -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.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:49:01 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 11:45:34 +1200 Message-Id: <1524699938-6764-32-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:c05::244 Subject: [Qemu-devel] [PATCH v8 31/35] 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: Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Richard Henderson , 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 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 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 ecf74a0..e005285 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -325,18 +325,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 4180c42..442c8cd 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -659,6 +659,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) { @@ -687,6 +712,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, @@ -984,6 +1011,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; @@ -1046,6 +1074,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: @@ -1075,6 +1104,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: @@ -1125,6 +1155,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: @@ -1217,6 +1248,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: @@ -1246,6 +1278,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: @@ -1293,6 +1326,7 @@ static void gen_fp_arith(DisasContext *ctx, uint32_t opc, int rd, default: goto do_illegal; } + fp_output = false; break; case OPC_RISC_FMV_D_X: @@ -1309,7 +1343,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); } }