arm: smh: Add option to detect semihosting

These functions are intended to support detecting semihosting and
falling back gracefully to alternative implementations. The test starts
by making semihosting call. SYS_ERRNO is chosen because it should not
mutate any state. If this semihosting call results in an exception
(rather than being caught by the debugger), then the exception handler
should call disable_semihosting() and resume execution after the call.

Ideally, this would just be part of semihosting by default, and not a
separate config. However, to reduce space ARM SPL doesn't include
exception vectors by default. This means we can't detect if a
semihosting call failed unless we enable them. To avoid forcing them to
be enabled, we use a separate config option. It might also be possible
to try and detect whether a debugger has enabled (by reading HDE from
DSCR), but I wasn't able to figure out a way to do this from all ELs.

This patch just introduces the generic code to handle detection. The
next patch will implement it for arm64 (but not arm32).

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
This commit is contained in:
Sean Anderson 2022-03-22 16:59:30 -04:00 committed by Tom Rini
parent 6d16157426
commit 385d69d76b
3 changed files with 72 additions and 0 deletions

View file

@ -6,6 +6,36 @@
#ifndef _SEMIHOSTING_H
#define _SEMIHOSTING_H
#if CONFIG_IS_ENABLED(SEMIHOSTING_FALLBACK)
/**
* semihosting_enabled() - Determine whether semihosting is supported
*
* Semihosting-based drivers should call this function before making other
* semihosting calls.
*
* Return: %true if a debugger is attached which supports semihosting, %false
* otherwise
*/
bool semihosting_enabled(void);
/**
* disable_semihosting() - Cause semihosting_enabled() to return false
*
* If U-Boot ever receives an unhandled exception caused by a semihosting trap,
* the trap handler should call this function.
*/
void disable_semihosting(void);
#else
static inline bool semihosting_enabled(void)
{
return CONFIG_IS_ENABLED(SEMIHOSTING);
}
static inline void disable_semihosting(void)
{
}
#endif
/**
* enum smh_open_mode - Numeric file modes for use with smh_open()
* MODE_READ: 'r'