From 7652128eeda0b0308c3e0f37eccde04de41f710b Mon Sep 17 00:00:00 2001 From: liangzhen Date: Wed, 20 Nov 2024 19:59:55 +0800 Subject: [PATCH] target/riscv: Ensure to handle all triggered a halt events If all current halted states are due to a halt group, then a new "triggered a halt" event has occurred. --- src/target/riscv/riscv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 9e8890054..380dde013 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -3743,6 +3743,7 @@ int riscv_openocd_poll(struct target *target) unsigned int should_resume = 0; unsigned int halted = 0; unsigned int running = 0; + unsigned int cause_groups = 0; struct target_list *entry; foreach_smp_target(entry, targets) { struct target *t = entry->target; @@ -3790,6 +3791,22 @@ int riscv_openocd_poll(struct target *target) LOG_TARGET_DEBUG(target, "resume all"); riscv_resume(target, true, 0, 0, 0, false); } else if (halted && running) { + foreach_smp_target(entry, targets) + { + struct target *t = entry->target; + if (t->state == TARGET_HALTED) { + riscv_reg_t dcsr; + if (riscv_reg_get(t, &dcsr, GDB_REGNO_DCSR) != ERROR_OK) + return ERROR_FAIL; + if (get_field(dcsr, CSR_DCSR_CAUSE) == CSR_DCSR_CAUSE_GROUP) + cause_groups++; + else + break; + } + } + if (halted == cause_groups) + return ERROR_OK; + LOG_TARGET_DEBUG(target, "halt all; halted=%d", halted); riscv_halt(target);