Mat*_*ias 3 interrupt bare-metal rust
我正在为Rust中的AMR板写一个裸机应用程序,它涉及中断服务程序.目前,我使用#naked自己的汇编程序prolog/epilog函数.但是,我想知道是否有更好的(并且希望更便携)方式我错过了,也许#interruptRust中的类似属性或任何其他编译器支持.我认为,就像GCC一样__attribute__ ((interrupt ("IRQ"))),Rust的后端LLVM提供了这样的属性.
中断只是另一种调用约定.对于Rust的AVR端口,我们添加了两种新类型的调用约定,一种用于AVR支持的每种中断.
调用约定的权威列表是源代码.Rust 1.16列出了这些:
#[derive(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)]
pub enum Abi {
// NB: This ordering MUST match the AbiDatas array below.
// (This is ensured by the test indices_are_correct().)
// Single platform ABIs
Cdecl,
Stdcall,
Fastcall,
Vectorcall,
Aapcs,
Win64,
SysV64,
PtxKernel,
Msp430Interrupt,
// Multiplatform / generic ABIs
Rust,
C,
System,
RustIntrinsic,
RustCall,
PlatformIntrinsic,
Unadjusted
}
Run Code Online (Sandbox Code Playgroud)
要使用它们,您需要用它声明您的函数:
#![feature(abi_msp430_interrupt)]
extern "msp430-interrupt" fn handler() {}
Run Code Online (Sandbox Code Playgroud)
您仍然可以使用中断向量表(或等效项)将该函数注册为异常处理程序.
当然,如果您的列表中尚未包含特定的LLVM调用约定,则可能需要提交一个通知Rust前端的PR.