From e5591c258412d421d66b9efd285ff3c3c14dcac6 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Tue, 20 Mar 2018 12:34:17 -0700 Subject: [PATCH] Halt the target again if it was reset while halted Change-Id: I59707e7b2e1646c312d4eb8e96e9d7dfd1e128c2 --- src/target/riscv/riscv-013.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index aed485042..142b5f705 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2570,9 +2570,17 @@ static bool riscv013_is_halted(struct target *target) int hartid = riscv_current_hartid(target); LOG_INFO("Hart %d unexpectedly reset!", hartid); /* TODO: Can we make this more obvious to eg. a gdb user? */ - dmi_write(target, DMI_DMCONTROL, - set_field(DMI_DMCONTROL_DMACTIVE | DMI_DMCONTROL_ACKHAVERESET, - hartsel_mask(target), hartid)); + uint32_t dmcontrol = DMI_DMCONTROL_DMACTIVE | + DMI_DMCONTROL_ACKHAVERESET; + dmcontrol = set_field(dmcontrol, hartsel_mask(target), hartid); + /* If we had been halted when we reset, request another halt. If we + * ended up running out of reset, then the user will (hopefully) get a + * message that a reset happened, that the target is running, and then + * that it is halted again once the request goes through. + */ + if (target->state == TARGET_HALTED) + dmcontrol |= DMI_DMCONTROL_HALTREQ; + dmi_write(target, DMI_DMCONTROL, dmcontrol); } return get_field(dmstatus, DMI_DMSTATUS_ALLHALTED); }