@@ -286,7 +286,8 @@ mseccfg_csr_t::mseccfg_csr_t(processor_t* const proc, const reg_t addr):
286
286
void mseccfg_csr_t::verify_permissions (insn_t insn, bool write) const {
287
287
basic_csr_t::verify_permissions (insn, write);
288
288
if (!proc->extension_enabled (EXT_SMEPMP) &&
289
- !proc->extension_enabled (EXT_ZICFILP))
289
+ !proc->extension_enabled (EXT_ZICFILP) &&
290
+ !proc->extension_enabled (EXT_ZKR))
290
291
throw trap_illegal_instruction (insn.bits ());
291
292
}
292
293
@@ -302,6 +303,14 @@ bool mseccfg_csr_t::get_rlb() const noexcept {
302
303
return (read () & MSECCFG_RLB);
303
304
}
304
305
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
+
305
314
bool mseccfg_csr_t::unlogged_write (const reg_t val) noexcept {
306
315
if (proc->n_pmp == 0 )
307
316
return false ;
@@ -321,6 +330,11 @@ bool mseccfg_csr_t::unlogged_write(const reg_t val) noexcept {
321
330
new_val |= (val & MSECCFG_MMWP); // MMWP is sticky
322
331
new_val |= (val & MSECCFG_MML); // MML is sticky
323
332
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
+
324
338
proc->get_mmu ()->flush_tlb ();
325
339
326
340
if (proc->extension_enabled (EXT_ZICFILP)) {
@@ -1434,6 +1448,16 @@ void seed_csr_t::verify_permissions(insn_t insn, bool write) const {
1434
1448
if (!proc->extension_enabled (EXT_ZKR) || !write)
1435
1449
throw trap_illegal_instruction (insn.bits ());
1436
1450
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
+ }
1437
1461
}
1438
1462
1439
1463
reg_t seed_csr_t::read () const noexcept {
0 commit comments