Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hit multiple icount triggers with different actions #1458

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions riscv/triggers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<match_result_t> icount_t::detect_icount_match(processor_t * const proc) noexcept
std::optional<match_result_t> icount_t::detect_icount_fire(processor_t * const proc) noexcept
{
if (!common_match(proc) || !allow_action(proc->get_state()))
return std::nullopt;
Expand All @@ -317,13 +317,19 @@ std::optional<match_result_t> 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
Expand Down Expand Up @@ -588,10 +594,13 @@ std::optional<match_result_t> module_t::detect_icount_match() noexcept

std::optional<match_result_t> ret = std::nullopt;
for (auto trigger: triggers) {
auto result = trigger->detect_icount_match(proc);
auto result = trigger->detect_icount_fire(proc);
if (result.has_value() && (!ret.has_value() || ret->action < result->action))
ret = result;
}
if (ret == std::nullopt || ret->action != MCONTROL_ACTION_DEBUG_MODE)
for (auto trigger: triggers)
trigger->detect_icount_decrement(proc);
return ret;
}

Expand Down
6 changes: 4 additions & 2 deletions riscv/triggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class trigger_t {

virtual std::optional<match_result_t> detect_memory_access_match(processor_t UNUSED * const proc,
operation_t UNUSED operation, reg_t UNUSED address, std::optional<reg_t> UNUSED data) noexcept { return std::nullopt; }
virtual std::optional<match_result_t> detect_icount_match(processor_t UNUSED * const proc) { return std::nullopt; }
virtual std::optional<match_result_t> detect_icount_fire(processor_t UNUSED * const proc) { return std::nullopt; }
virtual void detect_icount_decrement(processor_t UNUSED * const proc) {}
virtual std::optional<match_result_t> detect_trap_match(processor_t UNUSED * const proc, const trap_t UNUSED & t) noexcept { return std::nullopt; }

protected:
Expand Down Expand Up @@ -248,7 +249,8 @@ class icount_t : public trigger_t {
virtual bool icount_check_needed() const override { return count > 0 || pending; }
virtual void stash_read_values() override;

virtual std::optional<match_result_t> detect_icount_match(processor_t * const proc) noexcept override;
virtual std::optional<match_result_t> detect_icount_fire(processor_t * const proc) noexcept override;
virtual void detect_icount_decrement(processor_t * const proc) noexcept override;

private:
bool dmode = false;
Expand Down
Loading