Reputation: 55
I'm on Rust with AVR atmega328p, using
I have a global_asm!
macro which compiles Ok in a bin main.rs
and gives a compile error in a lib lib.rs
The error is
error: <inline asm>:2:5: instruction requires a CPU feature not currently enabled
jmp 0
^
The macro (the jump-address 0 is for demonstration only, compile fails on jmp instruction, not the address) :
//
global_asm!(r#"
jmp 0
"#);
To test, I have two crates, one to test as --bin with main.rs
, one to test as --lib with lib.rs
Both crates have .cargo/config.toml
[build]
target = "avr-atmega328p.json"
[target.avr-atmega328p]
rustflags = [
#
"-Clink-arg=-nostartfiles",
]
[unstable]
build-std = ["core"]
Both have Config.toml
[package]
name = "..."
edition = "2021"
[dependencies]
[profile.release]
panic = "abort"
lto = true
The main.rs
in the bin test crate :
//!
#![no_std]
#![no_main]
//
#![allow(unused_imports)]
//
#![feature(asm_experimental_arch)]
use core::arch::{ asm, global_asm };
//
global_asm!(r#"
jmp 0
"#);
///
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {
}
}
... compiles and links fine !
The lib.rs
in the lib test crate :
//!
#![no_std]
//
#![allow(unused_imports)]
//
#![feature(asm_experimental_arch)]
use core::arch::{ asm, global_asm };
//
global_asm!(r#"
jmp 0
"#);
... and gives compile error
error: <inline asm>:2:5: instruction requires a CPU feature not currently enabled
jmp 0
^
Command for both crates is cargo build --release
May be someone has an idea how to use the assembler jmp
instruction in a lib.
Btw. using rjmp xxx
works, but I need far jumps.
thx
Upvotes: 0
Views: 84