5.1.1. The SWI interface

The ARM and Thumb SWI instructions contain a field that encodes the SWI number used by the application code. This number can be decoded by the SWI handler in the system. See the chapter on exception handling in ADS Developer Guide for more information on SWI handlers.

Semihosting operations are requested using a single SWI number. This leaves the other SWI numbers available for use by the application or operating system. The SWI used for semihosting is:

0x123456

in ARM state

0xAB

in Thumb state

The SWI number indicates to the debug agent that the SWI is a semihosting request. In order to distinguish between operations, the operation type is passed in r0. All other parameters are passed in a block that is pointed to by r1.

The result is returned in r0, either as an explicit return value or as a pointer to a data block. Even if no result is returned, assume that r0 is corrupted.

The available semihosting operation numbers passed in r0 are allocated as follows:

0x00 to 0x31

These are used by ARM.

0x32 to 0xFF

These are reserved for future use by ARM.

0x100 to 0x1FF

These are reserved for user applications. They will not be used by ARM.

If you are writing your own SWI operations, however, you are advised to use a different SWI number rather than using the semihosted SWI number and these operation type numbers.

0x200 to 0xFFFFFFFF

These are undefined. They are not currently used and not recommended for use.

In the following sections, the number in parentheses after the operation name is the value placed into r0. For example SYS_OPEN (0x01).

If you are calling SWIs from assembly language code it is best to use the operation names that are defined in semihost.h. You can define the operation names with an EQU directive. For example:

SYS_OPEN    EQU 0x01
SYS_CLOSE   EQU 0x02

Changing the semihosting SWI numbers

It is strongly recommended that you do not change the semihosting SWI numbers 0x123456 (ARM) or 0xAB (Thumb). If you do so you must:

  • change all the code in your system, including library code, to use the new SWI number

  • reconfigure your debugger to use the new SWI number.

Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI0058D
Non-Confidential