3.9 Using the semihosting API

CADI provides a semihosting interface that enables interaction between a user and a connected target.

A debugger can use the host machine I/O to emulate the I/O devices in a simulation platform. An application running on a target component can request keyboard input that is then provided interactively when you enter the input on the host keyboard.

Figure 3-6 Semihosting interface
To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.

Because semihosting is used by the simulation target to provide and receive information, the interface methods are provided by the CADICallbackObj object. The primary methods are appliInput() and appliOutput(). Both use a data buffer of type char and the buffer size defined by the target.

After the call returns, the actualCount parameter indicates:

  • How many characters were successfully written to the output device by appliOutput().
  • How many characters were received from the input device by appliInput().

Because the forwarded string might contain '\0' characters, the end of the string is not indicated by '\0'.


actualCount is also used to indicate:
  • That the end of file was reached by returning zero.
  • That a string reading error occurred by returning static_cast<uint32_t>(-1).

The addressed target of appliInput() and appliOutput() is typically one StdIn, StdOut, and StdErr streams on the host. The host can redirect these standard stream calls to log files. The IDs for the standard streams are defined in the enum type CADIStreamId. The numbering corresponds to the C file conventions:

  • 0 is stdin.
  • 1 is stdout.
  • 2 is stderr.
  • IDs greater than 2 identify explicitly opened file streams.

Use the appliOpen() and appliClose() callbacks to open and close streams to files. The returned ID identifies the stream. The file stream IDs and standard stream IDs cannot overlap.

The semihosting interface also provides the doString() method to send messages from the target to the caller. This method can be used, for example, to send error messages or debug output. This call is not intended to be used for passing printouts from an application.

Non-ConfidentialPDF file icon PDF versionARM 100963_0200_00_en
Copyright © 2014–2017 ARM Limited or its affiliates. All rights reserved.