calling convention for MSP430 interrupts by japaric · Pull Request #38465 · rust-lang/rust (original) (raw)

…ention, r=nagisa

Add support for the x86-interrupt calling convention

This calling convention can be used for definining interrupt handlers on 32-bit and 64-bit x86 targets. The compiler then uses iret instead of ret for returning and ensures that all registers are restored to their original values.

Usage:

extern "x86-interrupt" fn handler(stack_frame: &ExceptionStackFrame) {…}

for interrupts and exceptions without error code and

extern "x86-interrupt" fn handler_with_err_code(stack_frame: &ExceptionStackFrame,
                                                error_code: u64) {…}

for exceptions that push an error code (e.g., page faults or general protection faults). The programmer must ensure that the correct version is used for each interrupt.

For more details see the LLVM PR and the corresponding proposal.

It is also possible to implement interrupt handlers on x86 through naked functions. In fact, almost all existing Rust OS projects for x86 use naked functions for this, including Redox, IntermezzOS, and blog_os. So support for the x86-interrupt calling convention isn't absolutely needed.

However, it has a number of benefits to naked functions:

Edit: See the tracking issue for an updated list of issues.

Unfortunately, the implementation of the x86-interrupt calling convention in LLVM has some issues that make it unsuitable for 64-bit kernels at the moment:

This PR adds experimental support for this calling convention under the abi_x86_interrupt feature gate. The implementation is very similar to rust-lang#38465 and was surprisingly simple :).

There is no accepted RFC for this change. In fact, the RFC for interrupt calling convention from 2015 was closed in favor of naked functions. However, the reactions to the recent PR for a MSP430 interrupt calling convention were [in favor of experimental interrupt ABIs](rust-lang#38465 (comment)).

@tari @steveklabnik @jackpot51 @ticki @hawkw @thepowersgang, you might be interested in this.