Specifications

Table Of Contents
ARM Debugger 2 8 A R M S p e c i f i c I m p l e m e n t a t i o n s
©1989-2014 Lauterbach GmbH
Semihosting
Semihosting is a technique for an application program running on an ARM processor to communicate with
the host computer of the debugger. This way the application can use the I/O facilities of the host computer
like keyboard input, screen output, and file I/O. This is especially useful if the target platform does not yet
provide these I/O facilities or in order to output additional debug information in printf() style.
A semihosting call from the application causes an exception by a SVC (SWI) instruction together with a
certain SVC number to indicate a semihosting request. The type of operation is passed in R0. R1 points to
the other parameters. On Cortex-M semihosting is implemented using the BKPT instead of SVC instruction.
Normally semihosting is invoked by code within the C library functions of the ARM RealView compiler like
printf() and scanf(). The application can also invoke the operations used for keyboard input, screen output,
and file I/O directly. The operations are described in the RealView Compilation Tools Developer Guide from
ARM in the chapter ‚Semihosting Operations'.
The debugger which needs to interface to the I/O facilities on the host provides two ways to handle a
semihosting request which results in a SVC (SWI) or BKPT exception:
SVC (SWI) Emulation Mode
A breakpoint placed on the SVC exception entry stops the application. The debugger handles the request
while the application is stopped, provides the required communication with the host, and restarts the
application at the address which was stored in the link register R14 on the SVC exception call. Other as for
the DCC mode the SVC parameter has to be 0x123456 to indicate a semihosting request.
This mode is enabled by TERM.METHOD ARMSWI [<address>] and by opening a TERM.GATE window
for the semihosting screen output. The handling of the semihosting requests is only active when the
TERM.GATE window is existing.
On ARM7 an on-chip or software breakpoint needs to be set at address 8 (SWI exception entry). On other
ARM cores also the vector catch register can be used: TrOnchip.Set SWI ON. The Cortex-M does not need
a breakpoint because it already uses the breakpoint instruction BKPT for the semihosting request.
When using the <address> option of the TERM.METHOD ARMSWI [<address>] any memory location with
a breakpoint on it can be used as a semihosting service entry instead of the SVC call at address 8. The
application just needs to jump to that location. After servicing the request the program execution continues at
that address (not at the address in the link register R14). You could for example place a ’BX R14’ command
at that address and hand the return address in R14. Since this method does not use the SVC command no
parameter (0x123456) will be checked to identify a semihosting call.