Skip to content

Commit e86b256

Browse files
committed
Add Shlcofideleg support
Signed-off-by: demin.han <[email protected]>
1 parent fd0a927 commit e86b256

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-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 & shiftamt_mask) >> shiftamt) | (val & ~shiftamt_mask);
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 & shiftamt_mask) << shiftamt) | (val & ~shiftamt_mask));
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 & shiftamt_mask) >> shiftamt) | (val & ~shiftamt_mask);
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 & shiftamt_mask) << shiftamt) | (val & ~shiftamt_mask));
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/csrs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class generic_int_accessor_t {
414414
const bool mask_mideleg;
415415
const bool mask_hideleg;
416416
const int shiftamt;
417+
static const reg_t shiftamt_mask = 0xfff;
417418
reg_t deleg_mask() const;
418419
};
419420

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)