add cargo fmt in Makefile, and exec make fmt

ch4
Yu Chen 3 years ago
parent 326b97a9fa
commit 7c785f8bbf

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

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

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

@ -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<UPSafeCell<MemorySet>> =
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!");
}

@ -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;

@ -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
}

@ -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

@ -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!");
}

@ -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::<u8>());
let _i = read_volatile(null_mut::<u8>());
}
0
}
}

@ -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::<u8>().write_volatile(1);
null_mut::<u8>().write_volatile(1);
}
0
}
}

Loading…
Cancel
Save