diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 9e8890054..654672e85 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);