summaryrefslogtreecommitdiff
path: root/arch/arm/lib
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2022-03-22 16:59:30 -0400
committerTom Rini <trini@konsulko.com>2022-04-01 16:56:53 -0400
commit385d69d76b4216c10083f908005983d0c62e159c (patch)
tree92bd8f763f5538def3726bacbf5b01fdd2158bcb /arch/arm/lib
parent6d16157426b63361d6390b3ab4b304bbe101c825 (diff)
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>
Diffstat (limited to 'arch/arm/lib')
-rw-r--r--arch/arm/lib/semihosting.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 7595dbc4a9..dbea2b06fb 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -20,6 +20,7 @@
#define SYSWRITE 0x05
#define SYSREAD 0x06
#define SYSREADC 0x07
+#define SYSISERROR 0x08
#define SYSSEEK 0x0A
#define SYSFLEN 0x0C
#define SYSERRNO 0x13
@@ -41,6 +42,26 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
return result;
}
+#if CONFIG_IS_ENABLED(SEMIHOSTING_FALLBACK)
+static bool _semihosting_enabled = true;
+static bool try_semihosting = true;
+
+bool semihosting_enabled(void)
+{
+ if (try_semihosting) {
+ smh_trap(SYSERRNO, NULL);
+ try_semihosting = false;
+ }
+
+ return _semihosting_enabled;
+}
+
+void disable_semihosting(void)
+{
+ _semihosting_enabled = false;
+}
+#endif
+
/**
* smh_errno() - Read the host's errno
*