target/riscv: Clean up halt_go for multiple harts.

Also add an early exit for if any harts are unavailable.

Change-Id: I0875d4d213c9faf87b219d8d57e440881366c8f8
Signed-off-by: Tim Newsome <tim@sifive.com>
This commit is contained in:
Tim Newsome 2022-10-06 10:45:05 -07:00
parent 51aa8053e2
commit 4270857a76
1 changed files with 11 additions and 6 deletions

View File

@ -4208,14 +4208,19 @@ static int riscv013_halt_go(struct target *target)
dmcontrol |= DM_DMCONTROL_HASEL;
dmcontrol = set_hartsel(dmcontrol, info->index);
dmi_write(target, DM_DMCONTROL, dmcontrol);
for (size_t i = 0; i < 256; ++i)
if (riscv_is_halted(target))
break;
if (!riscv_is_halted(target)) {
uint32_t dmstatus;
uint32_t dmstatus;
for (size_t i = 0; i < 256; ++i) {
if (dmstatus_read(target, &dmstatus, true) != ERROR_OK)
return ERROR_FAIL;
/* When no harts are running, there's no point in continuing this loop. */
if (!get_field(dmstatus, DM_DMSTATUS_ALLRUNNING))
break;
}
/* We declare success if no harts are running. One or more of them may be
* unavailable, though. */
if ((get_field(dmstatus, DM_DMSTATUS_ANYRUNNING))) {
if (dmi_read(target, &dmcontrol, DM_DMCONTROL) != ERROR_OK)
return ERROR_FAIL;