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.
- To distinguish an interrupt handler from a sub-routine,
mb-gcclooks 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
rtidfor returning to the interrupted function.
- The MicroBlaze compiler provides the
save_volatiles, which is similar to the
interrupt_handlerattribute, but returns using
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));
- 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_interruptis used on a C function, MicroBlaze saves only minimal registers.
void function_name () __attribute__ ((fast_interrupt));
|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.
|This attribute is similar to interrupt_handler, but it uses rtsd to return to the interrupted function, instead of rtid.
|This attribute is similar to interrupt_handler, but it jumps directly to the interrupt routine address instead of jumping to the fixed address 0x10.