Skip to content

Commit 13d7aa9

Browse files
ved-rivosSuHo-llrr
authored andcommitted
Add srmcfg CSR
1 parent 4d9c2ef commit 13d7aa9

File tree

7 files changed

+49
-3
lines changed

7 files changed

+49
-3
lines changed

disasm/isa_parser.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
300300
extension_table[EXT_ZCMOP] = true;
301301
} else if (ext_str == "zalasr") {
302302
extension_table[EXT_ZALASR] = true;
303+
} else if (ext_str == "ssqosid") {
304+
extension_table[EXT_SSQOSID] = true;
303305
} else if (ext_str[0] == 'x') {
304306
extension_table['X'] = true;
305307
if (ext_str.size() == 1) {

riscv/csrs.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,3 +1692,22 @@ bool smcntrpmf_csr_t::unlogged_write(const reg_t val) noexcept {
16921692
prev_val = read();
16931693
return masked_csr_t::unlogged_write(val);
16941694
}
1695+
1696+
srmcfg_csr_t::srmcfg_csr_t(processor_t* const proc, const reg_t addr, const reg_t mask, const reg_t init):
1697+
masked_csr_t(proc, addr, mask, init) {
1698+
}
1699+
1700+
void srmcfg_csr_t::verify_permissions(insn_t insn, bool write) const {
1701+
csr_t::verify_permissions(insn, write);
1702+
1703+
if (!proc->extension_enabled(EXT_SSQOSID))
1704+
throw trap_illegal_instruction(insn.bits());
1705+
1706+
if (proc->extension_enabled(EXT_SMSTATEEN)) {
1707+
if ((state->prv < PRV_M) && !(state->mstateen[0]->read() & MSTATEEN0_PRIV114))
1708+
throw trap_illegal_instruction(insn.bits());
1709+
}
1710+
1711+
if (state->v)
1712+
throw trap_virtual_instruction(insn.bits());
1713+
}

riscv/csrs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,11 @@ class smcntrpmf_csr_t : public masked_csr_t {
843843
private:
844844
std::optional<reg_t> prev_val;
845845
};
846+
847+
// srmcfg CSR provided by Ssqosid extension
848+
class srmcfg_csr_t: public masked_csr_t {
849+
public:
850+
srmcfg_csr_t(processor_t* const proc, const reg_t addr, const reg_t mask, const reg_t init);
851+
virtual void verify_permissions(insn_t insn, bool write) const override;
852+
};
846853
#endif

riscv/encoding.h

Lines changed: 11 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 (61d2ef4)
7+
* https://github.com/riscv/riscv-opcodes (a014979)
88
*/
99

1010
#ifndef RISCV_CSR_ENCODING_H
@@ -177,11 +177,14 @@
177177
#define MSTATEEN0_CS 0x00000001
178178
#define MSTATEEN0_FCSR 0x00000002
179179
#define MSTATEEN0_JVT 0x00000004
180+
#define MSTATEEN0_PRIV114 0x0080000000000000
181+
#define MSTATEEN0_HENVCFGH 0x0100000000000000
180182
#define MSTATEEN0_HCONTEXT 0x0200000000000000
181-
#define MSTATEEN0_CD 0x0100000000000000
182183
#define MSTATEEN0_HENVCFG 0x4000000000000000
183184
#define MSTATEEN_HSTATEEN 0x8000000000000000
184185

186+
#define MSTATEEN0H_PRIV114 0x00800000
187+
#define MSTATEEN0H_HENVCFGH 0x01000000
185188
#define MSTATEEN0H_HCONTEXT 0x02000000
186189
#define MSTATEEN0H_HENVCFG 0x40000000
187190
#define MSTATEENH_HSTATEEN 0x80000000
@@ -339,6 +342,10 @@
339342

340343
#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)
341344

345+
/* srmcfg CSR fields */
346+
#define SRMCFG_RCID 0x00000FFF
347+
#define SRMCFG_MCID 0x0FFF0000
348+
342349
#ifdef __riscv
343350

344351
#if __riscv_xlen == 64
@@ -3196,6 +3203,7 @@
31963203
#define CSR_SIREG6 0x157
31973204
#define CSR_STOPEI 0x15c
31983205
#define CSR_SATP 0x180
3206+
#define CSR_SRMCFG 0x181
31993207
#define CSR_SCONTEXT 0x5a8
32003208
#define CSR_VSSTATUS 0x200
32013209
#define CSR_VSIE 0x204
@@ -5144,6 +5152,7 @@ DECLARE_CSR(sireg5, CSR_SIREG5)
51445152
DECLARE_CSR(sireg6, CSR_SIREG6)
51455153
DECLARE_CSR(stopei, CSR_STOPEI)
51465154
DECLARE_CSR(satp, CSR_SATP)
5155+
DECLARE_CSR(srmcfg, CSR_SRMCFG)
51475156
DECLARE_CSR(scontext, CSR_SCONTEXT)
51485157
DECLARE_CSR(vsstatus, CSR_VSSTATUS)
51495158
DECLARE_CSR(vsie, CSR_VSIE)

riscv/isa_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef enum {
8484
EXT_ZIMOP,
8585
EXT_ZCMOP,
8686
EXT_ZALASR,
87+
EXT_SSQOSID,
8788
NUM_ISA_EXTENSIONS
8889
} isa_extension_t;
8990

riscv/processor.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
483483
(proc->extension_enabled(EXT_ZCMT) ? SSTATEEN0_JVT : 0) |
484484
SSTATEEN0_CS;
485485
const reg_t hstateen0_mask = sstateen0_mask | HSTATEEN0_SENVCFG | HSTATEEN_SSTATEEN;
486-
const reg_t mstateen0_mask = hstateen0_mask;
486+
const reg_t mstateen0_mask = hstateen0_mask | (proc->extension_enabled(EXT_SSQOSID) ? MSTATEEN0_PRIV114 : 0);
487487
for (int i = 0; i < 4; i++) {
488488
const reg_t mstateen_mask = i == 0 ? mstateen0_mask : MSTATEEN_HSTATEEN;
489489
mstateen[i] = std::make_shared<masked_csr_t>(proc, CSR_MSTATEEN0 + i, mstateen_mask, 0);
@@ -585,6 +585,12 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
585585
}
586586
}
587587

588+
if (proc->extension_enabled_const(EXT_SSQOSID)) {
589+
const reg_t srmcfg_mask = SRMCFG_MCID | SRMCFG_RCID;
590+
srmcfg = std::make_shared<srmcfg_csr_t>(proc, CSR_SRMCFG, srmcfg_mask, 0);
591+
csrmap[CSR_SRMCFG] = srmcfg;
592+
}
593+
588594
serialized = false;
589595

590596
log_reg_write.clear();

riscv/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ struct state_t
170170
csr_t_p stimecmp;
171171
csr_t_p vstimecmp;
172172

173+
csr_t_p srmcfg;
174+
173175
bool serialized; // whether timer CSRs are in a well-defined state
174176

175177
// When true, execute a single instruction and then enter debug mode. This

0 commit comments

Comments
 (0)