Skip to content

Commit b9151d0

Browse files
committed
refactor: replace asm! with llvm_asm! and fix some clippy issue
1 parent 0801975 commit b9151d0

File tree

19 files changed

+65
-61
lines changed

19 files changed

+65
-61
lines changed

os/src/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Context {
2020
#[naked]
2121
#[inline(never)]
2222
pub unsafe extern "C" fn switch(&mut self, target: &mut Context) {
23-
asm!(include_str!("process/switch.asm") :::: "volatile");
23+
llvm_asm!(include_str!("process/switch.asm") :::: "volatile");
2424
}
2525

2626
pub fn null() -> Context {
@@ -32,10 +32,10 @@ impl Context {
3232
}
3333

3434
pub unsafe fn append_initial_arguments(&self, args: [usize; 3]) {
35-
let contextContent = &mut *(self.content_addr as *mut ContextContent);
36-
contextContent.tf.x[10] = args[0];
37-
contextContent.tf.x[11] = args[1];
38-
contextContent.tf.x[12] = args[2];
35+
let context_content = &mut *(self.content_addr as *mut ContextContent);
36+
context_content.tf.x[10] = args[0];
37+
context_content.tf.x[11] = args[1];
38+
context_content.tf.x[12] = args[2];
3939
}
4040

4141
pub unsafe fn new_user_thread(
@@ -62,7 +62,7 @@ extern "C" {
6262

6363
impl ContextContent {
6464
fn new_kernel_thread(entry: usize, kstack_top: usize, satp: usize) -> ContextContent {
65-
let mut content = ContextContent {
65+
let content = ContextContent {
6666
ra: __trapret as usize,
6767
satp,
6868
s: [0; 12],

os/src/fs/file.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use crate::fs::ROOT_INODE;
12
use alloc::sync::Arc;
23
use rcore_fs::vfs::INode;
3-
use rcore_fs_sfs::INodeImpl;
4-
use crate::fs::ROOT_INODE;
54

6-
#[derive(Copy,Clone,Debug)]
5+
#[derive(Copy, Clone, Debug)]
76
pub enum FileDescriptorType {
87
FD_NONE,
98
FD_INODE,
@@ -29,14 +28,30 @@ impl File {
2928
offset: 0,
3029
}
3130
}
32-
pub fn set_readable(&mut self, v: bool) { self.readable = v; }
33-
pub fn set_writable(&mut self, v: bool) { self.writable = v; }
34-
pub fn get_readable(&self) -> bool { self.readable }
35-
pub fn get_writable(&self) -> bool { self.writable }
36-
pub fn set_fdtype(&mut self, t: FileDescriptorType) { self.fdtype = t; }
37-
pub fn get_fdtype(&self) -> FileDescriptorType { self.fdtype }
38-
pub fn set_offset(&mut self, o: usize) { self.offset = o; }
39-
pub fn get_offset(&self) -> usize { self.offset }
31+
pub fn set_readable(&mut self, v: bool) {
32+
self.readable = v;
33+
}
34+
pub fn set_writable(&mut self, v: bool) {
35+
self.writable = v;
36+
}
37+
pub fn get_readable(&self) -> bool {
38+
self.readable
39+
}
40+
pub fn get_writable(&self) -> bool {
41+
self.writable
42+
}
43+
pub fn set_fdtype(&mut self, t: FileDescriptorType) {
44+
self.fdtype = t;
45+
}
46+
pub fn get_fdtype(&self) -> FileDescriptorType {
47+
self.fdtype
48+
}
49+
pub fn set_offset(&mut self, o: usize) {
50+
self.offset = o;
51+
}
52+
pub fn get_offset(&self) -> usize {
53+
self.offset
54+
}
4055

4156
pub fn open_file(&mut self, path: &'static str, flags: i32) {
4257
self.set_fdtype(FileDescriptorType::FD_INODE);

os/src/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod device;
2-
pub mod stdio;
32
pub mod file;
3+
pub mod stdio;
44

55
use alloc::{sync::Arc, vec::Vec};
66
use lazy_static::*;
@@ -42,7 +42,7 @@ impl INodeExt for dyn INode {
4242
pub fn init() {
4343
println!("available programs in rust/ are:");
4444
let mut id = 0;
45-
let mut rust_dir = ROOT_INODE.lookup("rust").unwrap();
45+
let rust_dir = ROOT_INODE.lookup("rust").unwrap();
4646
while let Ok(name) = rust_dir.get_entry(id) {
4747
id += 1;
4848
println!(" {}", name);

os/src/fs/stdio.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::process;
21
use crate::sync::condvar::*;
32
use alloc::{collections::VecDeque, sync::Arc};
43
use lazy_static::*;

os/src/init.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ global_asm!(include_str!("boot/entry64.asm"));
22
global_asm!(include_str!("link_user.S"));
33

44
use crate::consts::*;
5-
use crate::memory::{alloc_frame, dealloc_frame};
65

76
#[no_mangle]
87
pub extern "C" fn rust_main() -> ! {

os/src/interrupt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::context::TrapFrame;
22
use crate::memory::access_pa_via_va;
33
use crate::process::tick;
4-
use crate::timer::{clock_set_next_event, TICKS};
4+
use crate::timer::clock_set_next_event;
55
use riscv::register::sie;
66
use riscv::register::{
7-
scause::{self, Exception, Interrupt, Trap},
8-
sepc, sscratch, sstatus, stvec,
7+
scause::{Exception, Interrupt, Trap},
8+
sscratch, sstatus, stvec,
99
};
1010

1111
global_asm!(include_str!("trap/trap.asm"));
@@ -89,7 +89,7 @@ fn external() {
8989
fn try_serial() -> bool {
9090
match super::io::getchar_option() {
9191
Some(ch) => {
92-
if (ch == '\r') {
92+
if ch == '\r' {
9393
crate::fs::stdio::STDIN.push('\n');
9494
} else {
9595
crate::fs::stdio::STDIN.push(ch);
@@ -104,21 +104,21 @@ fn try_serial() -> bool {
104104
pub fn disable_and_store() -> usize {
105105
let sstatus: usize;
106106
unsafe {
107-
asm!("csrci sstatus, 1 << 1" : "=r"(sstatus) ::: "volatile");
107+
llvm_asm!("csrci sstatus, 1 << 1" : "=r"(sstatus) ::: "volatile");
108108
}
109109
sstatus
110110
}
111111

112112
#[inline(always)]
113113
pub fn restore(flags: usize) {
114114
unsafe {
115-
asm!("csrs sstatus, $0" :: "r"(flags) :: "volatile");
115+
llvm_asm!("csrs sstatus, $0" :: "r"(flags) :: "volatile");
116116
}
117117
}
118118

119119
#[inline(always)]
120120
pub fn enable_and_wfi() {
121121
unsafe {
122-
asm!("csrsi sstatus, 1 << 1; wfi" :::: "volatile");
122+
llvm_asm!("csrsi sstatus, 1 << 1; wfi" :::: "volatile");
123123
}
124124
}

os/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![no_std]
2-
#![feature(asm)]
2+
#![feature(llvm_asm)]
33
#![feature(global_asm)]
44
#![feature(alloc_error_handler)]
55
#![feature(naked_functions)]

os/src/memory/frame_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ impl SegmentTreeAllocator {
1616
while self.m < self.n + 2 {
1717
self.m = self.m << 1;
1818
}
19-
for i in (1..(self.m << 1)) {
19+
for i in 1..(self.m << 1) {
2020
self.a[i] = 1;
2121
}
22-
for i in (1..self.n) {
22+
for i in 1..self.n {
2323
self.a[self.m + i] = 0;
2424
}
2525
for i in (1..self.m).rev() {

os/src/memory/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::consts::*;
66
use buddy_system_allocator::LockedHeap;
77
use frame_allocator::SEGMENT_TREE_ALLOCATOR as FRAME_ALLOCATOR;
88
use memory_set::{attr::MemoryAttr, handler::Linear, MemorySet};
9-
use riscv::addr::{Frame, Page, PhysAddr, VirtAddr};
9+
use riscv::addr::Frame;
1010
use riscv::register::sstatus;
1111

1212
pub fn init(l: usize, r: usize) {

os/src/memory/paging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl PageTableImpl {
135135
}
136136

137137
unsafe fn set_token(token: usize) {
138-
asm!("csrw satp, $0" :: "r"(token) :: "volatile");
138+
llvm_asm!("csrw satp, $0" :: "r"(token) :: "volatile");
139139
}
140140

141141
fn active_token() -> usize {

0 commit comments

Comments
 (0)