Skip to content

Commit 1551b08

Browse files
committed
Replace legacy asm! macro with llvm_asm!
From [RFC 2873](rust-lang/rfcs#2873): > The existing `asm!` macro will be renamed to `llvm_asm!` to provide an easy way to maintain backwards-compatibility with existing code using inline asm.
1 parent 117799b commit 1551b08

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

kernel/src/arch.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,42 +53,42 @@ pub fn intr_get() -> bool {
5353
#[allow(unused_assignments)]
5454
pub fn hart_id() -> usize {
5555
let mut hart_id: usize = 0;
56-
unsafe { asm!("mv $0, tp" : "=r"(hart_id) ::: "volatile"); }
56+
unsafe { llvm_asm!("mv $0, tp" : "=r"(hart_id) ::: "volatile"); }
5757
hart_id
5858
}
5959

6060
#[inline]
6161
#[allow(unused_assignments)]
6262
pub fn r_sip() -> usize {
6363
let mut sip: usize = 0;
64-
unsafe { asm!("csrr $0, sip" : "=r"(sip) ::: "volatile"); }
64+
unsafe { llvm_asm!("csrr $0, sip" : "=r"(sip) ::: "volatile"); }
6565
sip
6666
}
6767

6868
#[inline]
6969
pub fn w_sip(x: usize) {
70-
unsafe { asm!("csrw sip, $0" :: "r"(x) :: "volatile"); }
70+
unsafe { llvm_asm!("csrw sip, $0" :: "r"(x) :: "volatile"); }
7171
}
7272

7373
#[inline]
7474
#[allow(unused_assignments)]
7575
pub fn r_sstatus() -> usize {
7676
let mut x: usize = 0;
77-
unsafe { asm!("csrr $0, sstatus" : "=r"(x) ::: "volatile"); }
77+
unsafe { llvm_asm!("csrr $0, sstatus" : "=r"(x) ::: "volatile"); }
7878
x
7979
}
8080

8181
#[inline]
8282
#[allow(unused_assignments)]
8383
pub fn r_satp() -> usize {
8484
let mut x: usize = 0;
85-
unsafe { asm!("csrr $0, satp" : "=r"(x) ::: "volatile"); }
85+
unsafe { llvm_asm!("csrr $0, satp" : "=r"(x) ::: "volatile"); }
8686
x
8787
}
8888

8989
#[inline]
9090
pub fn w_sstatus(x: usize) {
91-
unsafe { asm!("csrw sstatus, $0" :: "r"(x) :: "volatile"); }
91+
unsafe { llvm_asm!("csrw sstatus, $0" :: "r"(x) :: "volatile"); }
9292
}
9393

9494
#[inline(always)]
@@ -99,24 +99,24 @@ pub fn __sync_synchronize() {
9999

100100
#[inline(always)]
101101
pub fn __sync_lock_test_and_set(a: &u32, mut b: u32) -> u32 {
102-
unsafe { asm!("amoswap.w.aq $0, $1, ($2)" :"=r"(b): "r"(b), "r"(a) :: "volatile"); }
102+
unsafe { llvm_asm!("amoswap.w.aq $0, $1, ($2)" :"=r"(b): "r"(b), "r"(a) :: "volatile"); }
103103
b
104104
}
105105

106106
#[inline(always)]
107107
pub fn __sync_lock_release(a: &u32) {
108-
unsafe { asm!("amoswap.w zero, zero, ($0)" :: "r"(a) :: "volatile"); }
108+
unsafe { llvm_asm!("amoswap.w zero, zero, ($0)" :: "r"(a) :: "volatile"); }
109109
}
110110

111111
#[inline(always)]
112112
pub unsafe fn w_ra(x: usize) {
113-
asm!("mv ra, $0" :: "r"(x) :: "volatile");
113+
llvm_asm!("mv ra, $0" :: "r"(x) :: "volatile");
114114
}
115115

116116

117117
pub fn sp() -> usize {
118118
let mut sp: usize = 0;
119-
unsafe { asm!("mv $0, sp" : "=r"(sp) ::: "volatile"); }
119+
unsafe { llvm_asm!("mv $0, sp" : "=r"(sp) ::: "volatile"); }
120120
sp
121121
}
122122

kernel/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(alloc_error_handler)]
1515
#![feature(box_syntax)]
1616
#![feature(alloc_prelude)]
17+
#![feature(llvm_asm)]
1718
#![allow(dead_code)]
1819
#![allow(unused_imports)]
1920

kernel/src/mem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn hartinit() {
196196
let root_ppn = &KERNEL_PGTABLE as *const Table as usize;
197197
let satp_val = arch::build_satp(8, 0, root_ppn);
198198
unsafe {
199-
asm!("csrw satp, $0" :: "r"(satp_val));
199+
llvm_asm!("csrw satp, $0" :: "r"(satp_val));
200200
asm::sfence_vma(0, 0);
201201
}
202202
}
@@ -261,4 +261,4 @@ pub fn debug() {
261261

262262
pub fn alloc_stack() -> *mut u8 {
263263
ALLOC().lock().allocate(PAGE_SIZE * 1024)
264-
}
264+
}

0 commit comments

Comments
 (0)