Keil Logo

SWI Functions

Software Interrupt (SWI) functions are functions that run in Supervisor Mode of ARM7™ and ARM9™ core and are interrupt protected. SWI functions can accept arguments and can return values. They are used in the same way as other functions.

The difference is hidden to the user and is handled by the C-compiler. It generates different code instructions to call SWI functions. SWI functions are called by executing the SWI instruction. When executing the SWI instruction, the controller changes the running mode to a Supervisor Mode and blocks any further IRQ interrupt requests. Note that the FIQ interrupts are not disabled in this mode. When the ARM controller leaves this mode, interrupts are enabled again.

If you want to use SWI functions in your RTX kernel project, you need to:

  1. Copy the SWI_Table.s file to your project folder and include it into your project.
    This file is located in the \Keil\ARM\RL\RTX\SRC\ARM folder.
  2. Declare a function with a __swi(x) attribute. Use the first SWI number, starting from 8, that is free.
    void __swi(8)  inc_5bit (U32 *cp);
  3. Write a function implementation and convert the function name into a __SWI_x function name. This name is referenced later by the linker from SWI_Table.s module.
    void __SWI_8            (U32 *cp) {
      /* A protected function to increment a 5-bit counter. */
      *cp = (*cp + 1) & 0x1F;
  4. Add the function __SWI_x to the SWI function table in the SWI_Table.s module.

    First import it from other modules:
    ; Import user SWI functions here.
                    IMPORT  __SWI_8
    then add a reference to it into the table:
    ; Insert user SWI functions here. SWI 0..7 are used by RTL Kernel.
                    DCD     __SWI_8                 ; SWI 8  User Function
  5. Your SWI function should now look like this:
    void __swi(8)  inc_5bit (U32 *cp);
    void __SWI_8            (U32 *cp) {
      /* A protected function to increment a 5-bit counter. */
      *cp = (*cp + 1) & 0x1F;


  • SWI functions 0..7 are reserved for the RTX kernel.
  • Do not leave gaps when numbering SWI functions. They must occupy a continuous range of numbers starting from 8.
  • SWI functions can still be interrupted by FIQ interrupts.

Related Knowledgebase Articles

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.