Skip to content

Commit b34b1ad

Browse files
committed
Xqci extension: fix qc.c.mnret and qc.c.mret instructions
Signed-off-by: Albert Yosher <[email protected]>
1 parent 32ec0a6 commit b34b1ad

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
$schema: csr_schema.json#
2+
kind: csr
3+
name: qc_mncause
4+
long_name: Machine NMI Cause
5+
address: 0x7c2
6+
base: 32
7+
priv_mode: M
8+
length: MXLEN
9+
description: |
10+
Reports the cause of the latest non-maskable interrupt.
11+
definedBy:
12+
anyOf:
13+
- Xqci
14+
- Xqciint
15+
fields:
16+
INT:
17+
type: RW-H
18+
reset_value: 0
19+
location: 31
20+
description: Interrupt bit copied from mcause.INT at the moment of NMI
21+
NMI:
22+
type: RW-H
23+
reset_value: 0
24+
location: 30
25+
description: If 1'b1, currently processing NMI.
26+
MPP:
27+
type: RW-H
28+
reset_value: 3
29+
location: 29-28
30+
description: M-mode Previous Privilege.
31+
MPIE:
32+
type: RW-H
33+
reset_value: 0
34+
location: 27
35+
description: M-mode Previous Interrupt Enable.
36+
MIE:
37+
type: RW-H
38+
reset_value: 0
39+
location: 26
40+
description: M-mode Interrupt Enable.
41+
EXCP:
42+
type: RW-H
43+
reset_value: 0
44+
location: 25
45+
description: Exception Pending Bit.
46+
RESP:
47+
type: RW-H
48+
reset_value: 0
49+
location: 24
50+
description: Resume Pending Bit.
51+
MPIL:
52+
type: RW-H
53+
reset_value: 0
54+
location: 19-16
55+
description: M-mode Previous Interrupt Level.
56+
MIL:
57+
type: RW-H
58+
reset_value: 15
59+
location: 15-12
60+
description: M-mode Interrupt Level.
61+
NMICODE:
62+
type: RW-H
63+
reset_value: 0
64+
location: 11-0
65+
description: NMI code ID.

cfgs/qc_iu/arch_overlay/inst/Xqci/qc.c.mnret.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ description: |
88
Returns from an NMI in M-mode.
99
Instruction encoded in CI instruction format.
1010
assembly: ""
11-
definedBy: Xqciint
11+
definedBy:
12+
anyOf:
13+
- Xqci
14+
- Xqciint
1215
access:
1316
s: never
1417
u: never
@@ -18,15 +21,18 @@ base: 32
1821
encoding:
1922
match: "0001100110010010"
2023
operation(): |
21-
CSR[mncause].MIE = CSR[mncause].MPIE;
22-
CSR[mncause].MPIE = 1;
23-
if (CSR[mncause].MPP == 2'b00) {
24+
if (implemented?(ExtensionName::S) && CSR[mstatus].MPP != 2'b11) {
25+
CSR[mstatus].MPRV = 0;
26+
}
27+
CSR[mstatus].MIE = CSR[mstatus].MPIE;
28+
CSR[mstatus].MPIE = 1;
29+
if (CSR[mstatus].MPP == 2'b00) {
2430
set_mode(PrivilegeMode::U);
25-
} else if (CSR[mncause].MPP == 2'b01) {
31+
} else if (CSR[mstatus].MPP == 2'b01) {
2632
set_mode(PrivilegeMode::S);
27-
} else if (CSR[mncause].MPP == 2'b11) {
33+
} else if (CSR[mstatus].MPP == 2'b11) {
2834
set_mode(PrivilegeMode::M);
2935
}
30-
CSR[mncause].MPP = implemented?(ExtensionName::U) ? 2'b00 : 2'b11;
36+
CSR[mstatus].MPP = implemented?(ExtensionName::U) ? 2'b00 : 2'b11;
3137
CSR[mcause].NMI = 0;
3238
$pc = CSR[qc_mnepc].sw_read();

cfgs/qc_iu/arch_overlay/inst/Xqci/qc.c.mret.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ description: |
88
Returns from an exception in M-mode.
99
Instruction encoded in CI instruction format.
1010
assembly: ""
11-
definedBy: Xqciint
11+
definedBy:
12+
anyOf:
13+
- Xqci
14+
- Xqciint
1215
access:
1316
s: never
1417
u: never

0 commit comments

Comments
 (0)