aboutsummaryrefslogtreecommitdiff
path: root/model/riscv_insts_base.sail
diff options
context:
space:
mode:
authorTim Hutt <timothy.hutt@codasip.com>2023-09-23 19:57:38 +0100
committerBill McSpadden <bill@riscv.org>2023-10-11 20:50:13 -0500
commit51a6c967fb320c2d47a3630b1f392e54eb69c3d7 (patch)
treecd864017e11911f4e86c32e7a437993a9ce05a58 /model/riscv_insts_base.sail
parent532714a6c71b47a91176eb90fef3b3b049c52fce (diff)
downloadsail-riscv-51a6c967fb320c2d47a3630b1f392e54eb69c3d7.zip
sail-riscv-51a6c967fb320c2d47a3630b1f392e54eb69c3d7.tar.gz
sail-riscv-51a6c967fb320c2d47a3630b1f392e54eb69c3d7.tar.bz2
Implement menvcfg
This implements the m/senvcfg(h) CSRs. This CSR is used to enable/disable extensions and behaviours for lower privilege modes. Currently the only implemented bit is FIOM which affects how fences work. It also affects how atomic memory accesses work in non-cacheable regions, but the model does not currently support PMAs so that can't easily be implemented.
Diffstat (limited to 'model/riscv_insts_base.sail')
-rw-r--r--model/riscv_insts_base.sail17
1 files changed, 17 insertions, 0 deletions
diff --git a/model/riscv_insts_base.sail b/model/riscv_insts_base.sail
index b5e699e..f5ef8cd 100644
--- a/model/riscv_insts_base.sail
+++ b/model/riscv_insts_base.sail
@@ -637,10 +637,22 @@ union clause ast = FENCE : (bits(4), bits(4))
mapping clause encdec = FENCE(pred, succ)
<-> 0b0000 @ pred @ succ @ 0b00000 @ 0b000 @ 0b00000 @ 0b0001111
+function effective_fence_set(set : bits(4), fiom : bool) -> bits(4) = {
+ // The bits are IORW. If FIOM is set then I implies R and O implies W.
+ if fiom then {
+ set[3 .. 2] @ (set[1 .. 0] | set[3 .. 2])
+ } else set
+}
+
/* For future versions of Sail where barriers can be parameterised */
$ifdef FEATURE_UNION_BARRIER
function clause execute (FENCE(pred, succ)) = {
+ // If the FIOM bit in menvcfg/senvcfg is set then the I/O bits can imply R/W.
+ let fiom = is_fiom_active();
+ let pred = effective_fence_set(pred, fiom);
+ let succ = effective_fence_set(succ, fiom);
+
match (pred, succ) {
(_ : bits(2) @ 0b11, _ : bits(2) @ 0b11) => __barrier(Barrier_RISCV_rw_rw()),
(_ : bits(2) @ 0b10, _ : bits(2) @ 0b11) => __barrier(Barrier_RISCV_r_rw()),
@@ -664,6 +676,11 @@ function clause execute (FENCE(pred, succ)) = {
$else
function clause execute (FENCE(pred, succ)) = {
+ // If the FIOM bit in menvcfg/senvcfg is set then the I/O bits can imply R/W.
+ let fiom = is_fiom_active();
+ let pred = effective_fence_set(pred, fiom);
+ let succ = effective_fence_set(succ, fiom);
+
match (pred, succ) {
(_ : bits(2) @ 0b11, _ : bits(2) @ 0b11) => __barrier(Barrier_RISCV_rw_rw),
(_ : bits(2) @ 0b10, _ : bits(2) @ 0b11) => __barrier(Barrier_RISCV_r_rw),