From 7c785f8bbf71ca9470faf2b3d15f1e24d74b0981 Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Fri, 20 May 2022 08:55:07 +0800 Subject: [PATCH] add cargo fmt in Makefile, and exec make fmt --- Makefile | 2 ++ os/src/boards/k210.rs | 1 - os/src/mm/frame_allocator.rs | 2 +- os/src/mm/memory_set.rs | 38 +++++++++++++++-------------------- os/src/mm/mod.rs | 5 ++--- os/src/syscall/process.rs | 2 +- os/src/trap/context.rs | 8 ++++---- os/src/trap/mod.rs | 8 +++++--- user/src/bin/04load_fault.rs | 6 +++--- user/src/bin/05store_fault.rs | 4 ++-- 10 files changed, 36 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 2e339762..c67d48a1 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,5 @@ docker: build_docker: docker build -t ${DOCKER_NAME} . +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 cb97f76f..4fea2d11 100644 --- a/os/src/boards/k210.rs +++ b/os/src/boards/k210.rs @@ -1,2 +1 @@ pub const CLOCK_FREQ: usize = 403000000 / 62; - diff --git a/os/src/mm/frame_allocator.rs b/os/src/mm/frame_allocator.rs index d4320da0..7818ba83 100644 --- a/os/src/mm/frame_allocator.rs +++ b/os/src/mm/frame_allocator.rs @@ -1,4 +1,4 @@ -//! Implementation of [`FrameAllocator`] which +//! Implementation of [`FrameAllocator`] which //! controls all the frames in the operating system. use super::{PhysAddr, PhysPageNum}; diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 32c91ed3..e8de984a 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -27,7 +27,7 @@ extern "C" { } lazy_static! { - /// a memory set instance through lazy_static! managing kernel space + /// a memory set instance through lazy_static! managing kernel space pub static ref KERNEL_SPACE: Arc> = Arc::new(unsafe { UPSafeCell::new(MemorySet::new_kernel()) }); } @@ -324,26 +324,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/os/src/mm/mod.rs b/os/src/mm/mod.rs index cafdbac0..e0fd13c7 100644 --- a/os/src/mm/mod.rs +++ b/os/src/mm/mod.rs @@ -1,12 +1,11 @@ //! Memory management implementation -//! +//! //! SV39 page-based virtual-memory architecture for RV64 systems, and //! everything about memory management, like frame allocator, page table, //! map area and memory set, is implemented here. -//! +//! //! Every task or process has a memory_set to control its virtual memory. - mod address; mod frame_allocator; mod heap_allocator; diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index e5b4ad42..ec469bdf 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -16,7 +16,7 @@ pub fn sys_yield() -> isize { 0 } -/// get current time +/// get current time pub fn sys_get_time() -> isize { get_time_ms() as isize } diff --git a/os/src/trap/context.rs b/os/src/trap/context.rs index 527d1b61..dc8b78df 100644 --- a/os/src/trap/context.rs +++ b/os/src/trap/context.rs @@ -37,10 +37,10 @@ impl TrapContext { let mut cx = Self { x: [0; 32], sstatus, - sepc: entry, // entry point of app - kernel_satp, // addr of page table - kernel_sp, // kernel stack - trap_handler,// addr of trap_handler function + sepc: entry, // entry point of app + kernel_satp, // addr of page table + kernel_sp, // kernel stack + trap_handler, // addr of trap_handler function }; cx.set_sp(sp); // app's user stack pointer cx // return initial Trap Context of app diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 14fb76b2..4a11dc0e 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -64,8 +64,10 @@ pub fn trap_handler() -> ! { cx.sepc += 4; cx.x[10] = syscall(cx.x[17], [cx.x[10], cx.x[11], cx.x[12]]) as usize; } - Trap::Exception(Exception::StoreFault) | Trap::Exception(Exception::StorePageFault) | - Trap::Exception(Exception::LoadFault) | Trap::Exception(Exception::LoadPageFault) => { + Trap::Exception(Exception::StoreFault) + | Trap::Exception(Exception::StorePageFault) + | Trap::Exception(Exception::LoadFault) + | Trap::Exception(Exception::LoadPageFault) => { println!("[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.", stval, cx.sepc); exit_current_and_run_next(); } @@ -115,7 +117,7 @@ pub fn trap_return() -> ! { #[no_mangle] /// Unimplement: traps/interrupts/exceptions from kernel mode -/// Todo: Chapter 9: I/O device +/// Todo: Chapter 9: I/O device pub fn trap_from_kernel() -> ! { panic!("a trap from kernel!"); } diff --git a/user/src/bin/04load_fault.rs b/user/src/bin/04load_fault.rs index 87b2fad2..2927e850 100644 --- a/user/src/bin/04load_fault.rs +++ b/user/src/bin/04load_fault.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -use core::ptr::{read_volatile,null_mut}; +use core::ptr::{null_mut, read_volatile}; #[no_mangle] fn main() -> i32 { @@ -12,7 +12,7 @@ fn main() -> i32 { println!("Into Test load_fault, we will insert an invalid load operation..."); println!("Kernel should kill this application!"); unsafe { - let _i=read_volatile(null_mut::()); + let _i = read_volatile(null_mut::()); } 0 -} \ No newline at end of file +} diff --git a/user/src/bin/05store_fault.rs b/user/src/bin/05store_fault.rs index d94f337c..0c86200b 100644 --- a/user/src/bin/05store_fault.rs +++ b/user/src/bin/05store_fault.rs @@ -12,7 +12,7 @@ fn main() -> i32 { println!("Into Test store_fault, we will insert an invalid store operation..."); println!("Kernel should kill this application!"); unsafe { - null_mut::().write_volatile(1); + null_mut::().write_volatile(1); } 0 -} \ No newline at end of file +}