aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYenHaoChen <howard25336284@gmail.com>2023-01-04 09:41:00 +0800
committerYenHaoChen <howard25336284@gmail.com>2023-01-04 09:41:00 +0800
commit6fd0169b32a17cc5a962477fb044715929ae6bd1 (patch)
tree52e97909d0a5feae9f4bd7f8f104fa8e477c4986
parent4cf0ef9c4e71c815014f38fc2a2961c697efc741 (diff)
downloadspike-6fd0169b32a17cc5a962477fb044715929ae6bd1.zip
spike-6fd0169b32a17cc5a962477fb044715929ae6bd1.tar.gz
spike-6fd0169b32a17cc5a962477fb044715929ae6bd1.tar.bz2
triggers: refactor: move detect_trap_match() to trap_common_t from itrigger_t/etrigger_t
-rw-r--r--riscv/triggers.cc18
-rw-r--r--riscv/triggers.h6
2 files changed, 3 insertions, 21 deletions
diff --git a/riscv/triggers.cc b/riscv/triggers.cc
index 07d1484..3f32f18 100644
--- a/riscv/triggers.cc
+++ b/riscv/triggers.cc
@@ -310,7 +310,7 @@ void itrigger_t::tdata1_write(processor_t * const proc, const reg_t val, const b
action = legalize_action(get_field(val, CSR_ITRIGGER_ACTION));
}
-std::optional<match_result_t> itrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept
+std::optional<match_result_t> trap_common_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept
{
if (!mode_match(proc->get_state()))
return std::nullopt;
@@ -361,22 +361,6 @@ void etrigger_t::tdata1_write(processor_t * const proc, const reg_t val, const b
action = legalize_action(get_field(val, CSR_ETRIGGER_ACTION));
}
-std::optional<match_result_t> etrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept
-{
- if (!mode_match(proc->get_state()))
- return std::nullopt;
-
- auto xlen = proc->get_xlen();
- bool interrupt = (t.cause() & ((reg_t)1 << (xlen - 1))) != 0;
- reg_t bit = t.cause() & ~((reg_t)1 << (xlen - 1));
- assert(bit < xlen);
- if (simple_match(interrupt, bit)) {
- hit = true;
- return match_result_t(TIMING_AFTER, action);
- }
- return std::nullopt;
-}
-
bool etrigger_t::simple_match(bool interrupt, reg_t bit) const
{
return !interrupt && ((tdata2 >> bit) & 1);
diff --git a/riscv/triggers.h b/riscv/triggers.h
index 49538ab..16c4343 100644
--- a/riscv/triggers.h
+++ b/riscv/triggers.h
@@ -150,6 +150,8 @@ public:
bool get_dmode() const override { return dmode; }
virtual action_t get_action() const override { return action; }
+ virtual std::optional<match_result_t> detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override;
+
private:
virtual bool simple_match(bool interrupt, reg_t bit) const = 0;
@@ -164,8 +166,6 @@ public:
virtual reg_t tdata1_read(const processor_t * const proc) const noexcept override;
virtual void tdata1_write(processor_t * const proc, const reg_t val, const bool allow_chain) noexcept override;
- virtual std::optional<match_result_t> detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override;
-
private:
virtual bool simple_match(bool interrupt, reg_t bit) const override;
bool nmi;
@@ -176,8 +176,6 @@ public:
virtual reg_t tdata1_read(const processor_t * const proc) const noexcept override;
virtual void tdata1_write(processor_t * const proc, const reg_t val, const bool allow_chain) noexcept override;
- virtual std::optional<match_result_t> detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override;
-
private:
virtual bool simple_match(bool interrupt, reg_t bit) const override;
};