Interrupt Handlers - 2025.2 English - UG1400

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

Document ID
UG1400
Release Date
2025-11-20
Version
2025.2 English

Interrupt handlers use different compilation methods compared to normal sub-routine calls. In addition to saving non-volatiles, interrupt handlers must save volatile registers they use. Interrupt handlers 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. The following is the definition of the attribute:
void function_name () __attribute__ ((interrupt_handler));
Note: The attribute for the interrupt handler should only exist in the prototype and not in the definition.

Interrupt handlers can also call other functions, which can 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: On-leaf functions are functions that have calls to other sub-routines.

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 a C function uses the attribute fast_interrupt, 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, the attribute only saves the volatiles the function use.
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.