From a10dfd04e794a9d6e6910b1803277110624d2aef Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Sun, 1 Dec 2024 10:36:29 -0800 Subject: [PATCH] Add extension_t csrs in reset(), not register_extension() This addresses one issue raised in #1863. register_extension() is only called once, while reset() is called whenever the processor_t is reset. This ensures that extension_t state, including CSRs, is always reset with reset() --- riscv/processor.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/riscv/processor.cc b/riscv/processor.cc index ecdf392ea..2917153a3 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -197,8 +197,11 @@ void processor_t::reset() put_csr(CSR_PMPCFG0, PMP_R | PMP_W | PMP_X | PMP_NAPOT); } - for (auto e : custom_extensions) // reset any extensions + for (auto e : custom_extensions) { // reset any extensions + for (auto &csr: e.second->get_csrs(*this)) + state.add_csr(csr->address, csr); e.second->reset(); + } if (sim) sim->proc_reset(id); @@ -711,8 +714,6 @@ void processor_t::register_extension(extension_t *x) { fprintf(stderr, "extensions must have unique names (got two named \"%s\"!)\n", x->name()); abort(); } - for (auto &csr: x->get_csrs(*this)) - state.add_csr(csr->address, csr); x->set_processor(this); }