Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #18 from sifive/halt_correctly
Browse files Browse the repository at this point in the history
riscv: Ensure that hart is halted before attempting to examine it.
  • Loading branch information
timsifive committed Feb 28, 2017
2 parents b4d38d0 + 7f13e90 commit 8785b25
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8785b25

Please sign in to comment.