9.130 __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.
See Developing Software for ARM Processors for more information.
ptr
Is a pointer to an argument/result block.
See Developing Software for ARM Processors for more information.

Return value

See Developing Software for ARM Processors for more information on the results of semihosting calls.

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 prior to 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.

Examples

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 reference
11 What is Semihosting?
7.26 --cpu=list
7.149 --thumb
9.16 __svc
Related information
BKPT
SVC
Non-ConfidentialPDF file icon PDF versionARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.