Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit da44e3f

Browse files
committed
Start test case for rjmp regression test
This commit introduces a minimal `![no_core]`-test case running on AVR, that contains the MCWE mentioned in [129301]. The test case itself does not have any assertions yet, but it shows the minimal set an language items necessary within the test case. [129301]: rust-lang#129301 (comment)
1 parent 17a19e6 commit da44e3f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/assembly/avr-rjmp-offsets.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//@ compile-flags: -Copt-level=s --target=avr-unknown-gnu-atmega328 -C panic=abort
2+
//@ needs-llvm-components: avr
3+
//@ assembly-output: emit-asm
4+
5+
#![feature(
6+
no_core,
7+
lang_items,
8+
intrinsics,
9+
rustc_attrs,
10+
arbitrary_self_types,
11+
asm_experimental_arch
12+
)]
13+
#![crate_type = "rlib"]
14+
#![no_core]
15+
16+
#[rustc_builtin_macro]
17+
macro_rules! asm {
18+
() => {};
19+
}
20+
21+
use minicore::ptr;
22+
23+
// CHECK-LABEL: pin_toggling
24+
#[no_mangle]
25+
pub fn pin_toggling() {
26+
let port_b = 0x25 as *mut u8; // the I/O-address of PORTB
27+
loop {
28+
unsafe { ptr::write_volatile(port_b, 1) };
29+
delay(500_0000);
30+
unsafe { ptr::write_volatile(port_b, 2) };
31+
delay(500_0000);
32+
}
33+
}
34+
35+
#[inline(never)]
36+
fn delay(_: u32) {
37+
unsafe { asm!("nop") };
38+
}
39+
40+
// FIXME: replace with proper minicore once available (#130693)
41+
mod minicore {
42+
#[lang = "sized"]
43+
pub trait Sized {}
44+
45+
#[lang = "copy"]
46+
pub trait Copy {}
47+
impl Copy for u32 {}
48+
impl Copy for &u32 {}
49+
impl<T: ?Sized> Copy for *mut T {}
50+
51+
pub mod ptr {
52+
#[inline]
53+
#[rustc_diagnostic_item = "ptr_write_volatile"]
54+
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
55+
extern "rust-intrinsic" {
56+
#[rustc_nounwind]
57+
pub fn volatile_store<T>(dst: *mut T, val: T);
58+
}
59+
unsafe { volatile_store(dst, src) };
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)