diff options
author | Scott Johnson <scott.johnson@arilinc.com> | 2021-02-23 16:28:49 -0800 |
---|---|---|
committer | Andrew Waterman <aswaterman@gmail.com> | 2021-09-08 07:59:02 -0700 |
commit | 6eedad425a0d08cabad4deaee52f90bf0f54bf65 (patch) | |
tree | 4bf9568c295a4daa528b43c8b36ee8e3144b4986 | |
parent | 44b0de2c5aded05ee790f80ce6f1aff5902c5989 (diff) | |
download | spike-6eedad425a0d08cabad4deaee52f90bf0f54bf65.zip spike-6eedad425a0d08cabad4deaee52f90bf0f54bf65.tar.gz spike-6eedad425a0d08cabad4deaee52f90bf0f54bf65.tar.bz2 |
Add tor_paddr() method to simplify callers
-rw-r--r-- | riscv/csrs.cc | 5 | ||||
-rw-r--r-- | riscv/csrs.h | 6 | ||||
-rw-r--r-- | riscv/mmu.cc | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/riscv/csrs.cc b/riscv/csrs.cc index 92ecca0..570ca6c 100644 --- a/riscv/csrs.cc +++ b/riscv/csrs.cc @@ -129,6 +129,11 @@ bool pmpaddr_csr_t::next_locked_and_tor() const noexcept { } +reg_t pmpaddr_csr_t::tor_paddr() const noexcept { + return (val & proc->pmp_tor_mask()) << PMP_SHIFT; +} + + // 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 4fe73d0..97d05ac 100644 --- a/riscv/csrs.h +++ b/riscv/csrs.h @@ -70,6 +70,12 @@ class pmpaddr_csr_t: public logged_csr_t { virtual void verify_permissions(insn_t insn, bool write) const override; virtual reg_t read() const noexcept override; reg_t raw_value() const noexcept; + + // Assuming this is configured as TOR, return address for top of + // range. Also forms bottom-of-range for next-highest pmpaddr + // register if that one is TOR. + reg_t tor_paddr() 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 2fd5a43..7afccae 100644 --- a/riscv/mmu.cc +++ b/riscv/mmu.cc @@ -222,7 +222,7 @@ reg_t mmu_t::pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode) reg_t base = 0; for (size_t i = 0; i < proc->n_pmp; i++) { - reg_t tor = (proc->state.pmpaddr[i]->raw_value() & proc->pmp_tor_mask()) << PMP_SHIFT; + reg_t tor = proc->state.pmpaddr[i]->tor_paddr(); uint8_t cfg = proc->state.pmpcfg[i]; if (cfg & PMP_A) { @@ -273,7 +273,7 @@ reg_t mmu_t::pmp_homogeneous(reg_t addr, reg_t len) reg_t base = 0; for (size_t i = 0; i < proc->n_pmp; i++) { - reg_t tor = (proc->state.pmpaddr[i]->raw_value() & proc->pmp_tor_mask()) << PMP_SHIFT; + reg_t tor = proc->state.pmpaddr[i]->tor_paddr(); uint8_t cfg = proc->state.pmpcfg[i]; if (cfg & PMP_A) { |