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 <[email protected]>
  • Loading branch information
JanMatCodasip committed Jan 7, 2025
1 parent c4ea6d1 commit 27cf384
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/target/riscv/riscv_semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,37 @@ 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, " -> NONE (!semihosting->is_active)");
return SEMIHOSTING_NONE;
}

riscv_reg_t pc;
int result = riscv_reg_get(target, &pc, GDB_REGNO_PC);
if (result != ERROR_OK)
return SEMIHOSTING_ERROR;

bool sequence_found;
bool sequence_found = false;
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
if (*retval != ERROR_OK)
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'.");
}

LOG_TARGET_DEBUG(target, " -> NONE (!semihosting->is_active)");
return SEMIHOSTING_NONE;
}

if (!sequence_found) {
LOG_TARGET_DEBUG(target, " -> NONE (no magic)");
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 27cf384

Please sign in to comment.