9.131 __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.

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:
0x123456
In ARM state for all architectures.
0xAB
In Thumb state, excluding M-profile architectures. This behavior is not guaranteed on all debug targets from ARM or from third parties.
0xAB
For M-profile architectures (Thumb only).

Restrictions

ARM processors earlier than ARMv7 use SVC instructions to make semihosting calls. However, if you are compiling for a Cortex M-profile processor, semihosting is implemented using the BKPT instruction.

Example

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
Related concepts
11.2 The semihosting interface
Related reference
7.28 --cpu=list
7.160 --thumb
9.16 __svc
Related information
BKPT
SVC
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.