Using semihosting to access resources on the host computer
Semihosting is a mechanism that enables code running on an ARM® target or emulator to communicate with and use the Input/Output facilities on a host computer. The host must be running the emulator, or a debugger that is attached to the ARM target.
Examples of these facilities include keyboard input, screen output,
and disk I/O. For example, you can use this mechanism to enable functions in the C
library, such as
scanf(), to use the screen and keyboard of the host
instead of having a screen and keyboard on the target system.
This is useful because development hardware often does not have all the input and output facilities of the final system. Semihosting enables the host computer to provide these facilities.
Semihosting is implemented by a set of defined software instructions, for example, SVCs, that generate exceptions from program control. The application invokes the appropriate semihosting call and the debug agent then handles the exception. The debug agent provides the required communication with the host.
Semihosting uses stack base and heap base addresses to determine the location and size of the stack and heap. The stack base, also known as the top of memory, is an address that is by default 64K from the end of the heap base. The heap base is by default contiguous to the application code.
The following figure shows a typical layout for an ARM target.
Figure 3-11 Typical layout between top of memory, stack, and heap
Semihosting support in DS-5 Development Studio
The suite of tools in DS-5 Development Studio supports the latest semihosting specification for both AArch64 and AArch32 states on both software models and real target hardware.
The Semihosting for AArch32 and AArch64 Version 2.0 specification introduces support for semihosting in mixed AArch64 and AArch32 systems by using HLT trap instructions in the A64, A32, and T32 instruction sets.
In ARM Compiler v6.6 and later, to build a project using HLT-based semihosting, import the symbol
__use_hlt_semihosting. HLT-based semihosting libraries are then selected automatically at link-time.
See Using the C and C++ libraries with an application in a semihosting environment section in the ARM Compiler ARM C and C++ Libraries and Floating-Point Support User Guide for more information.
In Fast Models and FVPs, semihosting is enabled when the semihosting-enable=true option is set. See Configuring the model in the Fixed Virtual Platforms (FVP) Reference Guide for more information.
In DS-5 Debugger, semihosting is enabled automatically when an image is loaded that contains the special symbols
__semihosting_library_function, or if you explicitly enable semihosting using the set semihosting enabled on command. See the set semihosting command documentation for more information about the command.