4.7.34.  __semihost

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 Appendix A Semihosting in the Developer Guide for more information.

ptr

Is a pointer to an argument/result block.

See Appendix A Semihosting in the Developer Guide for more information.

Return value

See Appendix A Semihosting in the Developer Guide 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:

SVC 0x123456

In ARM state for all architectures.

SVC 0xAB

In Thumb state, excluding ARMv7-M. This behavior is not guaranteed on all debug targets from ARM or from third parties.

BKPT 0xAB

For ARMv7-M, Thumb-2 only.

Restrictions

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.

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

See also

Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A
Non-Confidential