Skip to content

Commit a28e713

Browse files
committed
riscv-011: Don't trigger semihosting before the target is examined
In riscv-011 target, the handle_halt() function, and thus also riscv_semihosting(), can get called from within examine() before the examination is actually complete! The chain of the function calls is: - examine() -> riscv011_poll() -> poll_target() -> handle_halt() -> riscv_semihosting() If the target is already halted due to a breakpoint (dcsr.cause = SWBP) at the time OpenOCD connects to it, semihosting will be attempted before completing the examination, and the examination will fail. This issue was observed on HiFive1 Rev A01. The fix is to handle semihosting only after the target got successfully examined. Change-Id: Iccfa0da35d47a430d8674131ebd2eb8e5e2922c0 Signed-off-by: Jan Matyas <[email protected]>
1 parent 8f59570 commit a28e713

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/target/riscv/riscv-011.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,11 @@ static int handle_halt(struct target *target, bool announce)
18841884

18851885
if (target->debug_reason == DBG_REASON_BREAKPOINT) {
18861886
int retval;
1887-
if (riscv_semihosting(target, &retval) != 0)
1888-
return retval;
1887+
/* Don't try to handle semihosting before the target
1888+
* gets successfully examined. */
1889+
if (target_was_examined(target))
1890+
if (riscv_semihosting(target, &retval) != SEMIHOSTING_NONE)
1891+
return retval;
18891892
}
18901893

18911894
if (announce)

0 commit comments

Comments
 (0)