Skip to content

Commit

Permalink
target/riscv: Ensure to handle all triggered a halt events
Browse files Browse the repository at this point in the history
If all current halted states are due to a halt group, then
a new "triggered a halt" event has occurred.
  • Loading branch information
lz-bro committed Nov 20, 2024
1 parent f51900b commit 7652128
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7652128

Please sign in to comment.