You copied the Doc URL to your clipboard.

ARM Compiler armclang Reference Guide : __semihost intrinsic

__semihost intrinsic

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.

To use this intrinsic, your source file must contain #include <arm_compat.h>. This is only available for AArch32.

Syntax

int __semihost(int val, const void *ptr)

Where:

val
Is the request code for the semihosting request.
ptr
Is a pointer to an argument/result block.

Return value

The results of semihosting calls are passed either as an explicit return value or as a pointer to a data block.

Usage

Use this intrinsic from C or C++ to generate the appropriate semihosting call for your target and instruction set:

SVC 0x123456
In ARM state for all architectures.
SVC 0xAB
In Thumb state, excluding M-profile architectures. This behavior is not guaranteed on all debug targets from ARM or from third parties.
BKPT 0xAB
For M-profile architectures (Thumb only).

Restrictions

For ARM processors that are not Cortex-M profile, semihosting is implemented using the SVC instruction. For Cortex M-profile processors, semihosting is implemented using the BKPT instruction.

Example

char buffer[100];
...
void foo(void)
{
    __semihost(0x01, (const void *)buffer);
}

Compiling this code with the option -mthumb shows the generated SVC instruction:

foo:
    ...
    MOVW     r0, :lower16:buffer
    MOVT     r0, :upper16:buffer
    ... 
    SVC      #0xab
    ...

buffer:
    .zero    100
    .size    buffer, 100