From 07fc98b7c97dcb8f5affa83524a01621c6b15eb3 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Sun, 18 Jul 2021 19:21:16 +0800 Subject: [PATCH] Replace llvm_asm! with asm --- os/src/main.rs | 2 +- os/src/mm/memory_set.rs | 2 +- os/src/sbi.rs | 11 ++++++----- os/src/trap/mod.rs | 11 ++++++++--- user/src/lib.rs | 2 +- user/src/syscall.rs | 11 ++++++----- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/os/src/main.rs b/os/src/main.rs index 7879fc4e..14eb9542 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] #![feature(global_asm)] -#![feature(llvm_asm)] +#![feature(asm)] #![feature(panic_info_message)] #![feature(alloc_error_handler)] diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 079d6dba..f2311509 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -182,7 +182,7 @@ impl MemorySet { let satp = self.page_table.token(); unsafe { satp::write(satp); - llvm_asm!("sfence.vma" :::: "volatile"); + asm!("sfence.vma"); } } pub fn translate(&self, vpn: VirtPageNum) -> Option { diff --git a/os/src/sbi.rs b/os/src/sbi.rs index 36e15fcc..276c199d 100644 --- a/os/src/sbi.rs +++ b/os/src/sbi.rs @@ -14,11 +14,12 @@ const SBI_SHUTDOWN: usize = 8; fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize { let mut ret; unsafe { - llvm_asm!("ecall" - : "={x10}" (ret) - : "{x10}" (arg0), "{x11}" (arg1), "{x12}" (arg2), "{x17}" (which) - : "memory" - : "volatile" + asm!( + "ecall", + inlateout("x10") arg0 => ret, + in("x11") arg1, + in("x12") arg2, + in("x17") which, ); } ret diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 674181aa..e6baba52 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -86,10 +86,15 @@ pub fn trap_return() -> ! { } let restore_va = __restore as usize - __alltraps as usize + TRAMPOLINE; unsafe { - llvm_asm!("fence.i" :::: "volatile"); - llvm_asm!("jr $0" :: "r"(restore_va), "{a0}"(trap_cx_ptr), "{a1}"(user_satp) :: "volatile"); + asm!( + "fence.i", + "jr {restore_va}", + restore_va = in(reg) restore_va, + in("a0") trap_cx_ptr, + in("a1") user_satp, + options(noreturn) + ); } - panic!("Unreachable in back_to_user!"); } #[no_mangle] diff --git a/user/src/lib.rs b/user/src/lib.rs index 122aefcf..1fae0fd2 100644 --- a/user/src/lib.rs +++ b/user/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(llvm_asm)] +#![feature(asm)] #![feature(linkage)] #![feature(panic_info_message)] diff --git a/user/src/syscall.rs b/user/src/syscall.rs index 1b23a48a..ed3d16aa 100644 --- a/user/src/syscall.rs +++ b/user/src/syscall.rs @@ -6,11 +6,12 @@ const SYSCALL_GET_TIME: usize = 169; fn syscall(id: usize, args: [usize; 3]) -> isize { let mut ret: isize; unsafe { - llvm_asm!("ecall" - : "={x10}" (ret) - : "{x10}" (args[0]), "{x11}" (args[1]), "{x12}" (args[2]), "{x17}" (id) - : "memory" - : "volatile" + asm!( + "ecall", + inlateout("x10") args[0] => ret, + in("x11") args[1], + in("x12") args[2], + in("x17") id ); } ret