RISC-V: Add Zawrs ISA extension support
RFC PATCH v2 1/1 RISC-V: Add Zawrs ISA extension support
From: Christoph Muellner <[email protected]>
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 pretend that an interrupt occured, exit the execution loop and finally continue execution.
The specification can be found here:
https://github.com/riscv/riscv-zawrs/blob/main/zawrs.adoc
Note, that the Zawrs extension is not frozen or ratified yet. Therefore this patch is an RFC and not intended to get merged.
Changes since v1:
* Adding zawrs to the ISA string that is passed to the kernel
--- target/riscv/cpu.c | 2 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 3 ++ target/riscv/insn_trans/trans_rvzawrs.c.inc | 48 +++++++++++++++++++++ target/riscv/translate.c | 1 + 5 files changed, 55 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzawrs.c.inc
target/riscv/cpu.c +2 -0
@@ -877,6 +877,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false),DEFINE_PROP_BOOL ("svpbmt" ,RISCVCPU , cfg.ext_svpbmt, false), +DEFINE_PROP_BOOL ("zawrs" ,RISCVCPU , cfg.ext_zawrs, true),DEFINE_PROP_BOOL ("zba" ,RISCVCPU , cfg.ext_zba, true),DEFINE_PROP_BOOL ("zbb" ,RISCVCPU , cfg.ext_zbb, true), DEFINE_PROP_BOOL("zbc", RISCVCPU, cfg.ext_zbc, true),
@@ -1031,6 +1032,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)struct isa_ext_data isa_edata_arr[] = {ISA_EDATA_ENTRY (zicsr, ext_icsr),ISA_EDATA_ENTRY (zifencei, ext_ifencei), +ISA_EDATA_ENTRY (zawrs, ext_zawrs),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),
target/riscv/cpu.h +1 -0
@@ -380,6 +380,7 @@ struct RISCVCPUConfig {bool ext_h;bool ext_j;bool ext_v; +bool ext_zawrs;bool ext_zba;bool ext_zbb;bool ext_zbc;
target/riscv/insn32.decode +3 -0
@@ -111,6 +111,9 @@ wfi 0001000 00101 00000 000 00000 1110011 sfence_vma 0001001 ..... ..... 000 00000 1110011 @sfence_vma sfence_vm 0001000 00100 ..... 000 00000 1110011 @sfence_vm +# *** Zawrs Instruction Extension *** +wrs 000000010000 ..... 000 00000 1110011 @sfence_vm + # *** RV32I Base Instruction Set *** lui .................... ..... 0110111 @u auipc .................... ..... 0010111 @u
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +48 -0
48 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1005,6 +1005,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_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"
Signature · 1 line
2.35.3
Am Donnerstag, 2. Juni 2022, 15:40:17 CEST schrieb Christoph Muellner:
Quoted 12 lines
From: Christoph Muellner <[email protected]>
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 pretend that an interrupt occured, exit the execution loop and finally continue execution.
The specification can be found here:
https://github.com/riscv/riscv-zawrs/blob/main/zawrs.adoc
Quoted 7 lines
Note, that the Zawrs extension is not frozen or ratified yet. Therefore this patch is an RFC and not intended to get merged.
Changes since v1:
* Adding zawrs to the ISA string that is passed to the kernelSigned-off-by Christoph Muellner <[email protected]>
together with the Linux-kernel patch
Quoted 122 lines
--- target/riscv/cpu.c | 2 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 3 ++ target/riscv/insn_trans/trans_rvzawrs.c.inc | 48 +++++++++++++++++++++ target/riscv/translate.c | 1 + 5 files changed, 55 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzawrs.c.inctarget/riscv/cpu.c +2
-0@@ -877,6 +877,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false),DEFINE_PROP_BOOL ("svpbmt" ,RISCVCPU , cfg.ext_svpbmt, false), +DEFINE_PROP_BOOL ("zawrs" ,RISCVCPU , cfg.ext_zawrs, true),DEFINE_PROP_BOOL ("zba" ,RISCVCPU , cfg.ext_zba, true),DEFINE_PROP_BOOL ("zbb" ,RISCVCPU , cfg.ext_zbb, true), DEFINE_PROP_BOOL("zbc", RISCVCPU, cfg.ext_zbc, true),@@ -1031,6 +1032,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)struct isa_ext_data isa_edata_arr[] = {ISA_EDATA_ENTRY (zicsr, ext_icsr),ISA_EDATA_ENTRY (zifencei, ext_ifencei), +ISA_EDATA_ENTRY (zawrs, ext_zawrs),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),target/riscv/cpu.h +1
-0@@ -380,6 +380,7 @@ struct RISCVCPUConfig {bool ext_h;bool ext_j;bool ext_v; +bool ext_zawrs;bool ext_zba;bool ext_zbb;bool ext_zbc;target/riscv/insn32.decode +3
-0@@ -111,6 +111,9 @@ wfi 0001000 00101 00000 000 00000 1110011 sfence_vma 0001001 ..... ..... 000 00000 1110011 @sfence_vma sfence_vm 0001000 00100 ..... 000 00000 1110011 @sfence_vm +# *** Zawrs Instruction Extension *** +wrs 000000010000 ..... 000 00000 1110011 @sfence_vm + # *** RV32I Base Instruction Set *** lui .................... ..... 0110111 @u auipc .................... ..... 0010111 @utarget/riscv/insn_trans/trans_rvzawrs.c.inc new file +48
-0@@ -0,0 +1,48 @@ +/* + * RISC-V translation routines for the RISC-V Zawrs Extension. + * + * Copyright (c) 2022 Christoph Muellner, [email protected] + * + * 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 for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZAWRS(ctx) do { \ + if (!ctx->cfg_ptr->ext_zawrs) { \ + return false; \ + } \ +} while (0) + +static bool trans_wrs(DisasContext *ctx, arg_sfence_vm *a) +{ + REQUIRE_ZAWRS(ctx); + + /* + * We may continue if one or more of the following conditions are met: + * a) reservation set is invalid + * b) rs1 != 0 and X(rs1) < time CSR + * c) interrupt observed + * + * A reservation set can be invalidated by any store to a reserved + * memory location. However, that's currently not implemented in QEMU. + * So let's just exit the CPU loop and pretend that an interrupt occured. + */ + + /* 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 = DISAS_NORETURN; + + return true; +}target/riscv/translate.c +1
-0@@ -1005,6 +1005,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_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"
target/riscv/insn_trans/trans_rvzawrs.c.inc
Quoted 5 lines · Christoph Muellner
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +0
-0
Typo in the filename -- s/rvz/rz/.
target/riscv/insn_trans/trans_rvzawrs.c.inc line 27
Quoted 9 lines
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +9
-0+#define REQUIRE_ZAWRS(ctx) do { \ + if (!ctx->cfg_ptr->ext_zawrs) { \ + return false; \ + } \ +} while (0) + +static bool trans_wrs(DisasContext *ctx, arg_sfence_vm *a) +{ + REQUIRE_ZAWRS(ctx);
No point in the macro for what will only ever be a single user.
Otherwise, the implementation looks correct.
r~
Quoted 9 lines · Richard Henderson
target/riscv/insn_trans/trans_rvzawrs.c.inc
Quoted 5 lines · Christoph Muellner
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +0
-0Typo in the filename -- s/rvz/rz/.
This was actually intended as other files are named using the same pattern (ext={a,b,d,f,h,i,k,m,v,zfh} -> trans_rv${ext}.c.inc).
I had the impression that Zawrs would fit into the pattern as well. But if you prefer trans_rzawrs.c.inc I can change accordingly.
Quoted 12 lines
target/riscv/insn_trans/trans_rvzawrs.c.inc line 27
Quoted 10 lines
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +9
-0+#define REQUIRE_ZAWRS(ctx) do { \ + if (!ctx->cfg_ptr->ext_zawrs) { \ + return false; \ + } \ +} while (0) + +static bool trans_wrs(DisasContext *ctx, arg_sfence_vm *a) +{ + REQUIRE_ZAWRS(ctx);No point in the macro for what will only ever be a single user.
Ok, will change.
Thanks!
Quoted 6 lines
Otherwise, the implementation looks correct.
Reviewed-by Richard Henderson <[email protected]>r~
Quoted 9 lines · Richard Henderson
target/riscv/insn_trans/trans_rvzawrs.c.inc
Quoted 5 lines · Christoph Muellner
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +0
-0Typo in the filename -- s/rvz/rz/.
z = standard extension
a = atomics family
wrs = extension name
The full extension name indeed is Zawrs (see also
https://wiki.riscv.org/display/HOME/Specification+Status).
Quoted 17 lines
target/riscv/insn_trans/trans_rvzawrs.c.inc line 27
Quoted 9 lines
target/riscv/insn_trans/trans_rvzawrs.c.inc new file +9
-0+#define REQUIRE_ZAWRS(ctx) do { \ + if (!ctx->cfg_ptr->ext_zawrs) { \ + return false; \ + } \ +} while (0) + +static bool trans_wrs(DisasContext *ctx, arg_sfence_vm *a) +{ + REQUIRE_ZAWRS(ctx);No point in the macro for what will only ever be a single user.
Otherwise, the implementation looks correct.
Reviewed-by Richard Henderson <[email protected]>r~