Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace legacy asm! macro with llvm_asm! #10

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}