Skip to content

Commit 44fffa3

Browse files
committed
Use asm macro instead of removed llvm_asm.
1 parent fd53654 commit 44fffa3

File tree

6 files changed

+22
-42
lines changed

6 files changed

+22
-42
lines changed

src/asm.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
//! Miscellaneous assembly instructions
22
3+
use crate::asm;
4+
35
/// A no-operation. Useful to prevent delay loops from being optimized away.
46
#[inline(always)]
57
pub fn nop() {
68
unsafe {
7-
llvm_asm!("nop"
8-
:
9-
:
10-
:
11-
: "volatile");
9+
asm!("nop");
1210
}
1311
}
1412

1513
/// A compiler fence, prevents instruction reordering.
1614
#[inline(always)]
1715
pub fn barrier() {
1816
unsafe {
19-
llvm_asm!("" ::: "memory" : "volatile");
17+
asm!("");
2018
}
2119
}

src/interrupt.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Interrupts
22
3+
use crate::asm;
4+
35
pub use bare_metal::{CriticalSection, Mutex};
46

57
/// Disables all interrupts
@@ -8,11 +10,7 @@ pub fn disable() {
810
match () {
911
#[cfg(target_arch = "msp430")]
1012
() => unsafe {
11-
llvm_asm!("dint { nop"
12-
:
13-
:
14-
: "memory"
15-
: "volatile");
13+
asm!("dint {{ nop");
1614
},
1715
#[cfg(not(target_arch = "msp430"))]
1816
() => {}
@@ -31,11 +29,7 @@ pub unsafe fn enable() {
3129
match () {
3230
#[cfg(target_arch = "msp430")]
3331
() => {
34-
llvm_asm!("nop { eint { nop"
35-
:
36-
:
37-
: "memory"
38-
: "volatile");
32+
asm!("nop {{ eint {{ nop");
3933
}
4034
#[cfg(not(target_arch = "msp430"))]
4135
() => {}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
//! - Safe wrappers around assembly instructions like `nop`
1111
1212
#![deny(missing_docs)]
13-
#![feature(llvm_asm)]
13+
#![feature(asm_experimental_arch)]
1414
#![no_std]
1515

16+
use core::arch::asm;
17+
1618
extern crate bare_metal;
1719

1820
#[macro_use]

src/register/pc.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
//! Program counter
22
3+
use crate::asm;
4+
35
/// Reads the CPU register
46
#[inline(always)]
57
pub fn read() -> u16 {
68
let r;
79
unsafe {
8-
llvm_asm!("mov R0,$0"
9-
: "=r"(r)
10-
:
11-
:
12-
: "volatile");
10+
asm!("mov R0, {0}", out(reg) r);
1311
}
1412
r
1513
}
1614

1715
/// Writes `bits` to the CPU register
1816
#[inline(always)]
1917
pub unsafe fn write(bits: u16) {
20-
llvm_asm!("mov $0,R0"
21-
:
22-
: "r"(bits)
23-
:
24-
: "volatile");
18+
asm!("mov {0}, R0", in(reg) bits);
2519
}

src/register/sp.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
//! Main Stack Pointer
22
3+
use crate::asm;
4+
35
/// Reads the CPU register
46
#[inline(always)]
57
pub fn read() -> u16 {
68
let r;
79
unsafe {
8-
llvm_asm!("mov R1,$0"
9-
: "=r"(r)
10-
:
11-
:
12-
: "volatile");
10+
asm!("mov R1, {0}", out(reg) r);
1311
}
1412
r
1513
}
1614

1715
/// Writes `bits` to the CPU register
1816
#[inline(always)]
1917
pub unsafe fn write(bits: u16) {
20-
llvm_asm!("mov $0,R1"
21-
:
22-
: "r"(bits)
23-
:
24-
: "volatile");
18+
asm!("mov {0}, R1", in(reg) bits);
2519
}

src/register/sr.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Status Register
22
3+
use crate::asm;
4+
35
/// Status Register
46
#[derive(Clone, Copy, Debug)]
57
pub struct Sr {
@@ -77,11 +79,7 @@ impl Sr {
7779
pub fn read() -> Sr {
7880
let r: u16;
7981
unsafe {
80-
llvm_asm!("mov R2, $0"
81-
: "=r"(r)
82-
:
83-
:
84-
: "volatile");
82+
asm!("mov R2, {0}", out(reg) r);
8583
}
8684
Sr { bits: r }
8785
}

0 commit comments

Comments
 (0)