Skip to content

Commit 7a1bc94

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 eeedccd commit 7a1bc94

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,32 +105,41 @@ 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
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read PC)");
117112
return SEMIHOSTING_ERROR;
118113
}
119114

120-
bool sequence_found;
115+
bool sequence_found = false;
121116
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
122117
if (*retval != ERROR_OK) {
123118
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (during magic seq. detection)");
124119
return SEMIHOSTING_ERROR;
125120
}
126121

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

132141
/* Otherwise we have a semihosting call (and semihosting is enabled).
133-
* Proceed with the semihosting. */
142+
* Proceed with the handling of semihosting. */
134143

135144
/*
136145
* Perform semihosting call if we are not waiting on a fileio

0 commit comments

Comments
 (0)