aboutsummaryrefslogtreecommitdiff
path: root/riscv/triggers.h
diff options
context:
space:
mode:
authorScott Johnson <scott.johnson@arilinc.com>2022-12-08 12:29:57 -0800
committerYenHaoChen <howard25336284@gmail.com>2022-12-10 19:44:14 +0800
commit88cfdf2972635e5b7cfd127fbd5b6ebf48cb1462 (patch)
tree1fe67baddc738d7212a68626e13dc43bf59a31f9 /riscv/triggers.h
parentf94ba5f4234b968c553db75b9dc9db4bb886266a (diff)
downloadriscv-isa-sim-88cfdf2972635e5b7cfd127fbd5b6ebf48cb1462.zip
riscv-isa-sim-88cfdf2972635e5b7cfd127fbd5b6ebf48cb1462.tar.gz
riscv-isa-sim-88cfdf2972635e5b7cfd127fbd5b6ebf48cb1462.tar.bz2
Interpret mhselect in centralized place
And use that for legalize_mhselect(). Not using the second and third fields yet.
Diffstat (limited to 'riscv/triggers.h')
-rw-r--r--riscv/triggers.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/riscv/triggers.h b/riscv/triggers.h
index 9ce465a..1bb1855 100644
--- a/riscv/triggers.h
+++ b/riscv/triggers.h
@@ -91,6 +91,32 @@ protected:
private:
unsigned legalize_mhselect(bool h_enabled) const noexcept;
+
+ struct mhselect_interpretation {
+ const unsigned mhselect;
+ const mhselect_mode_t mode;
+ const std::optional<bool> shift_mhvalue;
+ };
+
+ mhselect_interpretation interpret_mhselect(bool h_enabled) const noexcept {
+ static unsigned warlize_if_h[8] = { 0, 1, 2, 0, 4, 5, 6, 4 }; // 3,7 downgrade
+ static unsigned warlize_no_h[8] = { 0, 0, 0, 0, 4, 4, 4, 4 }; // only 0,4 legal
+ static std::optional<mhselect_interpretation> table[8] = {
+ mhselect_interpretation{ 0, MHSELECT_MODE_IGNORE, std::nullopt },
+ mhselect_interpretation{ 1, MHSELECT_MODE_MCONTEXT, true },
+ mhselect_interpretation{ 2, MHSELECT_MODE_VMID, true },
+ std::nullopt,
+ mhselect_interpretation{ 4, MHSELECT_MODE_MCONTEXT, false },
+ mhselect_interpretation{ 5, MHSELECT_MODE_MCONTEXT, true },
+ mhselect_interpretation{ 6, MHSELECT_MODE_VMID, true },
+ std::nullopt
+ };
+ assert(mhselect < 8);
+ unsigned legal = h_enabled ? warlize_if_h[mhselect] : warlize_no_h[mhselect];
+ assert(legal < 8);
+ return table[legal].value();
+ }
+
mhselect_mode_t mhselect_mode(bool h_enabled) const noexcept;
unsigned mhselect_compare(bool h_enabled) const noexcept {
return legalize_mhselect(h_enabled) == 4 ? mhvalue : (mhvalue << 1) + (mhselect >> 2); // mhvalue or {mhvalue, mhselect[2]}