Skip to content

Commit

Permalink
Making halt_set_dcsr_ebreak more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsfv committed Mar 26, 2024
1 parent a4598e4 commit 6ff5d5d
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,35 +1840,23 @@ static int halt_set_dcsr_ebreak(struct target *target)
int halt_result = ERROR_OK;
int resume_result = ERROR_OK;

if (dm013_select_target(target) != ERROR_OK) {
LOG_TARGET_INFO(target, "dm013_select_target failed");
return ERROR_FAIL;
}
halt_result = riscv013_halt_go(target);
if (halt_result == ERROR_OK) {
if (dm013_select_target(target) != ERROR_OK) {
LOG_TARGET_INFO(target, "dm013_select_target failed");
return ERROR_FAIL;
}
if (set_dcsr_ebreak(target, false) == ERROR_OK) {
if (dm013_select_target(target) != ERROR_OK) {
LOG_TARGET_INFO(target, "dm013_select_target failed");
return ERROR_FAIL;
}
resume_result = riscv013_step_or_resume_current_hart(target, false);
if (riscv013_resume_prep(target) == ERROR_OK) {
resume_result = riscv013_resume_go(target);
if (resume_result == ERROR_OK) {
target->state = TARGET_RUNNING;
target->debug_reason = DBG_REASON_NOTHALTED;
info->dcsr_ebreak_is_set = true;
} else if (resume_result == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
LOG_TARGET_INFO(target, "riscv013_step_or_resume_current_hart aborted");
LOG_TARGET_INFO(target, "riscv013_resume_go aborted");
target->state = TARGET_UNAVAILABLE;
} else {
LOG_TARGET_INFO(target, "riscv013_step_or_resume_current_hart failed");
LOG_TARGET_INFO(target, "riscv013_resume_go failed");
result = ERROR_FAIL;
}
} else {
LOG_TARGET_INFO(target, "set_dcsr_ebreak failed");
LOG_TARGET_INFO(target, "resume_prep failed");
result = ERROR_FAIL;
}
} else if (halt_result == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
Expand Down Expand Up @@ -2729,7 +2717,7 @@ static int riscv013_get_hart_state(struct target *target, enum riscv_hart_state
return ERROR_FAIL;
if (get_field(dmstatus, DM_DMSTATUS_ANYHAVERESET)) {
// LOG_TARGET_INFO(target, "Hart unexpectedly reset!");
info->dcsr_ebreak_is_set = false;
// info->dcsr_ebreak_is_set = false;
/* TODO: Can we make this more obvious to eg. a gdb user? */
uint32_t dmcontrol = DM_DMCONTROL_DMACTIVE |
DM_DMCONTROL_ACKHAVERESET;
Expand Down Expand Up @@ -5275,6 +5263,9 @@ static int riscv013_step_or_resume_current_hart(struct target *target,
target->state = TARGET_UNAVAILABLE;
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
if (get_field(dmstatus, DM_DMSTATUS_ANYHAVERESET)) {
dmcontrol = dmcontrol | DM_DMCONTROL_ACKHAVERESET;
}
if (get_field(dmstatus, DM_DMSTATUS_ALLRESUMEACK) == 0)
continue;
if (step && get_field(dmstatus, DM_DMSTATUS_ALLHALTED) == 0)
Expand Down

0 comments on commit 6ff5d5d

Please sign in to comment.