From 7edcd83dac5c230533e8cfd752aa2ed6892becd8 Mon Sep 17 00:00:00 2001 From: zain2050 Date: Mon, 22 Sep 2025 14:09:37 +0000 Subject: [PATCH 1/3] Add IDL for Zawrs --- spec/std/isa/inst/Zawrs/wrs.nto.yaml | 11 +++++++++++ spec/std/isa/inst/Zawrs/wrs.sto.yaml | 1 + spec/std/isa/isa/builtin_functions.idl | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/spec/std/isa/inst/Zawrs/wrs.nto.yaml b/spec/std/isa/inst/Zawrs/wrs.nto.yaml index 835c008c27..fe29765219 100644 --- a/spec/std/isa/inst/Zawrs/wrs.nto.yaml +++ b/spec/std/isa/inst/Zawrs/wrs.nto.yaml @@ -51,3 +51,14 @@ access: vu: always data_independent_timing: false operation(): | + if ((CSR[mstatus].TW == 1'b1) && (mode() != PrivilegeMode::M)) { + raise (ExceptionCode::IllegalInstruction, mode(), $encoding); + } + if (CSR[misa].H == 1) { + if ((CSR[hstatus].VTW == 1'b1)) { + if ((mode() == PrivilegeMode::VS) || (mode() == PrivilegeMode::VU)) { + raise (ExceptionCode::VirtualInstruction, mode(), $encoding); + } + } + } + wait_on_reservation_set(); diff --git a/spec/std/isa/inst/Zawrs/wrs.sto.yaml b/spec/std/isa/inst/Zawrs/wrs.sto.yaml index 4d1c26f93d..735a22c9d2 100644 --- a/spec/std/isa/inst/Zawrs/wrs.sto.yaml +++ b/spec/std/isa/inst/Zawrs/wrs.sto.yaml @@ -47,3 +47,4 @@ access: vu: always data_independent_timing: false operation(): | + wait_on_reservation_set(); diff --git a/spec/std/isa/isa/builtin_functions.idl b/spec/std/isa/isa/builtin_functions.idl index 86a54d71c9..705d46d0e3 100644 --- a/spec/std/isa/isa/builtin_functions.idl +++ b/spec/std/isa/isa/builtin_functions.idl @@ -511,6 +511,21 @@ builtin function wfi { } } +builtin function wait_on_reservation_set { + description { + Wait-on-reservation-set: hint to temporarily + stall execution in a low-power state as long as: + + a. The reservation set is valid + b. If "wrs.sto" , a short duration since start of stall has not elapsed + c. No pending interrupt is observed + + A valid implementation is a no-op. + + The model will advance the PC; this function does not need to. + } +} + builtin function pma_applies? { returns Boolean arguments From 0bdc53d2cf8c06b3e2d2bcab9dba470432cb4108 Mon Sep 17 00:00:00 2001 From: zain2050 Date: Wed, 24 Sep 2025 13:21:29 +0000 Subject: [PATCH 2/3] Added config params for time limit --- spec/std/isa/ext/Zawrs.yaml | 12 +++++++++++ spec/std/isa/inst/Zawrs/wrs.nto.yaml | 14 ++++++++----- spec/std/isa/isa/builtin_functions.idl | 29 +++++++++++++++++++++----- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/spec/std/isa/ext/Zawrs.yaml b/spec/std/isa/ext/Zawrs.yaml index 4ce17136ce..fc32106d19 100644 --- a/spec/std/isa/ext/Zawrs.yaml +++ b/spec/std/isa/ext/Zawrs.yaml @@ -18,6 +18,18 @@ description: | * Code waiting on a flag to be set in memory indicative of an event occurring. For example, software on a RISC-V hart may wait on a "done" flag to be set in memory by an accelerator device indicating completion of a job previously submitted to the device. +params: + BOUNDED_TIME_LIMIT: + description: | + Defines the implementation-specific bounded time limit within which a wrs.nto instruction must complete. + schema: + type: integer + STO_DURATION: + description: | + Implementation-defined short timeout for wrs.sto instruction such that the stall is terminated on + the timeout if no other conditions have occurred to terminate the stall. + schema: + type: integer type: unprivileged versions: - version: "1.0.1" diff --git a/spec/std/isa/inst/Zawrs/wrs.nto.yaml b/spec/std/isa/inst/Zawrs/wrs.nto.yaml index fe29765219..f07ef55e91 100644 --- a/spec/std/isa/inst/Zawrs/wrs.nto.yaml +++ b/spec/std/isa/inst/Zawrs/wrs.nto.yaml @@ -52,13 +52,17 @@ access: data_independent_timing: false operation(): | if ((CSR[mstatus].TW == 1'b1) && (mode() != PrivilegeMode::M)) { - raise (ExceptionCode::IllegalInstruction, mode(), $encoding); + if (wait_on_reservation_set_bounded() == false) { + raise (ExceptionCode::IllegalInstruction, mode(), $encoding); + } } - if (CSR[misa].H == 1) { - if ((CSR[hstatus].VTW == 1'b1)) { - if ((mode() == PrivilegeMode::VS) || (mode() == PrivilegeMode::VU)) { + else if (CSR[misa].H == 1) { + if ((CSR[hstatus].VTW == 1'b1) && ((mode() == PrivilegeMode::VS) || (mode() == PrivilegeMode::VU))) { + if (wait_on_reservation_set_bounded() == false) { raise (ExceptionCode::VirtualInstruction, mode(), $encoding); } } } - wait_on_reservation_set(); + else { + wait_on_reservation_set($encoding); + } diff --git a/spec/std/isa/isa/builtin_functions.idl b/spec/std/isa/isa/builtin_functions.idl index 705d46d0e3..008835c130 100644 --- a/spec/std/isa/isa/builtin_functions.idl +++ b/spec/std/isa/isa/builtin_functions.idl @@ -512,17 +512,36 @@ builtin function wfi { } builtin function wait_on_reservation_set { + arguments Bits encoding description { - Wait-on-reservation-set: hint to temporarily - stall execution in a low-power state as long as: + Hint to temporarily stall execution + in a low-power state as long as: - a. The reservation set is valid - b. If "wrs.sto" , a short duration since start of stall has not elapsed - c. No pending interrupt is observed + * The reservation set is valid + * No pending interrupt is observed + * If "wrs.sto", STO_DURATION has not elapsed A valid implementation is a no-op. + The model will advance the PC; this function does not need to. + } +} +# A special form of "wait_on_reservation_set" when "wrs.nto" must +# complete within an implementation defined bounded time limit +builtin function wait_on_reservation_set_bounded { + returns Boolean + description { + Hint to temporarily stall execution + in a low-power state as long as: + + * The reservation set is valid + * No pending interrupt is observed + * BOUNDED_TIME_LIMIT has not elapsed + + A valid implementation is a no-op. The model will advance the PC; this function does not need to. + + Returns false if BOUNDED_TIME_LIMIT exceeded, else true } } From e95c4752f0996551ad38f651a101ce9b79831d24 Mon Sep 17 00:00:00 2001 From: zain2050 Date: Wed, 24 Sep 2025 13:29:30 +0000 Subject: [PATCH 3/3] make encoding an argument --- spec/std/isa/inst/Zawrs/wrs.sto.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/std/isa/inst/Zawrs/wrs.sto.yaml b/spec/std/isa/inst/Zawrs/wrs.sto.yaml index 735a22c9d2..e0bad8c090 100644 --- a/spec/std/isa/inst/Zawrs/wrs.sto.yaml +++ b/spec/std/isa/inst/Zawrs/wrs.sto.yaml @@ -47,4 +47,4 @@ access: vu: always data_independent_timing: false operation(): | - wait_on_reservation_set(); + wait_on_reservation_set($encoding);