Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for mcountinhibit CSR #1796

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion riscv/csr_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
add_csr(which_mevent, mevent[i]);
}
}
add_csr(CSR_MCOUNTINHIBIT, std::make_shared<const_csr_t>(proc, CSR_MCOUNTINHIBIT, 0));
add_const_ext_csr(EXT_SSCOFPMF, CSR_SCOUNTOVF, std::make_shared<scountovf_csr_t>(proc, CSR_SCOUNTOVF));
add_csr(CSR_MIE, mie = std::make_shared<mie_csr_t>(proc, CSR_MIE));
add_csr(CSR_MIP, mip = std::make_shared<mip_csr_t>(proc, CSR_MIP));
Expand Down Expand Up @@ -134,6 +133,7 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
add_supervisor_csr(CSR_MIDELEG, mideleg = std::make_shared<mideleg_csr_t>(proc, CSR_MIDELEG));
const reg_t counteren_mask = (proc->extension_enabled_const(EXT_ZICNTR) ? 0x7UL : 0x0) | (proc->extension_enabled_const(EXT_ZIHPM) ? 0xfffffff8ULL : 0x0);
add_user_csr(CSR_MCOUNTEREN, mcounteren = std::make_shared<masked_csr_t>(proc, CSR_MCOUNTEREN, counteren_mask, 0));
add_csr(CSR_MCOUNTINHIBIT, mcountinhibit = std::make_shared<masked_csr_t>(proc, CSR_MCOUNTINHIBIT, counteren_mask & (~MCOUNTEREN_TIME), 0));
add_supervisor_csr(CSR_SCOUNTEREN, scounteren = std::make_shared<masked_csr_t>(proc, CSR_SCOUNTEREN, counteren_mask, 0));
nonvirtual_sepc = std::make_shared<epc_csr_t>(proc, CSR_SEPC);
add_hypervisor_csr(CSR_VSEPC, vsepc = std::make_shared<epc_csr_t>(proc, CSR_VSEPC));
Expand Down
14 changes: 13 additions & 1 deletion riscv/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
* This file is auto-generated by running 'make' in
* https://github.com/riscv/riscv-opcodes (048218e)
* https://github.com/riscv/riscv-opcodes (6a1be96)
*/

#ifndef RISCV_CSR_ENCODING_H
Expand Down Expand Up @@ -223,6 +223,17 @@
#define MHPMEVENTH_MINH 0x40000000
#define MHPMEVENTH_OF 0x80000000

#define MCOUNTEREN_CY_SHIFT 0
#define MCOUNTEREN_TIME_SHIFT 1
#define MCOUNTEREN_IR_SHIFT 2

#define MCOUNTEREN_CY (1U << MCOUNTEREN_CY_SHIFT)
#define MCOUNTEREN_TIME (1U << MCOUNTEREN_TIME_SHIFT)
#define MCOUNTEREN_IR (1U << MCOUNTEREN_IR_SHIFT)

#define MCOUNTINHIBIT_CY MCOUNTEREN_CY
#define MCOUNTINHIBIT_IR MCOUNTEREN_IR

#define HENVCFG_FIOM 0x00000001
#define HENVCFG_LPE 0x00000004
#define HENVCFG_SSE 0x00000008
Expand Down Expand Up @@ -3008,6 +3019,7 @@
#define INSN_FIELD_MOP_RR_T_30 0x40000000
#define INSN_FIELD_MOP_RR_T_27_26 0xc000000
#define INSN_FIELD_C_MOP_T 0x700
#define INSN_FIELD_RS2=RS1 0x1f00000
#endif
#ifdef DECLARE_INSN
DECLARE_INSN(add, MATCH_ADD, MASK_ADD)
Expand Down
6 changes: 4 additions & 2 deletions riscv/execute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,12 @@ void processor_t::step(size_t n)
in_wfi = true;
}

state.minstret->bump(instret);
if (!(state.mcountinhibit->read() & MCOUNTINHIBIT_IR))
state.minstret->bump(instret);

// Model a hart whose CPI is 1.
state.mcycle->bump(instret);
if (!(state.mcountinhibit->read() & MCOUNTINHIBIT_CY))
state.mcycle->bump(instret);

n -= instret;
}
Expand Down
1 change: 1 addition & 0 deletions riscv/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct state_t
csr_t_p medeleg;
csr_t_p mideleg;
csr_t_p mcounteren;
csr_t_p mcountinhibit;
csr_t_p mevent[N_HPMCOUNTERS];
csr_t_p mnstatus;
csr_t_p mnepc;
Expand Down
Loading