aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYenHaoChen <howard25336284@gmail.com>2023-01-11 18:45:24 +0800
committerYenHaoChen <howard25336284@gmail.com>2023-01-30 21:16:42 +0800
commitb59ff6fec2d390afdcadc82bf8d679e8385cd444 (patch)
treeb3ce2772b077814be25e7557ba22debad3fd8d67
parent1230b321f9f547b6ab728cdb1ff1d82fb230df2a (diff)
downloadspike-b59ff6fec2d390afdcadc82bf8d679e8385cd444.zip
spike-b59ff6fec2d390afdcadc82bf8d679e8385cd444.tar.gz
spike-b59ff6fec2d390afdcadc82bf8d679e8385cd444.tar.bz2
triggers: add detect_icount_match()
-rw-r--r--riscv/execute.cc8
-rw-r--r--riscv/triggers.cc53
-rw-r--r--riscv/triggers.h10
3 files changed, 65 insertions, 6 deletions
diff --git a/riscv/execute.cc b/riscv/execute.cc
index ea03922..d244419 100644
--- a/riscv/execute.cc
+++ b/riscv/execute.cc
@@ -262,6 +262,14 @@ void processor_t::step(size_t n)
state.single_step = state.STEP_STEPPED;
}
+ if (!state.serialized) {
+ auto match = TM.detect_icount_match();
+ if (match.has_value()) {
+ assert(match->timing == triggers::TIMING_BEFORE);
+ throw triggers::matched_t((triggers::operation_t)0, 0, match->action);
+ }
+ }
+
// debug mode wfis must nop
if (unlikely(in_wfi && !state.debug_mode)) {
throw wait_for_interrupt_t();
diff --git a/riscv/triggers.cc b/riscv/triggers.cc
index 39e59bc..1ba7a62 100644
--- a/riscv/triggers.cc
+++ b/riscv/triggers.cc
@@ -287,6 +287,27 @@ 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
+{
+ if (!common_match(proc))
+ return std::nullopt;
+
+ std::optional<match_result_t> ret = std::nullopt;
+ if (pending) {
+ pending = 0;
+ hit = true;
+ ret = match_result_t(TIMING_BEFORE, action);
+ }
+
+ 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
{
auto xlen = proc->get_xlen();
@@ -296,9 +317,9 @@ reg_t icount_t::tdata1_read(const processor_t * const proc) const noexcept
tdata1 = set_field(tdata1, CSR_ICOUNT_VS, proc->extension_enabled('H') ? vs : 0);
tdata1 = set_field(tdata1, CSR_ICOUNT_VU, proc->extension_enabled('H') ? vu : 0);
tdata1 = set_field(tdata1, CSR_ICOUNT_HIT, hit);
- tdata1 = set_field(tdata1, CSR_ICOUNT_COUNT, count);
+ tdata1 = set_field(tdata1, CSR_ICOUNT_COUNT, count_read_value);
tdata1 = set_field(tdata1, CSR_ICOUNT_M, m);
- tdata1 = set_field(tdata1, CSR_ICOUNT_PENDING, pending);
+ tdata1 = set_field(tdata1, CSR_ICOUNT_PENDING, pending_read_value);
tdata1 = set_field(tdata1, CSR_ICOUNT_S, s);
tdata1 = set_field(tdata1, CSR_ICOUNT_U, u);
tdata1 = set_field(tdata1, CSR_ICOUNT_ACTION, action);
@@ -313,14 +334,20 @@ void icount_t::tdata1_write(processor_t * const proc, const reg_t val, const boo
vs = get_field(val, CSR_ICOUNT_VS);
vu = get_field(val, CSR_ICOUNT_VU);
hit = get_field(val, CSR_ICOUNT_HIT);
- count = get_field(val, CSR_ICOUNT_COUNT);
+ count = count_read_value = get_field(val, CSR_ICOUNT_COUNT);
m = get_field(val, CSR_ICOUNT_M);
- pending = get_field(val, CSR_ICOUNT_PENDING);
+ pending = pending_read_value = get_field(val, CSR_ICOUNT_PENDING);
s = proc->extension_enabled_const('S') ? get_field(val, CSR_ICOUNT_S) : 0;
u = proc->extension_enabled_const('U') ? get_field(val, CSR_ICOUNT_U) : 0;
action = legalize_action(val, CSR_ICOUNT_ACTION, CSR_ICOUNT_DMODE(xlen));
}
+void icount_t::stash_read_values()
+{
+ count_read_value = count;
+ pending_read_value = pending;
+}
+
reg_t itrigger_t::tdata1_read(const processor_t * const proc) const noexcept
{
auto xlen = proc->get_xlen();
@@ -531,6 +558,24 @@ std::optional<match_result_t> module_t::detect_memory_access_match(operation_t o
return ret;
}
+std::optional<match_result_t> module_t::detect_icount_match() noexcept
+{
+ for (auto trigger: triggers)
+ trigger->stash_read_values();
+
+ state_t * const state = proc->get_state();
+ if (state->debug_mode)
+ return std::nullopt;
+
+ std::optional<match_result_t> ret = std::nullopt;
+ for (auto trigger: triggers) {
+ auto result = trigger->detect_icount_match(proc);
+ if (result.has_value() && (!ret.has_value() || ret->action < result->action))
+ ret = result;
+ }
+ return ret;
+}
+
std::optional<match_result_t> module_t::detect_trap_match(const trap_t& t) noexcept
{
state_t * const state = proc->get_state();
diff --git a/riscv/triggers.h b/riscv/triggers.h
index e1a0fd7..aa41a6a 100644
--- a/riscv/triggers.h
+++ b/riscv/triggers.h
@@ -80,9 +80,11 @@ public:
virtual bool get_load() const { return false; }
virtual action_t get_action() const { return ACTION_DEBUG_EXCEPTION; }
virtual bool icount_check_needed() const { return false; }
+ virtual void stash_read_values() {}
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_trap_match(processor_t UNUSED * const proc, const trap_t UNUSED & t) noexcept { return std::nullopt; }
protected:
@@ -242,12 +244,15 @@ public:
bool get_dmode() const override { return dmode; }
virtual action_t get_action() const override { return action; }
virtual bool icount_check_needed() const override { return true; }
+ virtual void stash_read_values() override;
+
+ virtual std::optional<match_result_t> detect_icount_match(processor_t * const proc) noexcept override;
private:
bool dmode;
bool hit;
- unsigned count;
- bool pending;
+ unsigned count, count_read_value;
+ bool pending, pending_read_value;
action_t action;
};
@@ -267,6 +272,7 @@ public:
unsigned count() const { return triggers.size(); }
std::optional<match_result_t> detect_memory_access_match(operation_t operation, reg_t address, std::optional<reg_t> data) noexcept;
+ std::optional<match_result_t> detect_icount_match() noexcept;
std::optional<match_result_t> detect_trap_match(const trap_t& t) noexcept;
processor_t *proc;