diff options
| author | Julian Frimmel <julian@fri-me.de> | 2024-10-14 23:06:32 +0200 |
|---|---|---|
| committer | Julian Frimmel <julian@fri-me.de> | 2024-10-15 12:22:37 +0200 |
| commit | da44e3fdceb46b8d53b2a6e93bca3b80d4243a17 (patch) | |
| tree | 670a0b39848ff753a0dc4c63dd5cdb738ec6e3a3 | |
| parent | 17a19e684cdf3ca088af8b4da6a6209d128913f4 (diff) | |
| download | rust-da44e3fdceb46b8d53b2a6e93bca3b80d4243a17.tar.gz rust-da44e3fdceb46b8d53b2a6e93bca3b80d4243a17.zip | |
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]: https://github.com/rust-lang/rust/issues/129301#issuecomment-2301399472
| -rw-r--r-- | tests/assembly/avr-rjmp-offsets.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/assembly/avr-rjmp-offsets.rs b/tests/assembly/avr-rjmp-offsets.rs new file mode 100644 index 00000000000..fafa2b43138 --- /dev/null +++ b/tests/assembly/avr-rjmp-offsets.rs @@ -0,0 +1,62 @@ +//@ compile-flags: -Copt-level=s --target=avr-unknown-gnu-atmega328 -C panic=abort +//@ needs-llvm-components: avr +//@ assembly-output: emit-asm + +#![feature( + no_core, + lang_items, + intrinsics, + rustc_attrs, + arbitrary_self_types, + asm_experimental_arch +)] +#![crate_type = "rlib"] +#![no_core] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} + +use minicore::ptr; + +// CHECK-LABEL: pin_toggling +#[no_mangle] +pub fn pin_toggling() { + let port_b = 0x25 as *mut u8; // the I/O-address of PORTB + loop { + unsafe { ptr::write_volatile(port_b, 1) }; + delay(500_0000); + unsafe { ptr::write_volatile(port_b, 2) }; + delay(500_0000); + } +} + +#[inline(never)] +fn delay(_: u32) { + unsafe { asm!("nop") }; +} + +// FIXME: replace with proper minicore once available (#130693) +mod minicore { + #[lang = "sized"] + pub trait Sized {} + + #[lang = "copy"] + pub trait Copy {} + impl Copy for u32 {} + impl Copy for &u32 {} + impl<T: ?Sized> Copy for *mut T {} + + pub mod ptr { + #[inline] + #[rustc_diagnostic_item = "ptr_write_volatile"] + pub unsafe fn write_volatile<T>(dst: *mut T, src: T) { + extern "rust-intrinsic" { + #[rustc_nounwind] + pub fn volatile_store<T>(dst: *mut T, val: T); + } + unsafe { volatile_store(dst, src) }; + } + } +} |
