diff options
author | Scott Johnson <scott.johnson@arilinc.com> | 2021-02-23 17:40:39 -0800 |
---|---|---|
committer | Andrew Waterman <aswaterman@gmail.com> | 2021-09-08 07:59:02 -0700 |
commit | d9bd31becc124d3334f6fb0908d09d2cd8b06dd1 (patch) | |
tree | b093c47a8dc4b2d886767e41a2ae5f64f706c145 /riscv | |
parent | 95824344eb56097e9bb45cab9d22ab370908c2ff (diff) | |
download | riscv-isa-sim-d9bd31becc124d3334f6fb0908d09d2cd8b06dd1.zip riscv-isa-sim-d9bd31becc124d3334f6fb0908d09d2cd8b06dd1.tar.gz riscv-isa-sim-d9bd31becc124d3334f6fb0908d09d2cd8b06dd1.tar.bz2 |
Add new method match4()
To simplify calling code.
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/csrs.cc | 13 | ||||
-rw-r--r-- | riscv/csrs.h | 3 | ||||
-rw-r--r-- | riscv/mmu.cc | 7 |
3 files changed, 17 insertions, 6 deletions
diff --git a/riscv/csrs.cc b/riscv/csrs.cc index 8c18fc2..dff846c 100644 --- a/riscv/csrs.cc +++ b/riscv/csrs.cc @@ -145,6 +145,19 @@ reg_t pmpaddr_csr_t::napot_mask() const noexcept { } +bool pmpaddr_csr_t::match4(reg_t cur_addr) const noexcept { + state_t* const state = proc->get_state(); + uint8_t cfg = state->pmpcfg[pmpidx]; + if ((cfg & PMP_A) == 0) return false; + reg_t base = tor_base_paddr(); + reg_t tor = tor_paddr(); + bool is_tor = (cfg & PMP_A) == PMP_TOR; + bool napot_match = ((cur_addr ^ tor) & napot_mask()) == 0; + bool tor_match = base <= cur_addr && cur_addr < tor; + return is_tor ? tor_match : napot_match; +} + + // implement class pmpcfg_csr_t pmpcfg_csr_t::pmpcfg_csr_t(processor_t* const proc, const reg_t addr): logged_csr_t(proc, addr) { diff --git a/riscv/csrs.h b/riscv/csrs.h index beabd52..ab1adf6 100644 --- a/riscv/csrs.h +++ b/riscv/csrs.h @@ -83,6 +83,9 @@ class pmpaddr_csr_t: public logged_csr_t { // E.g. for 4KiB region, returns 0xffffffff_fffff000. reg_t napot_mask() const noexcept; + // Does a 4-byte access at the specified address match this PMP entry? + bool match4(reg_t cur_addr) const noexcept; + protected: virtual bool unlogged_write(const reg_t val) noexcept override; private: diff --git a/riscv/mmu.cc b/riscv/mmu.cc index be3d3e0..c315a53 100644 --- a/riscv/mmu.cc +++ b/riscv/mmu.cc @@ -221,21 +221,16 @@ reg_t mmu_t::pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode) return true; for (size_t i = 0; i < proc->n_pmp; i++) { - reg_t base = proc->state.pmpaddr[i]->tor_base_paddr(); - reg_t tor = proc->state.pmpaddr[i]->tor_paddr(); uint8_t cfg = proc->state.pmpcfg[i]; if (cfg & PMP_A) { - bool is_tor = (cfg & PMP_A) == PMP_TOR; // Check each 4-byte sector of the access bool any_match = false; bool all_match = true; for (reg_t offset = 0; offset < len; offset += 1 << PMP_SHIFT) { reg_t cur_addr = addr + offset; - bool napot_match = ((cur_addr ^ tor) & proc->state.pmpaddr[i]->napot_mask()) == 0; - bool tor_match = base <= cur_addr && cur_addr < tor; - bool match = is_tor ? tor_match : napot_match; + bool match = proc->state.pmpaddr[i]->match4(cur_addr); any_match |= match; all_match &= match; } |