diff options
author | YenHaoChen <howard25336284@gmail.com> | 2023-01-11 18:45:24 +0800 |
---|---|---|
committer | YenHaoChen <howard25336284@gmail.com> | 2023-01-30 21:16:42 +0800 |
commit | b59ff6fec2d390afdcadc82bf8d679e8385cd444 (patch) | |
tree | b3ce2772b077814be25e7557ba22debad3fd8d67 /riscv/triggers.cc | |
parent | 1230b321f9f547b6ab728cdb1ff1d82fb230df2a (diff) | |
download | riscv-isa-sim-b59ff6fec2d390afdcadc82bf8d679e8385cd444.zip riscv-isa-sim-b59ff6fec2d390afdcadc82bf8d679e8385cd444.tar.gz riscv-isa-sim-b59ff6fec2d390afdcadc82bf8d679e8385cd444.tar.bz2 |
triggers: add detect_icount_match()
Diffstat (limited to 'riscv/triggers.cc')
-rw-r--r-- | riscv/triggers.cc | 53 |
1 files changed, 49 insertions, 4 deletions
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(); |