You copied the Doc URL to your clipboard.

Using the C and C++ libraries with an application in a semihosting environment

If you are developing an application to run in a semihosted environment for debugging, you must have an execution environment that supports A32 or T32 semihosting trap instructions for AArch32 state or A64 semihosting trap instruction for AArch64 state.

The execution environment can be provided by either:

  • Using the standard semihosting functionality that is present by default in, for example, the ARM DSTREAM debug and trace unit.
  • Implementing your own handler for the semihosting calls.

It is not necessary to write any new functions or include files if you are using the default semihosting functionality of the C and C++ libraries.

The ARM debug agents support semihosting, but the memory map assumed by the C library might require tailoring to match the hardware being debugged.

ARM® Compiler supports semihosting by generating trap instructions such as HLT, SVC, or BKPT depending on the architecture or profile. Debug agents can trap these instructions to perform semihosting operations on the host.

Table 1-2 Semihosting trap instructions

Architecture Instruction Set Trap Instruction
ARMv8-A and ARMv8-R A64 HLT 0xF000
ARMv8-A and ARMv8-R A32 HLT 0xF000
SVC 0x123456
ARMv8-A and ARMv8-R T32 HLT 0x3C
SVC 0xAB
ARMv7-A and ARMv7-R A32 HLT 0xF000
SVC 0x123456
ARMv7-A and ARMv7-R T32 HLT 0x3C
SVC 0xAB
Any architecture with M-profile T32 BKPT 0xAB

For AArch32 in architectures with A-profile or R-profile, ARM Compiler supports two different semihosting implementations:

  • Semihosting using the SVC instruction. This is the default and legacy implementation.
  • Semihosting using the HLT instruction. This implementation is required for semihosting in hardware debug environments with mixed AArch32 and AArch64 states.

There are separate libraries for SVC-based and HLT-based semihosting. ARM Compiler uses the HLT-based semihosting library if your code references the symbol __use_hlt_semihosting. To do this, either:

  • IMPORT __use_hlt_semihosting from assembly language.
  • __asm(".global __use_hlt_semihosting\n\t") from C.

If you do not use the symbol __use_hlt_semihosting, then by default, ARM Compiler emits SVC instructions for semihosting calls. This symbol does not have an effect on M-profile architectures, or in AArch64 state.

ARM strongly discourages mixing HLT and SVC semihosting mechanisms within the same executable. The library only uses either SVC or HLT instructions, rather than a mixture. However, you must ensure that you do not mix SVC and HLT instructions when using:

  • inline assembly.
  • <arm_compat.h> header file.
Was this page helpful? Yes No