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
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||
|Armv8‑A and Armv8‑R||A32||
|Armv8‑A and Armv8‑R||T32||
|Armv7‑A and Armv7‑R||A32||
|Armv7‑A and Armv7‑R||T32||
|Any architecture with M-profile||T32||
For AArch32 in architectures with A-profile or R-profile, Arm Compiler supports two different semihosting implementations:
- Semihosting using the
SVCinstruction. This is the default and legacy implementation.
- Semihosting using the
HLTinstruction. 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_semihostingfrom 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
mechanisms within the same executable. The library only uses either
HLT instructions, rather than a
mixture. However, you must ensure that you do not mix
HLT instructions when using:
- inline assembly.