Skip to content

Commit

Permalink
Merge pull request #10 from onehr/master
Browse files Browse the repository at this point in the history
Replace legacy `asm!` macro with `llvm_asm!`
  • Loading branch information
skyzh authored Jul 10, 2020
2 parents 117799b + 1551b08 commit 97653ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
20 changes: 10 additions & 10 deletions kernel/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,42 @@ pub fn intr_get() -> bool {
#[allow(unused_assignments)]
pub fn hart_id() -> usize {
let mut hart_id: usize = 0;
unsafe { asm!("mv $0, tp" : "=r"(hart_id) ::: "volatile"); }
unsafe { llvm_asm!("mv $0, tp" : "=r"(hart_id) ::: "volatile"); }
hart_id
}

#[inline]
#[allow(unused_assignments)]
pub fn r_sip() -> usize {
let mut sip: usize = 0;
unsafe { asm!("csrr $0, sip" : "=r"(sip) ::: "volatile"); }
unsafe { llvm_asm!("csrr $0, sip" : "=r"(sip) ::: "volatile"); }
sip
}

#[inline]
pub fn w_sip(x: usize) {
unsafe { asm!("csrw sip, $0" :: "r"(x) :: "volatile"); }
unsafe { llvm_asm!("csrw sip, $0" :: "r"(x) :: "volatile"); }
}

#[inline]
#[allow(unused_assignments)]
pub fn r_sstatus() -> usize {
let mut x: usize = 0;
unsafe { asm!("csrr $0, sstatus" : "=r"(x) ::: "volatile"); }
unsafe { llvm_asm!("csrr $0, sstatus" : "=r"(x) ::: "volatile"); }
x
}

#[inline]
#[allow(unused_assignments)]
pub fn r_satp() -> usize {
let mut x: usize = 0;
unsafe { asm!("csrr $0, satp" : "=r"(x) ::: "volatile"); }
unsafe { llvm_asm!("csrr $0, satp" : "=r"(x) ::: "volatile"); }
x
}

#[inline]
pub fn w_sstatus(x: usize) {
unsafe { asm!("csrw sstatus, $0" :: "r"(x) :: "volatile"); }
unsafe { llvm_asm!("csrw sstatus, $0" :: "r"(x) :: "volatile"); }
}

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

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

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

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


pub fn sp() -> usize {
let mut sp: usize = 0;
unsafe { asm!("mv $0, sp" : "=r"(sp) ::: "volatile"); }
unsafe { llvm_asm!("mv $0, sp" : "=r"(sp) ::: "volatile"); }
sp
}

Expand Down
1 change: 1 addition & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(alloc_error_handler)]
#![feature(box_syntax)]
#![feature(alloc_prelude)]
#![feature(llvm_asm)]
#![allow(dead_code)]
#![allow(unused_imports)]

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn hartinit() {
let root_ppn = &KERNEL_PGTABLE as *const Table as usize;
let satp_val = arch::build_satp(8, 0, root_ppn);
unsafe {
asm!("csrw satp, $0" :: "r"(satp_val));
llvm_asm!("csrw satp, $0" :: "r"(satp_val));
asm::sfence_vma(0, 0);
}
}
Expand Down Expand Up @@ -261,4 +261,4 @@ pub fn debug() {

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

0 comments on commit 97653ed

Please sign in to comment.