Skip to content

Commit 3b9803b

Browse files
committed
Fix mret and mnret instructions to support correctly Smdbltrp (MDT bit) and MPRV bit
Before his fix IDL code reset mstatus.MPRV bit only in case if S mode is implemented for both mret and mnret. This seems wrong, since spec states that MPRV should be reset by both mret and mnret for case when mode processor is returning is different from Machine mode (2b'11). As well, Smdbltrp spec requires that such case (returning to non-machine mode), the mnret instruction should reset MDT bit. According to the spec mnret instruction should set mnstatus.NMIE=1. Also, mnret should use mnstatus.MNPP bit field for previous mode storage. Signed-off-by: Albert Yosher <[email protected]>
1 parent d51cb12 commit 3b9803b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

arch/inst/I/mret.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ access:
1414
encoding:
1515
match: "00110000001000000000000001110011"
1616
operation(): |
17-
if (implemented?(ExtensionName::S) && CSR[mstatus].MPP != 2'b11) {
17+
if (CSR[mstatus].MPP != 2'b11) {
1818
CSR[mstatus].MPRV = 0;
1919
}
20+
if (implemented?(ExtensionName::Smdbltrp)) {
21+
if (xlen() == 64) {
22+
CSR[mstatus].MDT = 1'b0;
23+
} else {
24+
CSR[mstatush].MDT = 1'b0;
25+
}
26+
}
2027
CSR[mstatus].MIE = CSR[mstatus].MPIE;
2128
CSR[mstatus].MPIE = 1;
2229
if (CSR[mstatus].MPP == 2'b00) {

arch/inst/Smrnmi/mnret.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
$schema: inst_schema.json#
44
kind: instruction
55
name: mnret
6-
long_name: No synopsis available.
6+
long_name: Machine NMI Return
77
description: |
8-
No description available.
8+
Returns from an NMI in M-mode.
99
definedBy: Smrnmi
1010
assembly: mnret
1111
encoding:
@@ -18,9 +18,17 @@ access:
1818
vu: always
1919
data_independent_timing: false
2020
operation(): |
21-
if (implemented?(ExtensionName::S) && CSR[mstatus].MPP != 2'b11) {
21+
if (CSR[mnstatus].MNPP != 2'b11) {
2222
CSR[mstatus].MPRV = 0;
23+
if (implemented?(ExtensionName::Smdbltrp)) {
24+
if (xlen() == 64) {
25+
CSR[mstatus].MDT = 1'b0;
26+
} else {
27+
CSR[mstatush].MDT = 1'b0;
28+
}
29+
}
2330
}
31+
CSR[mnstatus].NMIE = 1'b1;
2432
if (CSR[mnstatus].MNPP == 2'b00) {
2533
set_mode(PrivilegeMode::U);
2634
} else if (CSR[mnstatus].MNPP == 2'b01) {

0 commit comments

Comments
 (0)