|Non-Confidential||PDF version||ARM DUI0446Z|
|Home > Controlling Target Execution > Using semihosting to access resources on the host computer|
Semihosting is a mechanism for ARM® targets to communicate input/output requests from application code to a host computer running a debugger.
You can use semihosting to enable the host computer to provide input
and output facilities of the final system if your development hardware does not have
the necessary facilities. 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.
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.
If you are compiling for the ARMv6-M or ARMv7-M architectures, the Thumb
BKPT instruction is used instead of the Thumb
SVC instruction. For more information, see: The semihosting interface.)
DS-5 supports semihosting for both AArch64 and AArch32 states on both software models and real target hardware. DS-5 Debugger handles semihosting by intercepting instructions as per the following table:
Table 3-1 Semihosting trap instructions and encodings
HLTinstruction and the debugger handles the semihosting automatically.
HLTinstructions for semihosting traps, the debugger handles the semihosting automatically.
For AArch32 code running on real target hardware using a semihosting library
configured to use
SVC instructions or when using a
software model in either AArch32 or AArch64 states, you must explicitly set
a semihosting trap. Otherwise the debugger reports this error:
ERROR(TAB180): The semihosting
breakpoint address has not been specified.
This error is reported when the debugger tries to enable
semihosting, either when an image is loaded that contains the special
__semihosting_library_function, or if
you explicitly try to enable semihosting using set
semihosting enabled on.
You can set a semihosting trap in the debugger by executing the CLI command: set semihosting vector <trap_address>
This instructs the debugger to set a breakpoint at this address, and when this breakpoint is hit, the debugger takes control to perform the semihosting operation.
For AArch32 state, how execution gets to this address from the
SVC semihosting instruction
depends on the program used, the Exception level the program is executing at, how
exceptions are set up to propagate, and other settings.
It is your responsibility to ensure that execution reaches this address. This is typically done by setting the semihosting vector address to an appropriate offset in the appropriate vector table, or by creating an explicit entry in the vector table that, perhaps conditionally, branches to a known offset.