Skip to content

Commit 608207c

Browse files
committed
Add Shlcofideleg support
Signed-off-by: demin.han <demin.han@starfivetech.com>
1 parent f0d4d42 commit 608207c

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

disasm/isa_parser.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
344344
extension_table[EXT_SMNPM] = true;
345345
} else if (ext_str == "ssnpm") {
346346
extension_table[EXT_SSNPM] = true;
347+
} else if (ext_str == "shlcofideleg") {
348+
extension_table[EXT_SHLCOFIDELEG] = true;
347349
} else if (ext_str.substr(0, 3) == "zvl") {
348350
reg_t new_vlen;
349351
try {

riscv/csr_init.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
109109

110110
auto vsip_vsie_accr = std::make_shared<generic_int_accessor_t>(
111111
this,
112-
MIP_VS_MASK, // read_mask
113-
MIP_VSSIP, // ip_write_mask
114-
MIP_VS_MASK, // ie_write_mask
112+
MIP_VS_MASK | MIP_LCOFIP, // read_mask
113+
MIP_VSSIP, // ip_write_mask
114+
MIP_VS_MASK | MIP_LCOFIP, // ie_write_mask
115115
generic_int_accessor_t::mask_mode_t::HIDELEG,
116-
1 // shiftamt
116+
1 // shiftamt
117117
);
118118

119119
auto nonvirtual_sip = std::make_shared<mip_proxy_csr_t>(proc, CSR_SIP, sip_sie_accr);

riscv/csrs.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,21 +834,23 @@ generic_int_accessor_t::generic_int_accessor_t(state_t* const state,
834834
}
835835

836836
reg_t generic_int_accessor_t::ip_read() const noexcept {
837-
return (state->mip->read() & deleg_mask() & read_mask) >> shiftamt;
837+
const reg_t val = state->mip->read() & deleg_mask() & read_mask;
838+
return ((val & 0xfff) >> shiftamt) | (val & ~0xfff);
838839
}
839840

840841
void generic_int_accessor_t::ip_write(const reg_t val) noexcept {
841842
const reg_t mask = deleg_mask() & ip_write_mask;
842-
state->mip->write_with_mask(mask, val << shiftamt);
843+
state->mip->write_with_mask(mask, ((val & 0xfff) << shiftamt) | (val & ~0xfff));
843844
}
844845

845846
reg_t generic_int_accessor_t::ie_read() const noexcept {
846-
return (state->mie->read() & deleg_mask() & read_mask) >> shiftamt;
847+
const reg_t val = state->mie->read() & deleg_mask() & read_mask;
848+
return ((val & 0xfff) >> shiftamt) | (val & ~0xfff);
847849
}
848850

849851
void generic_int_accessor_t::ie_write(const reg_t val) noexcept {
850852
const reg_t mask = deleg_mask() & ie_write_mask;
851-
state->mie->write_with_mask(mask, val << shiftamt);
853+
state->mie->write_with_mask(mask, ((val & 0xfff) << shiftamt) | (val & ~0xfff));
852854
}
853855

854856
reg_t generic_int_accessor_t::deleg_mask() const {
@@ -1223,7 +1225,8 @@ void hypervisor_csr_t::verify_permissions(insn_t insn, bool write) const {
12231225
}
12241226

12251227
hideleg_csr_t::hideleg_csr_t(processor_t* const proc, const reg_t addr, csr_t_p mideleg):
1226-
masked_csr_t(proc, addr, MIP_VS_MASK, 0),
1228+
masked_csr_t(proc, addr, MIP_VS_MASK |
1229+
(proc->extension_enabled(EXT_SHLCOFIDELEG) ? MIP_LCOFIP : 0), 0),
12271230
mideleg(mideleg) {
12281231
}
12291232

riscv/isa_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ typedef enum {
8686
EXT_SMMPM,
8787
EXT_SMNPM,
8888
EXT_SSNPM,
89+
EXT_SHLCOFIDELEG,
8990
NUM_ISA_EXTENSIONS
9091
} isa_extension_t;
9192

0 commit comments

Comments
 (0)