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 835c008c27..f07ef55e91 100644 --- a/spec/std/isa/inst/Zawrs/wrs.nto.yaml +++ b/spec/std/isa/inst/Zawrs/wrs.nto.yaml @@ -51,3 +51,18 @@ access: vu: always data_independent_timing: false operation(): | + if ((CSR[mstatus].TW == 1'b1) && (mode() != PrivilegeMode::M)) { + if (wait_on_reservation_set_bounded() == false) { + raise (ExceptionCode::IllegalInstruction, mode(), $encoding); + } + } + 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); + } + } + } + else { + wait_on_reservation_set($encoding); + } diff --git a/spec/std/isa/inst/Zawrs/wrs.sto.yaml b/spec/std/isa/inst/Zawrs/wrs.sto.yaml index 4d1c26f93d..e0bad8c090 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($encoding); diff --git a/spec/std/isa/isa/builtin_functions.idl b/spec/std/isa/isa/builtin_functions.idl index 86a54d71c9..008835c130 100644 --- a/spec/std/isa/isa/builtin_functions.idl +++ b/spec/std/isa/isa/builtin_functions.idl @@ -511,6 +511,40 @@ builtin function wfi { } } +builtin function wait_on_reservation_set { + arguments Bits encoding + description { + Hint to temporarily stall execution + in a low-power state as long as: + + * 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 + } +} + builtin function pma_applies? { returns Boolean arguments