我正在为Rust中涉及中断服务例程的AMR板编写一个裸机应用程序。目前,我使用#naked
函数与我自己的汇编程序prolog/epilog。但是,我想知道是否有更好的(并且希望更便携)的方式,我错过了,也许是每晚在Rust上的类似#interrupt
的属性或任何其他编译器支持。我认为沿着GCC的__attribute__ ((interrupt ("IRQ")))
的路线,因为Rust的后端LLVM提供了这样一个属性。Rust编译器支持中断
2
A
回答
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);
}
相关问题
- 1. 编译器支持C11
- 2. Erlang编译器UTF32支持
- 3. 编译器,它支持Windows Vista中
- 4. 支持Windows编译
- 5. ios编译ffmpeg不支持ac3支持
- 6. icarus(iverilog编译器)的SystemVerilog支持
- 7. 什么编译器支持CUDA
- 8. 编译器支持枚举值
- 9. GNU Java编译器是否支持JNA?
- 10. 支持DirectX 11库的编译器
- 11. 哪些编译器支持Haskell FFI
- 12. 反编译器支持Java 8?
- 13. 通过TypeScript编译器支持“export ... from”
- 14. 启用C++支持ARMCC编译器
- 15. matlab编译器支持的matlab videoplayer
- 16. Android支持库v4和Google Maps API中断编译
- 17. 用于编译器的printf宏,支持和不支持VARIADIC
- 18. Rust如何编译为机器码?
- 19. 编译POCO与支持UTF8
- 20. 用MPI支持编译Valgrind
- 21. 编译器支持STL容器中的有状态分配器
- 22. 在Xcode中编辑支持文件编译器的位置
- 23. 在Qt中编译InterBase支持
- 24. ZFDataGrid支持翻译器
- 25. 如何判断编译器支持哪种版本的ISO C++标准?
- 26. F#编译器是否支持与C#编译器相同的foreach优化
- 27. Rust是否支持fork()跨平台?
- 28. 如何编译支持文本编解码器的Qt库4.7.1?
- 29. 支持Java编译器API中的仅清单jar文件
- 30. 什么编译器不支持printf标志中的“%#x”样式?
据我所知,这是关于a)b)unix环境中的信号,不是吗?问题中描述的环境不符合这两个条件。 – Matthias
阅读第二个链接,这是关于中断。铁锈不支持它。所以OP使用nix库来解决。 – sailfish009
SIGINT是在ISR被调用之后生成的信号。在这个时候,我不必关心序言或epilog。我正在寻找编译器支持硬件中断的ISR,像gcc的属性'__attribute__((interrupt(“IRQ”)));'' – Matthias