@@ -286,7 +286,8 @@ mseccfg_csr_t::mseccfg_csr_t(processor_t* const proc, const reg_t addr):
286286void mseccfg_csr_t::verify_permissions (insn_t insn, bool write) const {
287287 basic_csr_t::verify_permissions (insn, write);
288288 if (!proc->extension_enabled (EXT_SMEPMP) &&
289- !proc->extension_enabled (EXT_ZICFILP))
289+ !proc->extension_enabled (EXT_ZICFILP) &&
290+ !proc->extension_enabled (EXT_ZKR))
290291 throw trap_illegal_instruction (insn.bits ());
291292}
292293
@@ -302,6 +303,14 @@ bool mseccfg_csr_t::get_rlb() const noexcept {
302303 return (read () & MSECCFG_RLB);
303304}
304305
306+ bool mseccfg_csr_t::get_useed () const noexcept {
307+ return (read () & MSECCFG_USEED);
308+ }
309+
310+ bool mseccfg_csr_t::get_sseed () const noexcept {
311+ return (read () & MSECCFG_SSEED);
312+ }
313+
305314bool mseccfg_csr_t::unlogged_write (const reg_t val) noexcept {
306315 if (proc->n_pmp == 0 )
307316 return false ;
@@ -321,6 +330,11 @@ bool mseccfg_csr_t::unlogged_write(const reg_t val) noexcept {
321330 new_val |= (val & MSECCFG_MMWP); // MMWP is sticky
322331 new_val |= (val & MSECCFG_MML); // MML is sticky
323332
333+ if (proc->extension_enabled (EXT_ZKR)) {
334+ uint64_t mask = MSECCFG_USEED | MSECCFG_SSEED;
335+ new_val = (new_val & ~mask) | (val & mask);
336+ }
337+
324338 proc->get_mmu ()->flush_tlb ();
325339
326340 if (proc->extension_enabled (EXT_ZICFILP)) {
@@ -1434,6 +1448,16 @@ void seed_csr_t::verify_permissions(insn_t insn, bool write) const {
14341448 if (!proc->extension_enabled (EXT_ZKR) || !write)
14351449 throw trap_illegal_instruction (insn.bits ());
14361450 csr_t::verify_permissions (insn, write);
1451+
1452+ if (state->v ) {
1453+ if (state->mseccfg ->get_sseed () && write)
1454+ throw trap_virtual_instruction (insn.bits ());
1455+ else
1456+ throw trap_illegal_instruction (insn.bits ());
1457+ } else if ((state->prv == PRV_U && !state->mseccfg ->get_useed ()) ||
1458+ (state->prv == PRV_S && !state->mseccfg ->get_sseed ())) {
1459+ throw trap_illegal_instruction (insn.bits ());
1460+ }
14371461}
14381462
14391463reg_t seed_csr_t::read () const noexcept {
0 commit comments