Interrupt Handlers - 2021.2 English

Vitis Unified Software Platform Documentation: Embedded Software Development (UG1400)

Document ID
UG1400
ft:locale
English (United States)
Release Date
2021-12-15
Version
2021.2 English

Interrupt handlers must be compiled in a different manner than normal sub-routine calls. In addition to saving non-volatiles, interrupt handlers must save the volatile registers that are being used. Interrupt handlers should also store the value of the machine status register (RMSR) when an interrupt occurs.

interrupt_handler
To distinguish an interrupt handler from a sub-routine, mb-gcc looks for an attribute (interrupt_handler) in the declaration of the code. This attribute is defined as follows:
void function_name () __attribute__ ((interrupt_handler));
Note: The attribute for the interrupt handler is to be given only in the prototype and not in the definition.

Interrupt handlers might also call other functions, which might use volatile registers. To maintain the correct values in the volatile registers, the interrupt handler saves all the volatiles, if the handler is a non-leaf function.

Note: Functions that have calls to other sub-routines are called non-leaf functions.

Interrupt handlers are defined in the Microprocessor Software Specification (MSS) files. These definitions automatically add the attributes to the interrupt handler functions. The interrupt handler uses the instruction rtid for returning to the interrupted function.

save_volatiles
The MicroBlaze compiler provides the attribute save_volatiles, which is similar to the interrupt_handler attribute, but returns using rtsd instead of rtid. This attribute saves all the volatiles for non-leaf functions and only the used volatiles in the case of leaf functions.
void function_name () __attribute__((save_volatiles));
fast_interrupt
The MicroBlaze compiler provides the attribute fast_interrupt, which is similar to the interrupt_handler attribute. On fast interrupt, MicroBlaze jumps to the interrupt routine address instead jumping to the fixed address 0x10.

Unlike a normal interrupt, when the attribute fast_interrupt is used on a C function, MicroBlaze saves only minimal registers.

void function_name () __attribute__ ((fast_interrupt));
Table 1. Use of Attributes
Attributes Functions
interrupt_handler This attribute saves the machine status register and all the volatiles, in addition to the non-volatile registers. rtid returns from the interrupt handler. If the interrupt handler function is a leaf function, only those volatiles which are used by the function are saved.
save_volatiles This attribute is similar to interrupt_handler, but it uses rtsd to return to the interrupted function, instead of rtid.
fast_interrupt This attribute is similar to interrupt_handler, but it jumps directly to the interrupt routine address instead of jumping to the fixed address 0x10.