Skip to content

Commit bc7461b

Browse files
committed
Add const csr hedelegh and masks for stateen.priv113/stateen.context
1 parent ddb6e19 commit bc7461b

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

riscv/csr_init.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
179179
(1 << CAUSE_SOFTWARE_CHECK_FAULT) |
180180
(1 << CAUSE_HARDWARE_ERROR_FAULT);
181181
add_hypervisor_csr(CSR_HEDELEG, hedeleg = std::make_shared<masked_csr_t>(proc, CSR_HEDELEG, hedeleg_mask, 0));
182+
add_hypervisor_csr(CSR_HEDELEGH, std::make_shared<hedelegh_csr_t>(proc, CSR_HEDELEGH, 0));
182183
add_hypervisor_csr(CSR_HCOUNTEREN, hcounteren = std::make_shared<masked_csr_t>(proc, CSR_HCOUNTEREN, counteren_mask, 0));
183184
htimedelta = std::make_shared<basic_csr_t>(proc, CSR_HTIMEDELTA, 0);
184185
if (xlen == 32) {
@@ -285,8 +286,10 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
285286
(proc->extension_enabled(EXT_ZCMT) ? SSTATEEN0_JVT : 0) |
286287
SSTATEEN0_CS;
287288
const reg_t hstateen0_mask = sstateen0_mask | HSTATEEN0_SENVCFG | HSTATEEN_SSTATEEN |
288-
(proc->extension_enabled(EXT_SSCSRIND) ? HSTATEEN0_CSRIND : 0);
289-
const reg_t mstateen0_mask = hstateen0_mask | (proc->extension_enabled(EXT_SSQOSID) ? MSTATEEN0_PRIV114 : 0);
289+
(proc->extension_enabled(EXT_SSCSRIND) ? HSTATEEN0_CSRIND : 0) |
290+
(proc->get_cfg().trigger_count > 0 ? HSTATEEN0_SCONTEXT : 0);
291+
const reg_t mstateen0_mask = hstateen0_mask | MSTATEEN0_PRIV113 |
292+
(proc->extension_enabled(EXT_SSQOSID) ? MSTATEEN0_PRIV114 : 0);
290293
for (int i = 0; i < 4; i++) {
291294
const reg_t mstateen_mask = i == 0 ? mstateen0_mask : MSTATEEN_HSTATEEN;
292295
mstateen[i] = std::make_shared<masked_csr_t>(proc, CSR_MSTATEEN0 + i, mstateen_mask, 0);

riscv/csrs.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,3 +1978,18 @@ void hcontext_csr_t::verify_permissions(insn_t insn, bool write) const {
19781978
masked_csr_t::verify_permissions(insn, write);
19791979

19801980
}
1981+
1982+
hedelegh_csr_t::hedelegh_csr_t(processor_t* const proc, const reg_t addr, const reg_t init) :
1983+
const_csr_t(proc, addr, init){};
1984+
void hedelegh_csr_t::verify_permissions(insn_t insn, bool write) const {
1985+
if (proc->get_const_xlen() != 32)
1986+
throw trap_illegal_instruction(insn.bits());
1987+
if (proc->extension_enabled(EXT_SMSTATEEN)) {
1988+
if ((state->prv < PRV_M) &&
1989+
!(state->mstateen[0]->read() & MSTATEEN0_PRIV113))
1990+
throw trap_illegal_instruction(insn.bits());
1991+
1992+
}
1993+
const_csr_t::verify_permissions(insn, write);
1994+
1995+
}

riscv/csrs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,4 +924,10 @@ class hcontext_csr_t: public masked_csr_t {
924924
hcontext_csr_t(processor_t* const proc, const reg_t addr, const reg_t mask, const reg_t init);
925925
virtual void verify_permissions(insn_t insn, bool write) const override;
926926
};
927+
928+
class hedelegh_csr_t: public const_csr_t {
929+
public:
930+
hedelegh_csr_t(processor_t* const proc, const reg_t addr, const reg_t init);
931+
virtual void verify_permissions(insn_t insn, bool write) const override;
932+
};
927933
#endif

riscv/encoding.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* This file is auto-generated by running 'make' in
7-
* https://github.com/riscv/riscv-opcodes (47862ce)
7+
* https://github.com/riscv/riscv-opcodes (9f70bcd)
88
*/
99

1010
#ifndef RISCV_CSR_ENCODING_H
@@ -81,8 +81,9 @@
8181
#define USTATUS_UPIE 0x00000010
8282

8383
#define MNSTATUS_NMIE 0x00000008
84-
#define MNSTATUS_MNPP 0x00001800
8584
#define MNSTATUS_MNPV 0x00000080
85+
#define MNSTATUS_MNPELP 0x00000200
86+
#define MNSTATUS_MNPP 0x00001800
8687

8788
#define DCSR_XDEBUGVER (15U<<28)
8889
#define DCSR_EXTCAUSE (7<<24)
@@ -194,6 +195,7 @@
194195
#define MSTATEEN0_FCSR 0x00000002
195196
#define MSTATEEN0_JVT 0x00000004
196197
#define MSTATEEN0_CTR 0x0040000000000000
198+
#define MSTATEEN0_PRIV113 0x0100000000000000
197199
#define MSTATEEN0_PRIV114 0x0080000000000000
198200
#define MSTATEEN0_HCONTEXT 0x0200000000000000
199201
#define MSTATEEN0_AIA 0x0800000000000000
@@ -202,6 +204,7 @@
202204
#define MSTATEEN_HSTATEEN 0x8000000000000000
203205

204206
#define MSTATEEN0H_CTR 0x00400000
207+
#define MSTATEEN0H_PRIV113 0x01000000
205208
#define MSTATEEN0H_PRIV114 0x00800000
206209
#define MSTATEEN0H_HCONTEXT 0x02000000
207210
#define MSTATEEN0H_AIA 0x08000000
@@ -2768,6 +2771,7 @@
27682771
#define CSR_VSIEH 0x214
27692772
#define CSR_VSIPH 0x254
27702773
#define CSR_VSTIMECMPH 0x25d
2774+
#define CSR_HEDELEGH 0x612
27712775
#define CSR_HTIMEDELTAH 0x615
27722776
#define CSR_HIDELEGH 0x613
27732777
#define CSR_HVIENH 0x618
@@ -4313,6 +4317,7 @@ DECLARE_CSR(stimecmph, CSR_STIMECMPH)
43134317
DECLARE_CSR(vsieh, CSR_VSIEH)
43144318
DECLARE_CSR(vsiph, CSR_VSIPH)
43154319
DECLARE_CSR(vstimecmph, CSR_VSTIMECMPH)
4320+
DECLARE_CSR(hedelegh, CSR_HEDELEGH)
43164321
DECLARE_CSR(htimedeltah, CSR_HTIMEDELTAH)
43174322
DECLARE_CSR(hidelegh, CSR_HIDELEGH)
43184323
DECLARE_CSR(hvienh, CSR_HVIENH)

0 commit comments

Comments
 (0)