2017-04-13 73 views
2

我正在为Rust中涉及中断服务例程的AMR板编写一个裸机应用程序。目前,我使用#naked函数与我自己的汇编程序prolog/epilog。但是,我想知道是否有更好的(并且希望更便携)的方式,我错过了,也许是每晚在Rust上的类似#interrupt的属性或任何其他编译器支持。我认为沿着GCC的__attribute__ ((interrupt ("IRQ")))的路线,因为Rust的后端LLVM提供了这样一个属性。Rust编译器支持中断

回答

4

中断仅仅是另一种类型的调用约定的。对于Rust的AVR端口,我们添加了两种新的调用约定,一种用于AVR支持的每种中断。

调用约定的权威列表is the source code。拉斯特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 
} 

unstable book also mentions that the different calling conventions exist

要使用这些,你宣布你的功能吧:

#![feature(abi_msp430_interrupt)] 

extern "msp430-interrupt" fn handler() {} 

它仍然是你来注册功能中断矢量表(或同等学历)的异常处理程序。

当然,您可能需要提交PR,通知Rust前端要使用的特定LLVM调用约定,如果您尚未在此列表中。

-2

这里复制的信息,无耻;)

https://github.com/nix-rust/nix

https://users.rust-lang.org/t/unix-signals-in-rust/733/3

use nix::sys::signal; 

extern fn handle_sigint(_:i32) { 
    println!("Interrupted!"); 
    panic!(); 
} 

fn main() { 
    let sig_action = signal::SigAction::new(handle_sigint, 
              signal::SockFlag::empty(), 
              signal::SigSet::empty()); 
    signal::sigaction(signal::SIGINT, &sig_action); 
} 
+0

据我所知,这是关于a)b)unix环境中的信号,不是吗?问题中描述的环境不符合这两个条件。 – Matthias

+0

阅读第二个链接,这是关于中断。铁锈不支持它。所以OP使用nix库来解决。 – sailfish009

+0

SIGINT是在ISR被调用之后生成的信号。在这个时候,我不必关心序言或epilog。我正在寻找编译器支持硬件中断的ISR,像gcc的属性'__attribute__((interrupt(“IRQ”)));'' – Matthias