Skip to content

Commit

Permalink
RISC-V Semihosting 3 of 3: Warn if encountered but disabled
Browse files Browse the repository at this point in the history
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 <jan.matyas@codasip.com>
  • Loading branch information
JanMatCodasip committed Jan 20, 2025
1 parent 8c0a1cd commit 6ca507b
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/target/riscv/riscv_semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,44 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
struct semihosting *semihosting = target->semihosting;
assert(semihosting);

if (!semihosting->is_active) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
return SEMIHOSTING_NONE;
}

riscv_reg_t pc;
int result = riscv_reg_get(target, &pc, GDB_REGNO_PC);
if (result != ERROR_OK) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read PC)");
return SEMIHOSTING_ERROR;
}

bool sequence_found;
bool sequence_found = false;
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
if (*retval != ERROR_OK) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (during magic seq. detection)");
return SEMIHOSTING_ERROR;
}

if (!semihosting->is_active) {
if (sequence_found) {
// If semihositing is encountered but disabled, provide an additional hint to the user.
LOG_TARGET_WARNING(target, "RISC-V semihosting call encountered in the program "
"but semihosting is disabled!");
LOG_TARGET_WARNING(target, "The target will remain halted (PC = 0x%" TARGET_PRIxADDR ").", pc);
LOG_TARGET_WARNING(target, "Hint: Restart your debug session and enable semihosting "
"by command 'arm semihosting enable'.");
// TODO: This can be improved: If riscv_semihosting() is called also
// from "arm semihosting enable", the user will not be required to restart
// the debug session.
}

LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
return SEMIHOSTING_NONE;
}

if (!sequence_found) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (no magic sequence)");
return SEMIHOSTING_NONE;
}

/* Otherwise we have a semihosting call (and semihosting is enabled).
* Proceed with the semihosting. */
* Proceed with the handling of semihosting. */

/*
* Perform semihosting call if we are not waiting on a fileio
Expand Down

0 comments on commit 6ca507b

Please sign in to comment.