This is the mail archive of the
mailing list for the GCC project.
Re: [cfe-dev] RFC: Support x86 interrupt and exception handlers
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Hal Finkel <hfinkel at anl dot gov>, GCC Development <gcc at gcc dot gnu dot org>, cfe-dev at lists dot llvm dot org
- Date: Wed, 23 Sep 2015 15:35:33 -0700
- Subject: Re: [cfe-dev] RFC: Support x86 interrupt and exception handlers
- Authentication-results: sourceware.org; auth=none
- References: <28570882 dot 893 dot 1442876582839 dot JavaMail dot javamailuser at localhost> <56019A4A dot 3030109 at redhat dot com>
On Tue, Sep 22, 2015 at 11:13 AM, Richard Henderson <firstname.lastname@example.org> wrote:
> HJ, I think Hal is right. Providing the data via arguments is vastly superior
> to providing it via builtins. I had actually been thinking the same thing myself.
> It should be easy to check that the function has the correct signature in the
> hook adding the attribute. It should also be easy to check for the attribute
> at the beginning of ix86_function_arg et al, in order to handle these special
Thanks for all feedbacks. Here is the updated spec.
The interrupt and exception handlers are called by x86 processors. X86
hardware pushes information onto stack and calls the handler. The
1. Both interrupt and exception handlers must use the 'IRET' instruction,
instead of the 'RET' instruction, to return from the handlers.
2. All registers are callee-saved in interrupt and exception handlers.
3. The difference between interrupt and exception handlers is the
exception handler must pop 'ERROR_CODE' off the stack before the 'IRET'
The design goals of interrupt and exception handlers for x86 processors
1. Support both 32-bit and 64-bit modes.
2. Flexible for compilers to optimize.
3. Easy to use by programmers.
To implement interrupt and exception handlers for x86 processors, a
compiler should support:
Use this attribute to indicate that the specified function with
mandatory arguments is an interrupt or exception handler. The compiler
generates function entry and exit sequences suitable for use in an
interrupt handler when this attribute is present. 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 compiler.
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 argument:
typedef unsigned long long int uword_t;
typedef unsigned int uword_t;
f (struct interrupt_frame *frame)
2. exception handler:
The exception handler is very similar to the interrupt handler with
a different mandatory function signature:
f (struct interrupt_frame *frame, uword_t error_code)
and compiler pops `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.