I've just taken a look at semihosting 3.0.
The spec includes a mechanism for reporting features. After opening the special filename ":semihosting-features" one can read a header and one byte. This one byte is a bitmask that indicates whether optional semihosting features have been implemented. Implementation of this special filename requires changes to SYS_OPEN, SYS_SEEK, SYS_READ, SYS_CLOSE, SYS_FLEN, and SYS_ISTTY. Modifying six system calls seems excessive, and a way to introduce bugs.
A suggestion for an alternative: a SYS_OPEN of the special filename ":semihosting-features" returns not a file descriptor, but a 32-bit word. This word is a bitmask; if a bit is set this indicates an optional semihosting extension has been implemented.
This would provide the same functionality, and can be implemented in one or two lines.
Could you give a link to that spec?
It's "Semihosting for AArch32 and AArch64 Release 2019Q4"; https://static.docs.arm.com/100863/0300/semihosting.pdf