diff options
author | Andrew Waterman <andrew@sifive.com> | 2020-05-09 23:58:09 -0700 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2020-05-19 19:57:02 -0700 |
commit | 1e0fab92b1d6f350fc1f4f0093f5976588bd3afa (patch) | |
tree | 0cf8e1ddd6cf73cb59cdc6b7200d36c6d075f6bf /riscv/processor.cc | |
parent | e98630e79af962bc203e85f4e446d5a328df12d5 (diff) | |
download | spike-1e0fab92b1d6f350fc1f4f0093f5976588bd3afa.zip spike-1e0fab92b1d6f350fc1f4f0093f5976588bd3afa.tar.gz spike-1e0fab92b1d6f350fc1f4f0093f5976588bd3afa.tar.bz2 |
Support consuming PMP number and granularity from DTB
The feature itself isn't implemented yet.
Diffstat (limited to 'riscv/processor.cc')
-rw-r--r-- | riscv/processor.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/riscv/processor.cc b/riscv/processor.cc index b3e668a..9caee5c 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -43,6 +43,8 @@ processor_t::processor_t(const char* isa, const char* priv, const char* varch, for (auto disasm_insn : ext->get_disasms()) disassembler->add_insn(disasm_insn); + set_pmp_granularity(1 << PMP_SHIFT); + set_pmp_num(state.max_pmp); reset(); } @@ -488,6 +490,26 @@ static int ctz(reg_t val) return res; } +void processor_t::set_pmp_num(reg_t n) +{ + // check the number of pmp is in a reasonable range + if (n > state.max_pmp) { + fprintf(stderr, "error: bad number of pmp regions: '%ld' from the dtb\n", (unsigned long)n); + abort(); + } + n_pmp = n; +} + +void processor_t::set_pmp_granularity(reg_t gran) { + // check the pmp granularity is set from dtb(!=0) and is power of 2 + if (gran < (1 << PMP_SHIFT) || (gran & (gran - 1)) != 0) { + fprintf(stderr, "error: bad pmp granularity '%ld' from the dtb\n", (unsigned long)gran); + abort(); + } + + lg_pmp_granularity = ctz(gran); +} + void processor_t::take_interrupt(reg_t pending_interrupts) { reg_t mie = get_field(state.mstatus, MSTATUS_MIE); |