From 5729debb093769631077edc30a9c34f249f04f18 Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Fri, 20 May 2022 08:49:16 +0800 Subject: [PATCH] add cargo fmt in Makefile, and exec make fmt --- Makefile | 2 ++ os/src/boards/k210.rs | 1 - os/src/boards/qemu.rs | 1 - os/src/config.rs | 1 - os/src/drivers/block/mod.rs | 4 ++-- os/src/mm/memory_set.rs | 36 +++++++++++++----------------- user/src/bin/early_exit.rs | 7 +++--- user/src/bin/stackful_coroutine.rs | 35 +++++++++++++---------------- 8 files changed, 39 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 2e339762..a657cd92 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,5 @@ docker: build_docker: docker build -t ${DOCKER_NAME} . +fmt: + cd easy-fs; cargo fmt; cd ../easy-fs-fuse cargo fmt; cd ../os ; cargo fmt; cd ../user; cargo fmt; cd .. \ No newline at end of file diff --git a/os/src/boards/k210.rs b/os/src/boards/k210.rs index 4b2fd444..aa6d1ea6 100644 --- a/os/src/boards/k210.rs +++ b/os/src/boards/k210.rs @@ -20,4 +20,3 @@ pub const MMIO: &[(usize, usize)] = &[ ]; pub type BlockDeviceImpl = crate::drivers::block::SDCardWrapper; - diff --git a/os/src/boards/qemu.rs b/os/src/boards/qemu.rs index b3492526..b49ccc27 100644 --- a/os/src/boards/qemu.rs +++ b/os/src/boards/qemu.rs @@ -3,4 +3,3 @@ pub const CLOCK_FREQ: usize = 12500000; pub const MMIO: &[(usize, usize)] = &[(0x10001000, 0x1000)]; pub type BlockDeviceImpl = crate::drivers::block::VirtIOBlock; - diff --git a/os/src/config.rs b/os/src/config.rs index c1b2fa45..41fe977c 100644 --- a/os/src/config.rs +++ b/os/src/config.rs @@ -11,4 +11,3 @@ pub const TRAMPOLINE: usize = usize::MAX - PAGE_SIZE + 1; pub const TRAP_CONTEXT_BASE: usize = TRAMPOLINE - PAGE_SIZE; pub use crate::board::{CLOCK_FREQ, MMIO}; - diff --git a/os/src/drivers/block/mod.rs b/os/src/drivers/block/mod.rs index 7c1bb55d..7361ec83 100644 --- a/os/src/drivers/block/mod.rs +++ b/os/src/drivers/block/mod.rs @@ -1,13 +1,13 @@ mod sdcard; mod virtio_blk; -pub use virtio_blk::VirtIOBlock; pub use sdcard::SDCardWrapper; +pub use virtio_blk::VirtIOBlock; +use crate::board::BlockDeviceImpl; use alloc::sync::Arc; use easy_fs::BlockDevice; use lazy_static::*; -use crate::board::BlockDeviceImpl; lazy_static! { pub static ref BLOCK_DEVICE: Arc = Arc::new(BlockDeviceImpl::new()); diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 0d0b0f1d..aba1ae57 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -351,26 +351,20 @@ pub fn remap_test() { let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into(); let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into(); let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into(); - assert!( - !kernel_space - .page_table - .translate(mid_text.floor()) - .unwrap() - .writable(), - ); - assert!( - !kernel_space - .page_table - .translate(mid_rodata.floor()) - .unwrap() - .writable(), - ); - assert!( - !kernel_space - .page_table - .translate(mid_data.floor()) - .unwrap() - .executable(), - ); + assert!(!kernel_space + .page_table + .translate(mid_text.floor()) + .unwrap() + .writable(),); + assert!(!kernel_space + .page_table + .translate(mid_rodata.floor()) + .unwrap() + .writable(),); + assert!(!kernel_space + .page_table + .translate(mid_data.floor()) + .unwrap() + .executable(),); println!("remap_test passed!"); } diff --git a/user/src/bin/early_exit.rs b/user/src/bin/early_exit.rs index bf69e242..a81e55d3 100644 --- a/user/src/bin/early_exit.rs +++ b/user/src/bin/early_exit.rs @@ -5,11 +5,13 @@ extern crate user_lib; extern crate alloc; -use user_lib::{thread_create, exit}; use alloc::vec::Vec; +use user_lib::{exit, thread_create}; pub fn thread_a() -> ! { - for i in 0..1000 { print!("{}", i); } + for i in 0..1000 { + print!("{}", i); + } exit(1) } @@ -19,4 +21,3 @@ pub fn main() -> i32 { println!("main thread exited."); exit(0) } - diff --git a/user/src/bin/stackful_coroutine.rs b/user/src/bin/stackful_coroutine.rs index 3b0bf090..fd4a8d6d 100644 --- a/user/src/bin/stackful_coroutine.rs +++ b/user/src/bin/stackful_coroutine.rs @@ -3,7 +3,6 @@ // https://github.com/cfsamson/example-greenthreads #![no_std] #![no_main] - #![feature(naked_functions)] #![feature(asm)] @@ -17,10 +16,10 @@ use core::arch::asm; use alloc::vec; use alloc::vec::Vec; -use user_lib::{exit}; +use user_lib::exit; // In our simple example we set most constraints here. -const DEFAULT_STACK_SIZE: usize = 4096; //128 got SEGFAULT, 256(1024, 4096) got right results. +const DEFAULT_STACK_SIZE: usize = 4096; //128 got SEGFAULT, 256(1024, 4096) got right results. const MAX_TASKS: usize = 5; static mut RUNTIME: usize = 0; @@ -93,10 +92,7 @@ impl Runtime { let mut available_tasks: Vec = (1..MAX_TASKS).map(|i| Task::new(i)).collect(); tasks.append(&mut available_tasks); - Runtime { - tasks, - current: 0, - } + Runtime { tasks, current: 0 } } /// This is cheating a bit, but we need a pointer to our Runtime stored so we can call yield on it even if @@ -110,9 +106,9 @@ impl Runtime { /// This is where we start running our runtime. If it is our base task, we call yield until /// it returns false (which means that there are no tasks scheduled) and we are done. - pub fn run(&mut self){ - while self.t_yield() {} - println!("All tasks finished!"); + pub fn run(&mut self) { + while self.t_yield() {} + println!("All tasks finished!"); } /// This is our return function. The only place we use this is in our `guard` function. @@ -131,7 +127,7 @@ impl Runtime { /// If we find a task that's ready to be run we change the state of the current task from `Running` to `Ready`. /// Then we call switch which will save the current context (the old context) and load the new context /// into the CPU which then resumes based on the context it was just passed. - /// + /// /// NOITCE: if we comment below `#[inline(never)]`, we can not get the corrent running result #[inline(never)] fn t_yield(&mut self) -> bool { @@ -200,10 +196,9 @@ impl Runtime { // enough space to actually get an aligned pointer in the first place). let s_ptr = (s_ptr as usize & !7) as *mut u8; - available.ctx.x1 = guard as u64; //ctx.x1 is old return address - available.ctx.nx1 = f as u64; //ctx.nx2 is new return address + available.ctx.x1 = guard as u64; //ctx.x1 is old return address + available.ctx.nx1 = f as u64; //ctx.nx2 is new return address available.ctx.x2 = s_ptr.offset(-32) as u64; //cxt.x2 is sp - } available.state = State::Ready; } @@ -264,9 +259,10 @@ pub fn yield_task() { /// see: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html #[naked] #[no_mangle] -unsafe fn switch(old: *mut TaskContext, new: *const TaskContext) { +unsafe fn switch(old: *mut TaskContext, new: *const TaskContext) { // a0: _old, a1: _new - asm!(" + asm!( + " sd x1, 0x00(a0) sd x2, 0x08(a0) sd x8, 0x10(a0) @@ -300,12 +296,13 @@ unsafe fn switch(old: *mut TaskContext, new: *const TaskContext) { ld t0, 0x70(a1) jr t0 - ", options( noreturn) + ", + options(noreturn) ); } #[no_mangle] -pub fn main() { +pub fn main() { println!("stackful_coroutine begin..."); println!("TASK 0(Runtime) STARTING"); let mut runtime = Runtime::new(); @@ -349,4 +346,4 @@ pub fn main() { runtime.run(); println!("stackful_coroutine PASSED"); exit(0); -} \ No newline at end of file +} -- GitLab