__attribute__ ((interrupt))

Use this attribute to indicate that the specified function with mandatory arguments is an interrupt or exception handler.

This attribute tells the compiler to generate function entry and exit sequences suitable for use in an interrupt handler. Use 'IRET' instruction instead of 'RET' instruction to return from interrupt or exception handlers. All registers, except for the EFLAGS register, which is restored by the 'IRET' instruction, are preserved by the compiler.

Any interruptible-without-stack-switch code must be compiled with -mno-red-zone as interrupt handlers can and will touch the red zone because of the hardware design.

Interrupt handler

The interrupt handler must be declared with a mandatory pointer argument:

struct interrupt_frame;



__attribute__ ((interrupt))

void

f (struct interrupt_frame *frame)

{

...

}

The user must properly define the structure the pointer points to.

Exception handler

The exception handler is very similar to the interrupt handler with a different mandatory function signature:

typedef unsigned long long int uword_t;

typedef unsigned int uword_t;



struct interrupt_frame;



__attribute__ ((interrupt))

void

f (struct interrupt_frame *frame, uword_t error_code) { ...

}

The compiler pops the error code off stack before the 'IRET' instruction.

The exception handler should only be used for exceptions, which push an error code and all other exceptions must use the interrupt handler.

The system will crash if the wrong handler is used.

For more complete information about compiler optimizations, see our Optimization Notice.