You copied the Doc URL to your clipboard.

__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 targets in AArch32 state.

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:

Note

The HLT instruction is architecturally UNDEFINED for Arm®v7‑A and Armv7‑R architectures, in both A32 and T32 state.
SVC 0x123456
In A32 state, excluding M-profile architectures.
SVC 0xAB
In T32 state, excluding M-profile architectures. This behavior is not guaranteed on all debug targets from Arm or from third parties.
HLT 0xF000
In A32 state, excluding M-profile architectures.
HLT 0x3C
In T32 state, excluding M-profile architectures.
BKPT 0xAB
For M-profile architectures (T32 only).

Implementation

For Arm processors that are not Cortex®‑M profile, semihosting is implemented using the SVC or HLT instruction. For Cortex‑M profile processors, semihosting is implemented using the BKPT instruction.

To use HLT-based semihosting, you must define the pre-processor macro __USE_HLT_SEMIHOSTING before #include <arm_compat.h>. By default, Arm Compiler emits SVC instructions rather than HLT instructions for semihosting calls. If you define this macro, __USE_HLT_SEMIHOSTING, then Arm Compiler emits HLT instructions rather than SVC instructions for semihosting calls.

The presence of this macro, __USE_HLT_SEMIHOSTING, does not affect the M-profile architectures that still use BKPT for semihosting.

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
Was this page helpful? Yes No