[PATCH] D15709: [X86] Support 'interrupt' attribute for x86

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 21 22:20:28 PST 2015

ABataev created this revision.
ABataev added reviewers: aaron.ballman, rjmccall.
ABataev added a subscriber: cfe-commits.

This attribute may be attached to a function definition and
instructs the backend to generate appropriate function entry/exit code so that
it can be used directly as an interrupt handler.
The ``IRET`` instruction, instead of the ``RET`` instruction, is used 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
Any interruptible-without-stack-switch code must be compiled with -mno-red-zone
since interrupt handlers can and will, because of the hardware design, touch
the red zone.

1. interrupt handler must be declared with a mandatory pointer argument:

  .. code-block:: c

    struct interrupt_frame;

    __attribute__ ((interrupt))
    void f (struct interrupt_frame *frame) {

  and user must properly define the structure the pointer pointing to.

2. exception handler:

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

  .. code-block:: c

    #ifdef __x86_64__
    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) {

  and 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.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15709.43432.patch
Type: text/x-patch
Size: 14543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151222/09f097af/attachment-0001.bin>

More information about the cfe-commits mailing list