From 7f13e905050ca6a164ac2a25f6686fed765def0d Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 27 Feb 2017 18:53:50 -0800 Subject: [PATCH] riscv: Ensure that hart is halted before attempting to examine it. --- src/target/riscv/riscv-013.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index cee486e8e..d61799286 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1539,7 +1539,7 @@ static int examine(struct target *target) LOG_DEBUG(" authbusy=%d", get_field(dmcontrol, DMI_DMCONTROL_AUTHBUSY)); LOG_DEBUG(" version=%d", get_field(dmcontrol, DMI_DMCONTROL_VERSION)); - unsigned hartstatus = DMI_DMCONTROL_HARTSTATUS; + unsigned hartstatus = get_field(dmcontrol, DMI_DMCONTROL_HARTSTATUS); if (!get_field(dmcontrol, DMI_DMCONTROL_DMACTIVE)) { LOG_ERROR("Debug Module did not become active. dmcontrol=0x%x", @@ -1570,7 +1570,7 @@ static int examine(struct target *target) LOG_DEBUG(" datacount=%d", info->datacount); uint32_t accesscs = dmi_read(target, DMI_PROGBUFCS); - info->progsize = get_field(abstractcs, DMI_PROGBUFCS_PROGSIZE); + info->progsize = get_field(accesscs, DMI_PROGBUFCS_PROGSIZE); LOG_DEBUG("accesscs=0x%x", accesscs); LOG_DEBUG(" progsize=%d", info->progsize); @@ -1606,6 +1606,7 @@ static int examine(struct target *target) } if (hartstatus == 1) { + LOG_DEBUG("Hart currently running. Requesting halt.\n"); dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_HALTREQ | DMI_DMCONTROL_DMACTIVE); for (unsigned i = 0; i < 256; i++) { @@ -1644,6 +1645,7 @@ static int examine(struct target *target) } if (hartstatus == 1) { + LOG_DEBUG("Resuming hart.\n"); // Resume if the hart had been running. dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_DMACTIVE | DMI_DMCONTROL_RESUMEREQ);