gpt4 book ai didi

Rust 编译器对中断的支持

转载 作者:行者123 更新时间:2023-11-29 08:00:27 24 4
gpt4 key购买 nike

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

最佳答案

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

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

unstable book also mentions that the different calling conventions exist .

要使用它们,您需要用它声明您的函数:

#![feature(abi_msp430_interrupt)] 

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

将函数注册为中断向量表(或等效项)的异常处理程序仍然取决于您。

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

关于Rust 编译器对中断的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43389196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com