Skip to content

Commit 0d0863c

Browse files
authored
Merge pull request #2121 from binno/svukte_ext
Add Svukte extension support
2 parents bf0372d + a2dc352 commit 0d0863c

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

disasm/isa_parser.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
267267
extension_table[EXT_SVPBMT] = true;
268268
} else if (ext_str == "svinval") {
269269
extension_table[EXT_SVINVAL] = true;
270+
} else if (ext_str == "svukte") {
271+
if (max_xlen != 64)
272+
bad_isa_string(str, "'svukte' requires RV64");
273+
extension_table[EXT_SVUKTE] = true;
270274
} else if (ext_str == "zfa") {
271275
extension_table[EXT_ZFA] = true;
272276
} else if (ext_str == "zicbom") {

riscv/csr_init.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa)
329329
}
330330
const reg_t senvcfg_mask = (proc->extension_enabled(EXT_ZICBOM) ? SENVCFG_CBCFE | SENVCFG_CBIE : 0) |
331331
(proc->extension_enabled(EXT_ZICBOZ) ? SENVCFG_CBZE : 0) |
332+
(proc->extension_enabled(EXT_SVUKTE) ? SENVCFG_UKTE : 0) |
332333
(proc->extension_enabled(EXT_SSNPM) ? SENVCFG_PMM : 0) |
333334
(proc->extension_enabled(EXT_ZICFILP) ? SENVCFG_LPE : 0) |
334335
(proc->extension_enabled(EXT_ZICFISS) ? SENVCFG_SSE : 0);

riscv/csrs.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,8 @@ hstatus_csr_t::hstatus_csr_t(processor_t* const proc, const reg_t addr):
20272027
}
20282028

20292029
bool hstatus_csr_t::unlogged_write(const reg_t val) noexcept {
2030-
const reg_t mask = HSTATUS_VTSR | HSTATUS_VTW
2030+
const reg_t mask = (proc->extension_enabled(EXT_SVUKTE) ? HSTATUS_HUKTE : 0)
2031+
| HSTATUS_VTSR | HSTATUS_VTW
20312032
| (proc->supports_impl(IMPL_MMU) ? HSTATUS_VTVM : 0)
20322033
| (proc->extension_enabled(EXT_SSNPM) ? HSTATUS_HUPMM : 0)
20332034
| HSTATUS_HU | HSTATUS_SPVP | HSTATUS_SPV | HSTATUS_GVA;

riscv/isa_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef enum {
4848
EXT_SVNAPOT,
4949
EXT_SVPBMT,
5050
EXT_SVINVAL,
51+
EXT_SVUKTE,
5152
EXT_ZDINX,
5253
EXT_ZFA,
5354
EXT_ZFBFMIN,

riscv/mmu.cc

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ void throw_access_exception(bool virt, reg_t addr, access_type type)
5353
}
5454
}
5555

56+
[[noreturn]] void throw_page_fault_exception(bool virt, reg_t addr, access_type type)
57+
{
58+
switch (type) {
59+
case FETCH: throw trap_instruction_page_fault(virt, addr, 0, 0);
60+
case LOAD: throw trap_load_page_fault(virt, addr, 0, 0);
61+
case STORE: throw trap_store_page_fault(virt, addr, 0, 0);
62+
default: abort();
63+
}
64+
}
65+
5666
reg_t mmu_t::translate(mem_access_info_t access_info, reg_t len)
5767
{
5868
reg_t addr = access_info.transformed_vaddr;
@@ -560,6 +570,28 @@ reg_t mmu_t::s2xlate(reg_t gva, reg_t gpa, access_type type, access_type trap_ty
560570
}
561571
}
562572

573+
bool mmu_t::check_svukte_qualified(reg_t addr, reg_t mode, bool forced_virt)
574+
{
575+
state_t* state = proc->get_state();
576+
577+
if (mode != PRV_U)
578+
return true;
579+
580+
if (proc->extension_enabled('S') && get_field(state->senvcfg->read(), SENVCFG_UKTE)) {
581+
if (forced_virt && state->prv == PRV_U) {
582+
bool hstatus_hukte = proc->extension_enabled('H') && (get_field(state->hstatus->read(), HSTATUS_HUKTE) == 1);
583+
return !hstatus_hukte;
584+
}
585+
586+
assert(proc->get_xlen() == 64);
587+
if ((addr >> 63) & 1) {
588+
return (state->v || forced_virt) && ((state->vsatp->read() & SATP64_MODE) == 0);
589+
}
590+
}
591+
592+
return true;
593+
}
594+
563595
reg_t mmu_t::walk(mem_access_info_t access_info)
564596
{
565597
access_type type = access_info.type;
@@ -582,6 +614,10 @@ reg_t mmu_t::walk(mem_access_info_t access_info)
582614
if (vm.levels == 0)
583615
return s2xlate(addr, addr & ((reg_t(2) << (proc->xlen-1))-1), type, type, virt, hlvx, false) & ~page_mask; // zero-extend from xlen
584616

617+
if (proc->extension_enabled(EXT_SVUKTE) && !check_svukte_qualified(addr, mode, access_info.flags.forced_virt)) {
618+
throw_page_fault_exception(virt, addr, type);
619+
}
620+
585621
bool s_mode = mode == PRV_S;
586622
bool sum = proc->state.sstatus->readvirt(virt) & MSTATUS_SUM;
587623
bool mxr = (proc->state.sstatus->readvirt(false) | proc->state.sstatus->readvirt(virt)) & MSTATUS_MXR;
@@ -672,12 +708,7 @@ reg_t mmu_t::walk(mem_access_info_t access_info)
672708
}
673709
}
674710

675-
switch (type) {
676-
case FETCH: throw trap_instruction_page_fault(virt, addr, 0, 0);
677-
case LOAD: throw trap_load_page_fault(virt, addr, 0, 0);
678-
case STORE: throw trap_store_page_fault(virt, addr, 0, 0);
679-
default: abort();
680-
}
711+
throw_page_fault_exception(virt, addr, type);
681712
}
682713

683714
void mmu_t::register_memtracer(memtracer_t* t)

riscv/mmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct mem_access_info_t {
7878
};
7979

8080
void throw_access_exception(bool virt, reg_t addr, access_type type);
81+
[[noreturn]] void throw_page_fault_exception(bool virt, reg_t addr, access_type type);
8182

8283
// this class implements a processor's port into the virtual memory system.
8384
// an MMU and instruction cache are maintained for simulator performance.
@@ -447,6 +448,7 @@ class mmu_t
447448
check_triggers(operation, address, virt, address, data);
448449
}
449450
void check_triggers(triggers::operation_t operation, reg_t address, bool virt, reg_t tval, std::optional<reg_t> data);
451+
bool check_svukte_qualified(reg_t addr, reg_t mode, bool forced_virt);
450452
reg_t translate(mem_access_info_t access_info, reg_t len);
451453

452454
reg_t pte_load(reg_t pte_paddr, reg_t addr, bool virt, access_type trap_type, size_t ptesize) {

0 commit comments

Comments
 (0)