Skip to content

Commit e84af93

Browse files
KevinRSXalistair23
authored andcommitted
target/riscv: Add counter delegation definitions
This adds definitions for counter delegation, including the new scountinhibit register and the mstateen.CD bit. Signed-off-by: Kaiwen Xue <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Signed-off-by: Atish Patra <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent f254888 commit e84af93

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

target/riscv/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ struct CPUArchState {
392392
uint32_t scounteren;
393393
uint32_t mcounteren;
394394

395+
uint32_t scountinhibit;
395396
uint32_t mcountinhibit;
396397

397398
/* PMU cycle & instret privilege mode filtering */

target/riscv/cpu_bits.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
#define CSR_SSTATEEN2 0x10E
211211
#define CSR_SSTATEEN3 0x10F
212212

213+
/* Supervisor Counter Delegation */
214+
#define CSR_SCOUNTINHIBIT 0x120
215+
213216
/* Supervisor Trap Handling */
214217
#define CSR_SSCRATCH 0x140
215218
#define CSR_SEPC 0x141
@@ -779,6 +782,7 @@ typedef enum RISCVException {
779782
#define MENVCFG_CBCFE BIT(6)
780783
#define MENVCFG_CBZE BIT(7)
781784
#define MENVCFG_PMM (3ULL << 32)
785+
#define MENVCFG_CDE (1ULL << 60)
782786
#define MENVCFG_ADUE (1ULL << 61)
783787
#define MENVCFG_PBMTE (1ULL << 62)
784788
#define MENVCFG_STCE (1ULL << 63)
@@ -826,7 +830,9 @@ typedef enum RISCVException {
826830
#define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63
827831
#define ISELECT_MASK_AIA 0x1ff
828832

829-
/* MISELECT, SISELECT, and VSISELECT bits (AIA) */
833+
/* [M|S|VS]SELCT value for Indirect CSR Access Extension */
834+
#define ISELECT_CD_FIRST 0x40
835+
#define ISELECT_CD_LAST 0x5f
830836
#define ISELECT_MASK_SXCSRIND 0xfff
831837

832838
/* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */

target/riscv/machine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ const VMStateDescription vmstate_riscv_cpu = {
423423
VMSTATE_UINTTL(env.siselect, RISCVCPU),
424424
VMSTATE_UINT32(env.scounteren, RISCVCPU),
425425
VMSTATE_UINT32(env.mcounteren, RISCVCPU),
426+
VMSTATE_UINT32(env.scountinhibit, RISCVCPU),
426427
VMSTATE_UINT32(env.mcountinhibit, RISCVCPU),
427428
VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, 0,
428429
vmstate_pmu_ctr_state, PMUCTRState),

0 commit comments

Comments
 (0)