add cargo fmt in Makefile, and exec make fmt

This commit is contained in:
Yu Chen 2022-05-20 08:55:07 +08:00
parent e87bb122a8
commit ab99bc8c28
10 changed files with 36 additions and 40 deletions

View file

@ -6,3 +6,5 @@ docker:
build_docker: build_docker:
docker build -t ${DOCKER_NAME} . docker build -t ${DOCKER_NAME} .
fmt:
cd os ; cargo fmt; cd ../user; cargo fmt; cd ..

View file

@ -1,2 +1 @@
pub const CLOCK_FREQ: usize = 403000000 / 62; pub const CLOCK_FREQ: usize = 403000000 / 62;

View file

@ -1,4 +1,4 @@
//! Implementation of [`FrameAllocator`] which //! Implementation of [`FrameAllocator`] which
//! controls all the frames in the operating system. //! controls all the frames in the operating system.
use super::{PhysAddr, PhysPageNum}; use super::{PhysAddr, PhysPageNum};

View file

@ -27,7 +27,7 @@ extern "C" {
} }
lazy_static! { 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<UPSafeCell<MemorySet>> = pub static ref KERNEL_SPACE: Arc<UPSafeCell<MemorySet>> =
Arc::new(unsafe { UPSafeCell::new(MemorySet::new_kernel()) }); 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_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
let mid_rodata: VirtAddr = ((srodata as usize + erodata 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(); let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
assert!( assert!(!kernel_space
!kernel_space .page_table
.page_table .translate(mid_text.floor())
.translate(mid_text.floor()) .unwrap()
.unwrap() .writable(),);
.writable(), assert!(!kernel_space
); .page_table
assert!( .translate(mid_rodata.floor())
!kernel_space .unwrap()
.page_table .writable(),);
.translate(mid_rodata.floor()) assert!(!kernel_space
.unwrap() .page_table
.writable(), .translate(mid_data.floor())
); .unwrap()
assert!( .executable(),);
!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),
);
println!("remap_test passed!"); println!("remap_test passed!");
} }

View file

@ -1,12 +1,11 @@
//! Memory management implementation //! Memory management implementation
//! //!
//! SV39 page-based virtual-memory architecture for RV64 systems, and //! SV39 page-based virtual-memory architecture for RV64 systems, and
//! everything about memory management, like frame allocator, page table, //! everything about memory management, like frame allocator, page table,
//! map area and memory set, is implemented here. //! map area and memory set, is implemented here.
//! //!
//! Every task or process has a memory_set to control its virtual memory. //! Every task or process has a memory_set to control its virtual memory.
mod address; mod address;
mod frame_allocator; mod frame_allocator;
mod heap_allocator; mod heap_allocator;

View file

@ -16,7 +16,7 @@ pub fn sys_yield() -> isize {
0 0
} }
/// get current time /// get current time
pub fn sys_get_time() -> isize { pub fn sys_get_time() -> isize {
get_time_ms() as isize get_time_ms() as isize
} }

View file

@ -37,10 +37,10 @@ impl TrapContext {
let mut cx = Self { let mut cx = Self {
x: [0; 32], x: [0; 32],
sstatus, sstatus,
sepc: entry, // entry point of app sepc: entry, // entry point of app
kernel_satp, // addr of page table kernel_satp, // addr of page table
kernel_sp, // kernel stack kernel_sp, // kernel stack
trap_handler,// addr of trap_handler function trap_handler, // addr of trap_handler function
}; };
cx.set_sp(sp); // app's user stack pointer cx.set_sp(sp); // app's user stack pointer
cx // return initial Trap Context of app cx // return initial Trap Context of app

View file

@ -64,8 +64,10 @@ pub fn trap_handler() -> ! {
cx.sepc += 4; cx.sepc += 4;
cx.x[10] = syscall(cx.x[17], [cx.x[10], cx.x[11], cx.x[12]]) as usize; 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::StoreFault)
Trap::Exception(Exception::LoadFault) | Trap::Exception(Exception::LoadPageFault) => { | 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); println!("[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.", stval, cx.sepc);
exit_current_and_run_next(); exit_current_and_run_next();
} }
@ -115,7 +117,7 @@ pub fn trap_return() -> ! {
#[no_mangle] #[no_mangle]
/// Unimplement: traps/interrupts/exceptions from kernel mode /// Unimplement: traps/interrupts/exceptions from kernel mode
/// Todo: Chapter 9: I/O device /// Todo: Chapter 9: I/O device
pub fn trap_from_kernel() -> ! { pub fn trap_from_kernel() -> ! {
panic!("a trap from kernel!"); panic!("a trap from kernel!");
} }

View file

@ -4,7 +4,7 @@
#[macro_use] #[macro_use]
extern crate user_lib; extern crate user_lib;
use core::ptr::{read_volatile,null_mut}; use core::ptr::{null_mut, read_volatile};
#[no_mangle] #[no_mangle]
fn main() -> i32 { fn main() -> i32 {
@ -12,7 +12,7 @@ fn main() -> i32 {
println!("Into Test load_fault, we will insert an invalid load operation..."); println!("Into Test load_fault, we will insert an invalid load operation...");
println!("Kernel should kill this application!"); println!("Kernel should kill this application!");
unsafe { unsafe {
let _i=read_volatile(null_mut::<u8>()); let _i = read_volatile(null_mut::<u8>());
} }
0 0
} }

View file

@ -12,7 +12,7 @@ fn main() -> i32 {
println!("Into Test store_fault, we will insert an invalid store operation..."); println!("Into Test store_fault, we will insert an invalid store operation...");
println!("Kernel should kill this application!"); println!("Kernel should kill this application!");
unsafe { unsafe {
null_mut::<u8>().write_volatile(1); null_mut::<u8>().write_volatile(1);
} }
0 0
} }