Skip to content

Commit a9961a6

Browse files
committed
fix(data): fix and refactor check for Zcmt enabled
1 parent aa848c7 commit a9961a6

File tree

4 files changed

+46
-49
lines changed

4 files changed

+46
-49
lines changed

spec/std/isa/csr/jvt.yaml

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,19 @@ fields:
4646
}
4747
reset_value: UNDEFINED_LEGAL
4848
sw_write(csr_value): |
49-
if ((mode() != PrivilegeMode::M) && implemented?(ExtensionName::Smstateen)) {
50-
if (CSR[mstateen0].JVT == 1'b0) {
51-
unimplemented_csr($encoding);
52-
}
53-
}
54-
else if ((mode() == PrivilegeMode::U) && implemented?(ExtensionName::Ssstateen)) {
55-
if (CSR[sstateen0].JVT == 1'b0) {
56-
unimplemented_csr($encoding);
57-
}
58-
}
59-
else if ((mode() == PrivilegeMode::VS) && implemented?(ExtensionName::Ssstateen)) {
60-
if (CSR[hstateen0].JVT == 1'b0) {
61-
unimplemented_csr($encoding);
62-
}
63-
}
64-
else if ((mode() == PrivilegeMode::VU) && implemented?(ExtensionName::Ssstateen)) {
65-
if ((CSR[sstateen0].JVT == 1'b0) || (CSR[hstateen0].JVT == 1'b0)) {
66-
unimplemented_csr($encoding);
67-
}
49+
if (( mode() != PrivilegeMode::M && implemented?(ExtensionName::Smstateen)
50+
&& CSR[mstateen0].JVT == 1'b0 )
51+
||
52+
( mode() == PrivilegeMode::U && implemented?(ExtensionName::Ssstateen)
53+
&& CSR[sstateen0].JVT == 1'b0 )
54+
||
55+
( mode() == PrivilegeMode::VS && implemented?(ExtensionName::Ssstateen)
56+
&& CSR[hstateen0].JVT == 1'b0 )
57+
||
58+
( mode() == PrivilegeMode::VU && implemented?(ExtensionName::Ssstateen)
59+
&& (CSR[sstateen0].JVT == 1'b0 || CSR[hstateen0].JVT == 1'b0) )) {
60+
61+
unimplemented_csr($encoding);
6862
}
6963
else {
7064
if (JVT_BASE_TYPE == "custom") {
@@ -94,28 +88,4 @@ fields:
9488
}
9589
return 0;
9690
sw_read(): |
97-
# If the Smstateen extension is implemented, then bit 2 in `mstateen0`, `sstateen0`, and `hstateen0` is
98-
# implemented. If bit 2 of a controlling `stateen0` CSR is zero, then access to the `jvt` CSR and execution
99-
# of a `cm.jalt` or `cm.jt` instruction by a lower privilege level results in an illegal-instruction trap (or, if
100-
# appropriate, a virtual-instruction trap).
101-
102-
if ((mode() != PrivilegeMode::M) && implemented?(ExtensionName::Smstateen)) {
103-
if (CSR[mstateen0].JVT == 1'b0) {
104-
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
105-
}
106-
}
107-
else if ((mode() == PrivilegeMode::U) && implemented?(ExtensionName::Ssstateen)) {
108-
if (CSR[sstateen0].JVT == 1'b0) {
109-
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
110-
}
111-
}
112-
else if ((mode() == PrivilegeMode::VS) && implemented?(ExtensionName::Ssstateen)) {
113-
if (CSR[hstateen0].JVT == 1'b0) {
114-
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
115-
}
116-
}
117-
else if ((mode() == PrivilegeMode::VU) && implemented?(ExtensionName::Ssstateen)) {
118-
if ((CSR[sstateen0].JVT == 1'b0) || (CSR[hstateen0].JVT == 1'b0)) {
119-
raise(ExceptionCode::VirtualInstruction, mode(), $encoding);
120-
}
121-
}
91+
check_zcmt_enabled($encoding);

spec/std/isa/inst/Zcmt/cm.jalt.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ access:
2525
vu: always
2626
operation(): |
2727
# Ensure JVT readable
28-
Bits<12> csr_addr = $bits(CSR[jvt].address());
29-
Csr csr_handle = direct_csr_lookup(csr_addr);
30-
XReg jvt = csr_sw_read(csr_handle);
28+
check_zcmt_enabled($encoding);
3129
3230
if (CSR[jvt].MODE != 0) {
3331
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);

spec/std/isa/inst/Zcmt/cm.jt.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ access:
2323
vu: always
2424
operation(): |
2525
# Ensure JVT readable
26-
#Csr csr_handle = direct_csr_lookup(CSR[jvt].address());
27-
#XReg jvt = csr_sw_read(csr_handle);
26+
check_zcmt_enabled($encoding);
2827
2928
if (CSR[jvt].MODE != 0) {
3029
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);

spec/std/isa/isa/globals.isa

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,3 +3062,33 @@ function mstatus_sd_reset_value
30623062
return ((fs_value == 3) || (vs_value == 3)) ? 1 : 0;
30633063
}
30643064
}
3065+
3066+
function check_zcmt_enabled {
3067+
arguments
3068+
Bits<INSTR_ENC_SIZE> encoding
3069+
description {
3070+
If the Smstateen extension is implemented, then bit 2 in `mstateen0`, `sstateen0`, and `hstateen0` is
3071+
implemented. If bit 2 of a controlling `stateen0` CSR is zero, then access to the `jvt` CSR and execution
3072+
of a `cm.jalt` or `cm.jt` instruction by a lower privilege level results in an illegal-instruction trap (or, if
3073+
appropriate, a virtual-instruction trap).
3074+
}
3075+
body {
3076+
if (( mode() != PrivilegeMode::M && implemented?(ExtensionName::Smstateen)
3077+
&& CSR[mstateen0].JVT == 1'b0 )
3078+
||
3079+
( mode() == PrivilegeMode::U && implemented?(ExtensionName::Ssstateen)
3080+
&& CSR[sstateen0].JVT == 1'b0 )) {
3081+
3082+
raise(ExceptionCode::IllegalInstruction, mode(), encoding);
3083+
}
3084+
else
3085+
if (( mode() == PrivilegeMode::VS && implemented?(ExtensionName::Ssstateen)
3086+
&& CSR[hstateen0].JVT == 1'b0 )
3087+
||
3088+
( mode() == PrivilegeMode::VU && implemented?(ExtensionName::Ssstateen)
3089+
&& (CSR[sstateen0].JVT == 1'b0 || CSR[hstateen0].JVT == 1'b0) )) {
3090+
3091+
raise(ExceptionCode::VirtualInstruction, mode(), encoding);
3092+
}
3093+
}
3094+
}

0 commit comments

Comments
 (0)