Keil™, An ARM® Company

RealView Compiler Reference Guide

Technical Support

On-Line Manuals

RealView Compiler Reference Guide

Preface
Introduction
Compiler Command-line Options
Language Extensions
Compiler-specific Features
Keywords and operators
__align
__alignof__
__ALIGNOF__
__asm
__forceinline
__global_reg
__inline
__int64
__INTADDR__
__irq
__packed
__pure
__smc
__softfp
__svc
__svc_indirect
__svc_indirect_r7
__value_in_regs
__weak
__writeonly
__declspec attributes
__declspec(dllexport)
__declspec(dllimport)
__declspec(noinline)
__declspec(noreturn)
__declspec(nothrow)
__declspec(notshared)
__declspec(thread)
Function attributes
__attribute__((alias))
__attribute__((always_inline))
__attribute__((const))
__attribute__((deprecated))
__attribute__((malloc))
__attribute__((noinline))
__attribute__((noreturn))
__attribute__((pure))
__attribute__((section))
__attribute__((unused))
__attribute__((used))
__attribute__((weak))
Type attributes
__attribute__((aligned))
__attribute((packed))
__attribute__((transparent_union))
Variable attributes
__attribute__((alias))
__attribute__((at(address)))
__attribute__((aligned))
__attribute__((deprecated))
__attribute__((packed))
__attribute__((section))
__attribute__((transparent_union))
__attribute__((unused))
__attribute__((used))
__attribute__((weak))
__attribute__((zero_init))
Pragmas
#pragma [no_]anon_unions
#pragma arm
#pragma arm section [section_sort_list]
#pragma diag_default tag[,tag,...]
#pragma diag_error tag[,tag,...]
#pragma diag_remark tag[,tag,...]
#pragma diag_suppress tag[,tag,...]
#pragma diag_warning tag[, tag, ...]
#pragma [no_]exceptions_unwind
#pragma hdrstop
#pragma import symbol_name
#pragma [no_]inline
#pragma no_pch
#pragma Onum
#pragma once
#pragma Ospace
#pragma Otime
#pragma pop
#pragma push
#pragma [no_]softfp_linkage
#pragma unroll [(n)]
#pragma unroll_completely
#pragma thumb
Instruction intrinsics
__breakpoint
__builtin_clz
__builtin_constant_p
__builtin_expect
__builtin_frame_address
__builtin_return_address
__builtin_popcount
__cdp
__clrex
__clz
__current_pc
__current_sp
__disable_fiq
__disable_irq
__enable_fiq
__enable_irq
__fabs
__fabsf
__force_stores
__ldrex
__ldrt
__memory_changed
__nop
__pld
__pli
__qadd
__qdbl
__qsub
__rbit
__rev
__return_address
__ror
__schedule_barrier
__semihost
__sev
__sqrt
__sqrtf
__ssat
__strex
__strt
__swp
__usat
__wfe
__wfi
__yield
ARMv6 SIMD intrinsics
ETSI basic operations
C55x intrinsics
Named register variables
Compiler predefines
Predefined macros
Function names
C and C++ Implementation Details
Via File Syntax
Standard C Implementation Definition
Standard C++ Implementation Definition
C and C++ Compiler Implementation Limits

__semihost

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.

ptr

Is a pointer to an argument/result block.

Return value

See Appendix A Semihosting in the Compiler User 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 ARM Limited. All rights reserved.ARM DUI 0376A