Skip to content

Commit da35b2e

Browse files
authored
[clang][Docs] Document X86 interrupt attribute (#65662)
Adds documentation for the X86 `__attribute__((interrupt))` attribute, in a similar format to interrupt attributes of other platforms. Migrated from https://reviews.llvm.org/D159317
1 parent 4a1fe09 commit da35b2e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
31253125
let Subjects = SubjectList<[HasFunctionProto]>;
31263126
let ParseKind = "Interrupt";
31273127
let HasCustomParsing = 1;
3128-
let Documentation = [Undocumented];
3128+
let Documentation = [AnyX86InterruptDocs];
31293129
}
31303130

31313131
def AnyX86NoCallerSavedRegisters : InheritableAttr,

clang/include/clang/Basic/AttrDocs.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,54 @@ Marking virtual functions as ``disable_tail_calls`` is legal.
48014801
}];
48024802
}
48034803

4804+
def AnyX86InterruptDocs : Documentation {
4805+
let Category = DocCatFunction;
4806+
let Heading = "interrupt (X86)";
4807+
let Content = [{
4808+
Clang supports the GNU style ``__attribute__((interrupt))`` attribute on X86
4809+
targets. This attribute may be attached to a function definition and instructs
4810+
the backend to generate appropriate function entry/exit code so that it can be
4811+
used directly as an interrupt service routine.
4812+
4813+
Interrupt handlers have access to the stack frame pushed onto the stack by the processor,
4814+
and return using the ``IRET`` instruction. All registers in an interrupt handler are callee-saved.
4815+
Exception handlers also have access to the error code pushed onto the stack by the processor,
4816+
when applicable.
4817+
4818+
An interrupt handler must take the following arguments:
4819+
4820+
.. code-block:: c
4821+
4822+
__attribute__ ((interrupt))
4823+
void f (struct stack_frame *frame) {
4824+
...
4825+
}
4826+
4827+
Where ``struct stack_frame`` is a suitable struct matching the stack frame pushed by the
4828+
processor.
4829+
4830+
An exception handler must take the following arguments:
4831+
4832+
.. code-block:: c
4833+
4834+
__attribute__ ((interrupt))
4835+
void g (struct stack_frame *frame, unsigned long code) {
4836+
...
4837+
}
4838+
4839+
On 32-bit targets, the ``code`` argument should be of type ``unsigned int``.
4840+
4841+
Exception handlers should only be used when an error code is pushed by the processor.
4842+
Using the incorrect handler type will crash the system.
4843+
4844+
Interrupt and exception handlers cannot be called by other functions and must have return type ``void``.
4845+
4846+
Interrupt and exception handlers should only call functions with the 'no_caller_saved_registers'
4847+
attribute, or should be compiled with the '-mgeneral-regs-only' flag to avoid saving unused
4848+
non-GPR registers.
4849+
}];
4850+
}
4851+
48044852
def AnyX86NoCallerSavedRegistersDocs : Documentation {
48054853
let Category = DocCatFunction;
48064854
let Content = [{

0 commit comments

Comments
 (0)