Do not decrement instruction-count triggers while the hart is already in Debug Mode, and store the decremented count before testing whether it reached zero.
This matches the architectural rule that triggers do not fire in Debug Mode and avoids losing a count update when the trigger transitions to its firing state. Signed-off-by: Chao Liu <[email protected]> --- target/riscv/debug.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 4dbcf289f2..ae9b1cd42a 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -837,6 +837,11 @@ bool riscv_itrigger_enabled(CPURISCVState *env) void helper_itrigger_match(CPURISCVState *env) { int count; + + if (env->debug_mode) { + return; + } + for (int i = 0; i < RV_MAX_TRIGGERS; i++) { if (get_trigger_type(env, i) != TRIGGER_TYPE_INST_CNT) { continue; @@ -848,7 +853,9 @@ void helper_itrigger_match(CPURISCVState *env) if (!count) { continue; } - itrigger_set_count(env, i, count--); + + count--; + itrigger_set_count(env, i, count); if (!count) { env->itrigger_enabled = riscv_itrigger_enabled(env); do_trigger_action(env, i); -- 2.53.0
