replaces virtual functions with memory pointers (kind of)
This commit is contained in:
@@ -348,6 +348,9 @@ template <typename BASE, typename LOGCAT = logging::disass> struct riscv_hart_co
|
||||
using reg_t = typename core::reg_t;
|
||||
using addr_t = typename core::addr_t;
|
||||
|
||||
using rd_csr_f = std::function<iss::status(unsigned addr, reg_t&)>;
|
||||
using wr_csr_f = std::function<iss::status(unsigned addr, reg_t)>;
|
||||
|
||||
#define MK_CSR_RD_CB(FCT) [this](unsigned a, reg_t& r) -> iss::status { return this->FCT(a, r); };
|
||||
#define MK_CSR_WR_CB(FCT) [this](unsigned a, reg_t r) -> iss::status { return this->FCT(a, r); };
|
||||
|
||||
@@ -530,8 +533,14 @@ template <typename BASE, typename LOGCAT = logging::disass> struct riscv_hart_co
|
||||
this->reg.cycle + cycle_offset);
|
||||
};
|
||||
|
||||
void register_custom_csr_rd(unsigned addr) { csr_rd_cb[addr] = &this_class::read_custom_csr; }
|
||||
void register_custom_csr_wr(unsigned addr) { csr_wr_cb[addr] = &this_class::write_custom_csr; }
|
||||
void register_csr(unsigned addr, rd_csr_f f) { csr_rd_cb[addr] = f; }
|
||||
void register_csr(unsigned addr, wr_csr_f f) { csr_wr_cb[addr] = f; }
|
||||
void register_csr(unsigned addr, rd_csr_f rdf, wr_csr_f wrf) {
|
||||
csr_rd_cb[addr] = rdf;
|
||||
csr_wr_cb[addr] = wrf;
|
||||
}
|
||||
void unregister_csr_rd(unsigned addr) { csr_rd_cb.erase(addr); }
|
||||
void unregister_csr_wr(unsigned addr) { csr_wr_cb.erase(addr); }
|
||||
|
||||
bool debug_mode_active() { return this->reg.PRIV & 0x4; }
|
||||
|
||||
@@ -777,8 +786,6 @@ protected:
|
||||
using csr_page_type = typename csr_type::page_type;
|
||||
csr_type csr;
|
||||
|
||||
using rd_csr_f = std::function<iss::status(unsigned addr, reg_t&)>;
|
||||
using wr_csr_f = std::function<iss::status(unsigned addr, reg_t)>;
|
||||
std::unordered_map<unsigned, rd_csr_f> csr_rd_cb;
|
||||
std::unordered_map<unsigned, wr_csr_f> csr_wr_cb;
|
||||
|
||||
|
Reference in New Issue
Block a user