-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathavr-rjmp-offsets.rs
47 lines (41 loc) · 1.42 KB
/
avr-rjmp-offsets.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! This test case is a `#![no_core]`-version of the MVCE presented in #129301.
//!
//! The function [`delay()`] is removed, as it is not necessary to trigger the
//! wrong behavior and would require some additional lang items.
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
#![no_core]
#![no_main]
#![allow(internal_features)]
use minicore::ptr;
#[no_mangle]
pub fn main() -> ! {
let port_b = 0x25 as *mut u8; // the I/O-address of PORTB
// a simple loop with some trivial instructions within. This loop label has
// to be placed correctly before the `ptr::write_volatile()` (some LLVM ver-
// sions did place it after the first loop instruction, causing unsoundness)
loop {
unsafe { ptr::write_volatile(port_b, 1) };
unsafe { ptr::write_volatile(port_b, 2) };
}
}
// 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) };
}
}
}