From patchwork Fri Oct 22 13:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 516137 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp1116148imj; Fri, 22 Oct 2021 07:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIpMmSP+fyN7GrNkise1DEH/gDAz8QcLQooAIPprEPqOFYkKk7ssm2bCXnFN4P/ewgI+Zo X-Received: by 2002:a4a:3315:: with SMTP id q21mr175081ooq.12.1634911301652; Fri, 22 Oct 2021 07:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634911301; cv=none; d=google.com; s=arc-20160816; b=NXazUSOhEpHsqSh1Yi33ofLe6zkPRvmOJ0uoeSlRHckt4AU2GJfG/pvQTSZz6Kg1Ig /OUfUVe5crolGBRN7xw++quW1EOQVHJ8PTGUz5kq+ukgojA1Z4CDJIVtUHQOm4nJM5Ro lunHndBRz+BlegzA8ZEeqQdGet8WJxO3vQXhvblbakryQ7tC19itF9EPbfBodhQo7bYY 6zQqallf7kwnJX9cxL54baI9+PCAiiWxsZ6D3Yi82c52/KAk3UYp1vze03AZ8Vk2ab4k YF4+2L9w9tBbaR8GFp8jpRbdpWdBmUbjaHUAtaiatAa5oRv8FTO0Nvg0a1vL4q6hZQ6v MyBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=pRDoh7tc+GJUsi6XlCXCMSC95KZJiko+Ndby7lWiGKU=; b=G8usiCzwqHa8SiF1AeHhCclS/qknAG1qwCAg9XZIE+YkaH1QqS0pwJYF9/q6qYA2wY fc1RriXtmTXy4BlWveZ0Zl7ci2WPFm9wXcW6VEEreLBtYteRFzT6dc/WbKBz+Bij6EgB iPPB9bbtWZuPo8Xblg72yQ5L4MqibGLBVsbF2+rPNUE6KsJcHjRyvGvkuTVASYlW1H6M HaEIzNIDNeItLWRXtCt2mjqOIcm4kPr0V09xGH95S89lxf9/tJjHRR6v8wntoAyGscKm EUUSLZ0H/Cpes4019JjuploFo7XZKo9Ngcuo6Ci/IYxQD9tbcaMAsdqs/Tj4X5+Zs+Xy zptw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b="ovx/MyhX"; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=PasnbfC1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b12si15305128ots.285.2021.10.22.07.01.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Oct 2021 07:01:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b="ovx/MyhX"; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=PasnbfC1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=opensource.wdc.com Received: from localhost ([::1]:44958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdv76-0004oP-Gk for patch@linaro.org; Fri, 22 Oct 2021 10:01:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdumg-0001pO-TP for qemu-devel@nongnu.org; Fri, 22 Oct 2021 09:40:35 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:39690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdume-0001Qs-Hd for qemu-devel@nongnu.org; Fri, 22 Oct 2021 09:40:34 -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=1634910031; x=1666446031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4DS/XWr3pNjpqgLBujVnjAyIdXduE58PjNTGgxFTWEo=; b=ovx/MyhXjkXaaIREObIcW6B+oYIPxNmFSnwYkD835IRzeaYnSKoQG8Gq Nik80ikYGAzXLutBGjfVc1LlSnBzJvP+gMeaEqXlNRPb5vbNku/0ZqmKc tTrQh9D2XAeSRufjJsv65wYmP3uMXX6IRQF+9g3h8D6Kr4BK8yeXrkhio oMx2ns6g6ZB9OfP8AR4yzVQ4SAkGmYK29VAwwnkvOpwLnZHUmS7zU3hCh kmrHnb5Ybf0+IZZ6CtCToIfHrQ3vYGU5fH9HkMXDqwQcfqOU7pRuKvBFX GGqZ8JxXAnD6tAY6An4Q9FR0WcaQbAJNXFS7PE04S3NmZhp8ExQyz24tt A==; X-IronPort-AV: E=Sophos;i="5.87,172,1631548800"; d="scan'208";a="183617898" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2021 21:40:30 +0800 IronPort-SDR: cFGNN7LcRtIkp4P5ecpbyJ/xLy3P27nrpkiS22V08EJgmchafsxgFIrBVEQ3v2cpzk0KIQIdqF wRGICq0mieQ2T5FqB0kfMaZBDp/x0npXvvTs0Ym+WFicVSZHa8K28HUjbgY/UyksCTzD8wKXMh 9I46edgN5fD6z7izn5bXCGhYbXwrOS6vgPu5eWo1HG1Ksd4hQq0ItHiPYlOV9cF4hYi1ODELJS MAscFhBBdTVVBZ4fVkep5VwyaNN3srzNRTWP/J6mdfdTlNdvN415Wq4e+dSpVTlQGT5H9SEWFe SxPCgBV7KWpUv4RmuIfXo6iT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2021 06:16:06 -0700 IronPort-SDR: 3bF9b45U+KdAanXmGFFBZYQE/pIoOjZZ1WLlA0hVdzj/g1Lr+7ceGfCXeMceHqXf6MQvZ1idjW hD7BPvgs/wDpdj/yJVCVHqi4bulDGevsZ+1bMHzx+N8tbkBpIIU+u4d5Ugpjkwt8BDBYSQcWv2 MABN1sGGO3ugb66Sg0w8AUhA4f4PSd87sIj3O0DXX04JtHu2nWShdfd7XendnMEr9SQwxxD/Sz +VWwxaCm7XfdMOqkquqt8md3AJei1uAQKoFmKnTfuTWKsdN+7ag1hZVmJEsRjymf6WFIeOAyHE Q9s= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2021 06:40:32 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4HbQTW4DCnz1RtVn for ; Fri, 22 Oct 2021 06:40:31 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1634910031; x=1637502032; bh=4DS/XWr3pNjpqgLBuj VnjAyIdXduE58PjNTGgxFTWEo=; b=PasnbfC18qRHh3IvS73qg3+V1KN8SrzdOb 9w71ySwTpm00kzXc+YYVZL39R2F+Ki2oWJO3/OO4P3qPjnoo+y2VvuIZ8nErB7e/ bUSC8M08JR738BeZJIj+WXTbUr5YnTLw3pZOYlupCP9D2w2yjQ+I9goNgxkQZC9o 89iZ23JRCm6efg+L1YnxKncoesQ4sWFL0fjR8ZCLHcobCywKGIvhbMRgaqFW2/dj UXY0cHg8sO9TF/3kVi9i7ILq1nBeOK1/Qd+N/Hd4VV/ADPfWH/fJGqrObpluSHeg /4OGQ2p1v1Evu/4602FUjCJ6tipKBTKCbFatZXpqU4ORzj/+EQQA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id oUlvDIMJA908 for ; Fri, 22 Oct 2021 06:40:31 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.39]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4HbQTR4c5rz1RtVl; Fri, 22 Oct 2021 06:40:27 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL 22/33] target/riscv: Compute mstatus.sd on demand Date: Fri, 22 Oct 2021 23:38:01 +1000 Message-Id: <20211022133812.3972903-23-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211022133812.3972903-1-alistair.francis@opensource.wdc.com> References: <20211022133812.3972903-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=9222bbd82=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The position of this read-only field is dependent on the current xlen. Rather than having to compute that difference in many places, compute it only on read. Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson Message-id: 20211020031709.359469-16-richard.henderson@linaro.org Signed-off-by: Alistair Francis --- target/riscv/cpu_helper.c | 3 +-- target/riscv/csr.c | 37 ++++++++++++++++++++++--------------- target/riscv/translate.c | 5 ++--- 3 files changed, 25 insertions(+), 20 deletions(-) -- 2.31.1 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 429afd1f48..0d1132f39d 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -185,10 +185,9 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env) void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) { - uint64_t sd = riscv_cpu_mxl(env) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD; uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS | MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE | - MSTATUS64_UXL | sd; + MSTATUS64_UXL; bool current_virt = riscv_cpu_virt_enabled(env); g_assert(riscv_has_ext(env, RVH)); diff --git a/target/riscv/csr.c b/target/riscv/csr.c index c4a479ddd2..69e4d65fcd 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -477,10 +477,28 @@ static RISCVException read_mhartid(CPURISCVState *env, int csrno, } /* Machine Trap Setup */ + +/* We do not store SD explicitly, only compute it on demand. */ +static uint64_t add_status_sd(RISCVMXL xl, uint64_t status) +{ + if ((status & MSTATUS_FS) == MSTATUS_FS || + (status & MSTATUS_XS) == MSTATUS_XS) { + switch (xl) { + case MXL_RV32: + return status | MSTATUS32_SD; + case MXL_RV64: + return status | MSTATUS64_SD; + default: + g_assert_not_reached(); + } + } + return status; +} + static RISCVException read_mstatus(CPURISCVState *env, int csrno, target_ulong *val) { - *val = env->mstatus; + *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus); return RISCV_EXCP_NONE; } @@ -498,7 +516,6 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, { uint64_t mstatus = env->mstatus; uint64_t mask = 0; - int dirty; /* flush tlb on mstatus fields that affect VM */ if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV | @@ -520,12 +537,7 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, mstatus = (mstatus & ~mask) | (val & mask); - dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) | - ((mstatus & MSTATUS_XS) == MSTATUS_XS); - if (riscv_cpu_mxl(env) == MXL_RV32) { - mstatus = set_field(mstatus, MSTATUS32_SD, dirty); - } else { - mstatus = set_field(mstatus, MSTATUS64_SD, dirty); + if (riscv_cpu_mxl(env) == MXL_RV64) { /* SXL and UXL fields are for now read only */ mstatus = set_field(mstatus, MSTATUS64_SXL, MXL_RV64); mstatus = set_field(mstatus, MSTATUS64_UXL, MXL_RV64); @@ -798,13 +810,8 @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, { target_ulong mask = (sstatus_v1_10_mask); - if (riscv_cpu_mxl(env) == MXL_RV32) { - mask |= SSTATUS32_SD; - } else { - mask |= SSTATUS64_SD; - } - - *val = env->mstatus & mask; + /* TODO: Use SXL not MXL. */ + *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask); return RISCV_EXCP_NONE; } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index bed1c2174e..d38f87d718 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -280,7 +280,6 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) static void mark_fs_dirty(DisasContext *ctx) { TCGv tmp; - target_ulong sd = get_xl(ctx) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD; if (ctx->mstatus_fs != MSTATUS_FS) { /* Remember the state change for the rest of the TB. */ @@ -288,7 +287,7 @@ static void mark_fs_dirty(DisasContext *ctx) tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); tcg_temp_free(tmp); } @@ -299,7 +298,7 @@ static void mark_fs_dirty(DisasContext *ctx) tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); tcg_temp_free(tmp); }