Skip to content

Commit 83b9898

Browse files
committed
RISC-V Semihosting 3 of 3: Warn if encountered but disabled
If semihosting is disabled but there is a semihosting request encountered in the program, provide a clear hint to the user what happened and what can be done about it. Change-Id: I8fa7b821ca9a853cbc884f38d138fa5c8946c84c Signed-off-by: Jan Matyas <[email protected]>
1 parent 4af47de commit 83b9898

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/target/riscv/riscv_semihosting.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,37 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
105105
struct semihosting *semihosting = target->semihosting;
106106
assert(semihosting);
107107

108-
if (!semihosting->is_active) {
109-
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
110-
return SEMIHOSTING_NONE;
111-
}
112-
113108
riscv_reg_t pc;
114109
int result = riscv_reg_get(target, &pc, GDB_REGNO_PC);
115110
if (result != ERROR_OK)
116111
return SEMIHOSTING_ERROR;
117112

118-
bool sequence_found;
113+
bool sequence_found = false;
119114
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
120115
if (*retval != ERROR_OK)
121116
return SEMIHOSTING_ERROR;
122117

118+
if (!semihosting->is_active) {
119+
if (sequence_found) {
120+
// If semihositing is encountered but disabled, provide an additional hint to the user.
121+
LOG_TARGET_WARNING(target, "RISC-V semihosting call encountered in the program "
122+
"but semihosting is disabled!");
123+
LOG_TARGET_WARNING(target, "The target will remain halted (PC = 0x%" TARGET_PRIxADDR ").", pc);
124+
LOG_TARGET_WARNING(target, "Hint: Restart your debug session and enable semihosting "
125+
"by command 'arm semihosting enable'.");
126+
}
127+
128+
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
129+
return SEMIHOSTING_NONE;
130+
}
131+
123132
if (!sequence_found) {
124133
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (no magic sequence)");
125134
return SEMIHOSTING_NONE;
126135
}
127136

128137
/* Otherwise we have a semihosting call (and semihosting is enabled).
129-
* Proceed with the semihosting. */
138+
* Proceed with the handling of semihosting. */
130139

131140
/*
132141
* Perform semihosting call if we are not waiting on a fileio

0 commit comments

Comments
 (0)