From 7b3b2e94adefa63a31c73267af21819ad833aba0 Mon Sep 17 00:00:00 2001 From: YenHaoChen Date: Tue, 1 Aug 2023 14:44:07 +0800 Subject: triggers: refactor: icount: breakdown detect_icount_match() into detect_icount_fire() and detect_icount_decrement() --- riscv/triggers.cc | 18 +++++++++++++----- riscv/triggers.h | 6 ++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/riscv/triggers.cc b/riscv/triggers.cc index b2b815d..24a0f4e 100644 --- a/riscv/triggers.cc +++ b/riscv/triggers.cc @@ -305,7 +305,7 @@ void mcontrol6_t::tdata1_write(processor_t * const proc, const reg_t val, const load = get_field(val, CSR_MCONTROL6_LOAD); } -std::optional icount_t::detect_icount_match(processor_t * const proc) noexcept +std::optional icount_t::detect_icount_fire(processor_t * const proc) noexcept { if (!common_match(proc) || !allow_action(proc->get_state())) return std::nullopt; @@ -317,13 +317,19 @@ std::optional icount_t::detect_icount_match(processor_t * const ret = match_result_t(TIMING_BEFORE, action); } - if (count >= 1 && (ret == std::nullopt || action != MCONTROL_ACTION_DEBUG_MODE)) { + return ret; +} + +void icount_t::detect_icount_decrement(processor_t * const proc) noexcept +{ + if (!common_match(proc) || !allow_action(proc->get_state())) + return; + + if (count >= 1) { if (count == 1) pending = 1; count = count - 1; } - - return ret; } reg_t icount_t::tdata1_read(const processor_t * const proc) const noexcept @@ -588,7 +594,9 @@ std::optional module_t::detect_icount_match() noexcept std::optional ret = std::nullopt; for (auto trigger: triggers) { - auto result = trigger->detect_icount_match(proc); + auto result = trigger->detect_icount_fire(proc); + if (result == std::nullopt || result->action != MCONTROL_ACTION_DEBUG_MODE) + trigger->detect_icount_decrement(proc); if (result.has_value() && (!ret.has_value() || ret->action < result->action)) ret = result; } diff --git a/riscv/triggers.h b/riscv/triggers.h index 0bf6097..6f00122 100644 --- a/riscv/triggers.h +++ b/riscv/triggers.h @@ -85,7 +85,8 @@ public: virtual std::optional detect_memory_access_match(processor_t UNUSED * const proc, operation_t UNUSED operation, reg_t UNUSED address, std::optional UNUSED data) noexcept { return std::nullopt; } - virtual std::optional detect_icount_match(processor_t UNUSED * const proc) { return std::nullopt; } + virtual std::optional detect_icount_fire(processor_t UNUSED * const proc) { return std::nullopt; } + virtual void detect_icount_decrement(processor_t UNUSED * const proc) {} virtual std::optional detect_trap_match(processor_t UNUSED * const proc, const trap_t UNUSED & t) noexcept { return std::nullopt; } protected: @@ -248,7 +249,8 @@ public: virtual bool icount_check_needed() const override { return count > 0 || pending; } virtual void stash_read_values() override; - virtual std::optional detect_icount_match(processor_t * const proc) noexcept override; + virtual std::optional detect_icount_fire(processor_t * const proc) noexcept override; + virtual void detect_icount_decrement(processor_t * const proc) noexcept override; private: bool dmode = false; -- cgit v1.1