From nobody Sun May 12 20:25:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1664981600; cv=none; d=zohomail.com; s=zohoarc; b=E2wGOTeKpErNcRQ6cWIJydQxSAX5hk7Fwmwss9gwruuoR3FhQ8wMjeAqLzfOKRJSk8ODFlz6LamoQhrFUJdcHpeNBF3NOW10BWFZRU5fMfdkHzIbLybt+o9JnYULiGBX9FfOyJbCdZ8gv8H10G+XKS8MuBr7jlPbGNj3wP+xXXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664981600; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=EXf432YdLxs6LN/1SdCnkgTiHy1iNPRF9DC1hWNzFo4=; b=ZZu71U/Oq0rkYq5Dxnpp+9QrwcY61hD/FV0Z4tHMKZH1AYB/Wr2rixti3MsRXw4QCO2L3QZB0azAvJFZ55WvnSy/PmqY4UQ0U1VPxgq4bpUoDBtJ8PR2+vXmG2Maeu4YZsM3aWgMSLpY5kBlHLrb5ptaYho3SY4E4Q1VYB9wDxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664981600035889.9826675799401; Wed, 5 Oct 2022 07:53:20 -0700 (PDT) Received: from localhost ([::1]:41926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1og5lu-00035H-3Z for importer@patchew.org; Wed, 05 Oct 2022 10:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1og5ie-0000Fz-F9 for qemu-devel@nongnu.org; Wed, 05 Oct 2022 10:49:57 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:34411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1og5ib-0006Rk-V7 for qemu-devel@nongnu.org; Wed, 05 Oct 2022 10:49:56 -0400 Received: by mail-ej1-x62f.google.com with SMTP id au23so15236442ejc.1 for ; Wed, 05 Oct 2022 07:49:52 -0700 (PDT) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id q1-20020a17090609a100b00772b5835c12sm8829932eje.23.2022.10.05.07.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 07:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EXf432YdLxs6LN/1SdCnkgTiHy1iNPRF9DC1hWNzFo4=; b=cH0DxkuSEFwVdgeVS6cNGK4+cY8LokwB7PjH6wlJ/9z3a//Wii/qZ6f/HQrEm6ThnA ICOeVyDnaBZixD0LQ7c/U3Y7AnDqR/oLEu4i3UestXYYMMDwg3nM+VKGdWrcasix14CX tH/pnT3DrTooa08O4yubolwjulZ+GiL1rgFeituxQISXUTDfv3Ga69xbp3inuKQ2lTx7 qA+LQYEcNN6G/XYmhV5VezvwWKGimOwGh8/mlDKUgB+xaSmmeFmwdX7RgkTFPsDT6X+c iavyUD2BH4soU7PE2NufVc2Bd0/DLq3yWxEP+K4SIvMEWGuRF2dbfuEgwYQUR1hcq6Wd eaZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EXf432YdLxs6LN/1SdCnkgTiHy1iNPRF9DC1hWNzFo4=; b=xtV9ysSusCBRVwKG8Poa9nVjh6MKjLUKJhcyIRzg8BnUQimxP3fTD0z/xTUwIaCaoZ ADDY6FEGQCPUQXgQPo+mT14acMMI/C4r97iwJwvzum6eQnKZpNQoB2dcaCmT7LjJew+L tVau/oFRksvxW5go2YKWZFuTEJnjzB+LLutxN0tJdBMFdU1Pn1+CquoM7ZSBlJckWFia /b1y4ju6+RJfxic6DPme+BxT8jmkiCrFUqwNN8GTChP6gEK7ZvDy2h8NdDKh/icklwXO fN2xYj0loVfAkUeBRa5/UlUulU+Qk7bEXw8hREFme4aCGGRDhapnYY3zpuxeCmKqbjAa kJ3Q== X-Gm-Message-State: ACrzQf0TjRGsGgv4mhjWdSvX1EehBGPFBiK4OAuzGh7JwXPeUaQig4q0 RBRzbZzt962k5vil5EiEyi5Z/w== X-Google-Smtp-Source: AMsMyM5ReyrcD9OdIVSmiJyA2qDmvp8aoZPxiDJZMJM+v2ra4+PnEz2q9a6AT6Ly9ty1VhCeHDZJ9A== X-Received: by 2002:a17:907:608b:b0:78b:cb91:6efd with SMTP id ht11-20020a170907608b00b0078bcb916efdmr11795ejc.32.1664981391687; Wed, 05 Oct 2022 07:49:51 -0700 (PDT) From: Christoph Muellner To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Alistair Francis , Bin Meng , Philipp Tomsich , =?UTF-8?q?Heiko=20St=C3=BCbner?= , Aaron Durbin , Palmer Dabbelt , Richard Henderson Cc: Christoph Muellner Subject: [PATCH v4] RISC-V: Add Zawrs ISA extension support Date: Wed, 5 Oct 2022 16:49:48 +0200 Message-Id: <20221005144948.3421504-1-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=christoph.muellner@vrull.eu; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @vrull.eu) X-ZM-MESSAGEID: 1664981600771100001 This patch adds support for the Zawrs ISA extension. Given the current (incomplete) implementation of reservation sets there seems to be no way to provide a full emulation of the WRS instruction (wake on reservation set invalidation or timeout or interrupt). Therefore, we just exit the TB and return to the main loop. The specification can be found here: https://github.com/riscv/riscv-zawrs/blob/main/zawrs.adoc Note, that the Zawrs extension is frozen, but not ratified yet. Changes since v3: * Remove "RFC" since the extension is frozen * Rebase on master and fix integration issues * Fix entry ordering in extension list Changes since v2: * Rebase on master and resolve conflicts * Adjustments according to a specification change * Inline REQUIRE_ZAWRS() since it has only one user Changes since v1: * Adding zawrs to the ISA string that is passed to the kernel Signed-off-by: Christoph M=C3=BCllner Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 7 +++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzawrs.c.inc | 51 +++++++++++++++++++++ target/riscv/translate.c | 1 + 5 files changed, 64 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzawrs.c.inc diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index b29c88b9f0..b08ce94ba6 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -76,6 +76,7 @@ static const struct isa_ext_data isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zicsr, true, PRIV_VERSION_1_10_0, ext_icsr), ISA_EXT_DATA_ENTRY(zifencei, true, PRIV_VERSION_1_10_0, ext_ifencei), ISA_EXT_DATA_ENTRY(zihintpause, true, PRIV_VERSION_1_10_0, ext_zihintp= ause), + ISA_EXT_DATA_ENTRY(zawrs, true, PRIV_VERSION_1_12_0, ext_zawrs), ISA_EXT_DATA_ENTRY(zfh, true, PRIV_VERSION_1_12_0, ext_zfh), ISA_EXT_DATA_ENTRY(zfhmin, true, PRIV_VERSION_1_12_0, ext_zfhmin), ISA_EXT_DATA_ENTRY(zfinx, true, PRIV_VERSION_1_12_0, ext_zfinx), @@ -744,6 +745,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error = **errp) return; } =20 + if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { + error_setg(errp, "Zawrs extension requires A extension"); + return; + } + if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { error_setg(errp, "Zfh/Zfhmin extensions require F extension"); return; @@ -999,6 +1005,7 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), DEFINE_PROP_BOOL("Zihintpause", RISCVCPU, cfg.ext_zihintpause, true), + DEFINE_PROP_BOOL("Zawrs", RISCVCPU, cfg.ext_zawrs, true), DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, false), DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b131fa8c8e..2b87966373 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -446,6 +446,7 @@ struct RISCVCPUConfig { bool ext_svnapot; bool ext_svpbmt; bool ext_zdinx; + bool ext_zawrs; bool ext_zfh; bool ext_zfhmin; bool ext_zfinx; diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index d0253b8104..b7e7613ea2 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -718,6 +718,10 @@ vsetvli 0 ........... ..... 111 ..... 1010111 = @r2_zimm11 vsetivli 11 .......... ..... 111 ..... 1010111 @r2_zimm10 vsetvl 1000000 ..... ..... 111 ..... 1010111 @r =20 +# *** Zawrs Standard Extension *** +wrs_nto 000000001101 00000 000 00000 1110011 +wrs_sto 000000011101 00000 000 00000 1110011 + # *** RV32 Zba Standard Extension *** sh1add 0010000 .......... 010 ..... 0110011 @r sh2add 0010000 .......... 100 ..... 0110011 @r diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/ins= n_trans/trans_rvzawrs.c.inc new file mode 100644 index 0000000000..f0da2fe50a --- /dev/null +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc @@ -0,0 +1,51 @@ +/* + * RISC-V translation routines for the RISC-V Zawrs Extension. + * + * Copyright (c) 2022 Christoph Muellner, christoph.muellner@vrull.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +static bool trans_wrs(DisasContext *ctx) +{ + if (!ctx->cfg_ptr->ext_zawrs) { + return false; + } + + /* + * The specification says: + * While stalled, an implementation is permitted to occasionally + * terminate the stall and complete execution for any reason. + * + * So let's just exit TB and return to the main loop. + */ + + /* Clear the load reservation (if any). */ + tcg_gen_movi_tl(load_res, -1); + + gen_set_pc_imm(ctx, ctx->pc_succ_insn); + tcg_gen_exit_tb(NULL, 0); + ctx->base.is_jmp =3D DISAS_NORETURN; + + return true; +} + +#define GEN_TRANS_WRS(insn) \ +static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ +{ \ + (void)a; \ + return trans_wrs(ctx); \ +} + +GEN_TRANS_WRS(wrs_nto) +GEN_TRANS_WRS(wrs_sto) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index db123da5ec..e22de88e97 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1029,6 +1029,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) #include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_rvk.c.inc" #include "insn_trans/trans_privileged.c.inc" --=20 2.37.3