Skip to content

Commit c01427d

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. Hot-fix this by making shure that semihosting is not attempted before the target gets successfully examined. Change-Id: Iccfa0da35d47a430d8674131ebd2eb8e5e2922c0 Signed-off-by: Jan Matyas <[email protected]>
1 parent 41a2254 commit c01427d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/target/riscv/riscv-011.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,16 @@ static int handle_halt(struct target *target, bool announce)
18891889

18901890
if (target->debug_reason == DBG_REASON_BREAKPOINT) {
18911891
int retval;
1892-
if (riscv_semihosting(target, &retval) != 0)
1893-
return retval;
1892+
/* Hotfix: Don't try to handle semihosting before the target is marked as examined. */
1893+
/* TODO: The code should be rearranged so that:
1894+
* - Semihosting is not attempted before the target is examined.
1895+
* - When the target is already halted on a semihosting magic sequence
1896+
* at the time when OpenOCD connects to it, this semihosting attempt
1897+
* gets handled right after the examination.
1898+
*/
1899+
if (target_was_examined(target))
1900+
if (riscv_semihosting(target, &retval) != SEMIHOSTING_NONE)
1901+
return retval;
18941902
}
18951903

18961904
if (announce)

0 commit comments

Comments
 (0)