This intrinsic inserts an SVC or BKPT instruction into the instruction stream generated by the compiler. It enables you to make semihosting calls from C or C++ that are independent of the target architecture.
int __semihost(int val, const void *ptr)
Where:
valIs the request code for the semihosting request.
ptrIs a pointer to an argument/result block.
See Appendix A Semihosting in the Compiler User Guide for more information on the results of semihosting calls.
Use this intrinsic from C or C++ to generate the appropriate semihosting call for your target and instruction set:
SVC 0x123456In ARM state for all architectures.
SVC 0xABIn Thumb state, excluding ARMv7‑M. This behavior is not guaranteed on all debug targets from ARM or from third parties.
BKPT 0xABFor ARMv7‑M, Thumb‑2 only.
ARM processors prior to ARMv7 use SVC instructions to make semihosting calls. However, if you are compiling for the Cortex‑M3 processor, semihosting is implemented using the BKPT instruction.
char buffer[100];
...
void foo(void)
{
__semihost(0x01, (const void *)buf); // equivalent in thumb state to
// int __svc(0xAB) my_svc(int, int *);
// result = my_svc(0x1, &buffer);
}
Compiling this code with the option --thumb generates:
||foo|| PROC
...
LDR r1,|L1.12|
MOVS r0,#1
SVC #0xab
...
|L1.12|
...
buffer
% 400