Skip to content

Commit 11d43cf

Browse files
authored
Substitute llvm_asm!(deprecated) with asm! (#5)
1 parent b6c469f commit 11d43cf

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/asm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ macro_rules! instruction {
77
pub unsafe fn $fnname() {
88
match () {
99
#[cfg(all(riscv, feature = "inline-asm"))]
10-
() => llvm_asm!($asm :::: "volatile"),
10+
() => core::arch::asm!($asm),
1111

1212
#[cfg(all(riscv, not(feature = "inline-asm")))]
1313
() => {
@@ -58,7 +58,7 @@ instruction!(
5858
pub unsafe fn sfence_vma(asid: usize, addr: usize) {
5959
match () {
6060
#[cfg(all(riscv, feature = "inline-asm"))]
61-
() => llvm_asm!("sfence.vma $0, $1" :: "r"(asid), "r"(addr) :: "volatile"),
61+
() => core::arch::asm!("sfence.vma {0}, {1}", in(reg) addr, in(reg) asid),
6262

6363
#[cfg(all(riscv, not(feature = "inline-asm")))]
6464
() => {
@@ -87,7 +87,7 @@ mod hypervisor_extension {
8787
match () {
8888
#[cfg(all(riscv, feature = "inline-asm"))]
8989
// Since LLVM does not recognize the two registers, we assume they are placed in a0 and a1, correspondingly.
90-
() => llvm_asm!($asm ::"{x10}"(rs1),"{x11}"(rs2):: "volatile"),
90+
() => core::arch::asm!($asm, in("x10") rs1, in("x11") rs2),
9191

9292
#[cfg(all(riscv, not(feature = "inline-asm")))]
9393
() => {
@@ -112,7 +112,7 @@ mod hypervisor_extension {
112112
#[cfg(all(riscv, feature = "inline-asm"))]
113113
() => {
114114
let mut result : usize;
115-
llvm_asm!($asm :"={x10}"(result):"{x10}"(rs1):: "volatile");
115+
core::arch::asm!($asm, inlateout("x10") rs1 => result);
116116
return result;
117117
}
118118

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
//! - Interrupt manipulation mechanisms.
1414
//! - Wrappers around assembly instructions like `WFI`.
1515
16+
1617
#![no_std]
17-
#![cfg_attr(feature = "inline-asm", feature(llvm_asm))]
18+
#![cfg_attr(feature = "inline-asm", feature(asm_const))]
1819
extern crate bare_metal;
1920
#[macro_use]
2021
extern crate bitflags;

src/register/macros.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ macro_rules! read_csr {
77
#[cfg(all(riscv, feature = "inline-asm"))]
88
() => {
99
let r: usize;
10-
llvm_asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
10+
core::arch::asm!("csrrs {0}, {1}, x0", out(reg) r, const $csr_number);
1111
r
1212
}
1313

@@ -36,7 +36,7 @@ macro_rules! read_csr_rv32 {
3636
#[cfg(all(riscv32, feature = "inline-asm"))]
3737
() => {
3838
let r: usize;
39-
llvm_asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
39+
core::arch::asm!("csrrs {0}, {1}, x0", out(reg) r, const $csr_number);
4040
r
4141
}
4242

@@ -102,7 +102,7 @@ macro_rules! write_csr {
102102
unsafe fn _write(bits: usize) {
103103
match () {
104104
#[cfg(all(riscv, feature = "inline-asm"))]
105-
() => llvm_asm!("csrrw x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
105+
() => core::arch::asm!("csrrw x0, {1}, {0}", in(reg) bits, const $csr_number),
106106

107107
#[cfg(all(riscv, not(feature = "inline-asm")))]
108108
() => {
@@ -128,7 +128,7 @@ macro_rules! write_csr_rv32 {
128128
unsafe fn _write(bits: usize) {
129129
match () {
130130
#[cfg(all(riscv32, feature = "inline-asm"))]
131-
() => llvm_asm!("csrrw x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
131+
() => core::arch::asm!("csrrw x0, {1}, {0}", in(reg) bits, const $csr_number),
132132

133133
#[cfg(all(riscv32, not(feature = "inline-asm")))]
134134
() => {
@@ -178,7 +178,7 @@ macro_rules! set {
178178
unsafe fn _set(bits: usize) {
179179
match () {
180180
#[cfg(all(riscv, feature = "inline-asm"))]
181-
() => llvm_asm!("csrrs x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
181+
() => core::arch::asm!("csrrs x0, {1}, {0}", in(reg) bits, const $csr_number),
182182

183183
#[cfg(all(riscv, not(feature = "inline-asm")))]
184184
() => {
@@ -204,7 +204,7 @@ macro_rules! clear {
204204
unsafe fn _clear(bits: usize) {
205205
match () {
206206
#[cfg(all(riscv, feature = "inline-asm"))]
207-
() => llvm_asm!("csrrc x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
207+
() => core::arch::asm!("csrrc x0, {1}, {0}", in(reg) bits, const $csr_number),
208208

209209
#[cfg(all(riscv, not(feature = "inline-asm")))]
210210
() => {
@@ -229,7 +229,7 @@ macro_rules! set_csr {
229229
pub unsafe fn $set_field() {
230230
_set($e);
231231
}
232-
}
232+
};
233233
}
234234

235235
macro_rules! clear_csr {
@@ -239,7 +239,7 @@ macro_rules! clear_csr {
239239
pub unsafe fn $clear_field() {
240240
_clear($e);
241241
}
242-
}
242+
};
243243
}
244244

245245
macro_rules! set_clear_csr {
@@ -270,3 +270,4 @@ macro_rules! read_composite_csr {
270270
}
271271
};
272272
}
273+

0 commit comments

Comments
 (0)