mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 01:16:26 +04:00
add cargo fmt in Makefile, and exec make fmt
This commit is contained in:
parent
daf439cff4
commit
3aa7fac88a
2
Makefile
2
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 ..
|
@ -3,4 +3,3 @@ pub const CLOCK_FREQ: usize = 12500000;
|
||||
pub const MMIO: &[(usize, usize)] = &[(0x10001000, 0x1000)];
|
||||
|
||||
pub type BlockDeviceImpl = crate::drivers::block::VirtIOBlock;
|
||||
|
||||
|
@ -12,4 +12,3 @@ pub const TRAMPOLINE: usize = usize::MAX - PAGE_SIZE + 1;
|
||||
pub const TRAP_CONTEXT: usize = TRAMPOLINE - PAGE_SIZE;
|
||||
|
||||
pub use crate::board::{CLOCK_FREQ, MMIO};
|
||||
|
||||
|
@ -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<dyn BlockDevice> = Arc::new(BlockDeviceImpl::new());
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! `Arc<Inode>` -> `OSInodeInner`: In order to open files concurrently
|
||||
//! we need to wrap `Inode` into `Arc`,but `Mutex` in `Inode` prevents
|
||||
//! file systems from being accessed simultaneously
|
||||
//!
|
||||
//! `UPSafeCell<OSInodeInner>` -> `OSInode`: for static `ROOT_INODE`,we
|
||||
//! `Arc<Inode>` -> `OSInodeInner`: In order to open files concurrently
|
||||
//! we need to wrap `Inode` into `Arc`,but `Mutex` in `Inode` prevents
|
||||
//! file systems from being accessed simultaneously
|
||||
//!
|
||||
//! `UPSafeCell<OSInodeInner>` -> `OSInode`: for static `ROOT_INODE`,we
|
||||
//! need to wrap `OSInodeInner` into `UPSafeCell`
|
||||
use super::File;
|
||||
use crate::drivers::BLOCK_DEVICE;
|
||||
@ -14,7 +14,7 @@ use bitflags::*;
|
||||
use easy_fs::{EasyFileSystem, Inode};
|
||||
use lazy_static::*;
|
||||
/// A wrapper around a filesystem inode
|
||||
/// to implement File trait atop
|
||||
/// to implement File trait atop
|
||||
pub struct OSInode {
|
||||
readable: bool,
|
||||
writable: bool,
|
||||
@ -67,7 +67,7 @@ pub fn list_apps() {
|
||||
println!("**************/");
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
bitflags! {
|
||||
///Open file flags
|
||||
pub struct OpenFlags: u32 {
|
||||
///Read only
|
||||
|
@ -3,7 +3,7 @@ mod inode;
|
||||
mod stdio;
|
||||
|
||||
use crate::mm::UserBuffer;
|
||||
/// File trait
|
||||
/// File trait
|
||||
pub trait File: Send + Sync {
|
||||
/// If readable
|
||||
fn readable(&self) -> bool;
|
||||
|
@ -9,7 +9,7 @@
|
||||
//! - [`mm`]: Address map using SV39
|
||||
//! - [`sync`]: Wrap a static data structure inside it so that we are able to access it without any `unsafe`.
|
||||
//! - [`fs`]: Separate user from file system with some structures
|
||||
//!
|
||||
//!
|
||||
//! The operating system also starts in this module. Kernel code starts
|
||||
//! executing from `entry.asm`, after which [`rust_main()`] is called to
|
||||
//! initialize various pieces of functionality. (See its source code for
|
||||
|
@ -109,11 +109,11 @@ impl VirtAddr {
|
||||
pub fn ceil(&self) -> VirtPageNum {
|
||||
VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
|
||||
}
|
||||
///Get page offset
|
||||
///Get page offset
|
||||
pub fn page_offset(&self) -> usize {
|
||||
self.0 & (PAGE_SIZE - 1)
|
||||
}
|
||||
///Check page aligned
|
||||
///Check page aligned
|
||||
pub fn aligned(&self) -> bool {
|
||||
self.page_offset() == 0
|
||||
}
|
||||
@ -138,11 +138,11 @@ impl PhysAddr {
|
||||
pub fn ceil(&self) -> PhysPageNum {
|
||||
PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
|
||||
}
|
||||
///Get page offset
|
||||
///Get page offset
|
||||
pub fn page_offset(&self) -> usize {
|
||||
self.0 & (PAGE_SIZE - 1)
|
||||
}
|
||||
///Check page aligned
|
||||
///Check page aligned
|
||||
pub fn aligned(&self) -> bool {
|
||||
self.page_offset() == 0
|
||||
}
|
||||
@ -160,7 +160,7 @@ impl From<PhysPageNum> for PhysAddr {
|
||||
}
|
||||
|
||||
impl VirtPageNum {
|
||||
///Return VPN 3 level index
|
||||
///Return VPN 3 level index
|
||||
pub fn indexes(&self) -> [usize; 3] {
|
||||
let mut vpn = self.0;
|
||||
let mut idx = [0usize; 3];
|
||||
@ -173,11 +173,11 @@ impl VirtPageNum {
|
||||
}
|
||||
|
||||
impl PhysAddr {
|
||||
///Get reference to `PhysAddr` value
|
||||
///Get reference to `PhysAddr` value
|
||||
pub fn get_ref<T>(&self) -> &'static T {
|
||||
unsafe { (self.0 as *const T).as_ref().unwrap() }
|
||||
}
|
||||
///Get mutable reference to `PhysAddr` value
|
||||
///Get mutable reference to `PhysAddr` value
|
||||
pub fn get_mut<T>(&self) -> &'static mut T {
|
||||
unsafe { (self.0 as *mut T).as_mut().unwrap() }
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Implementation of [`FrameAllocator`] which
|
||||
//! Implementation of [`FrameAllocator`] which
|
||||
//! controls all the frames in the operating system.
|
||||
use super::{PhysAddr, PhysPageNum};
|
||||
use crate::config::MEMORY_END;
|
||||
|
@ -389,26 +389,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,9 +1,9 @@
|
||||
//! 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;
|
||||
|
@ -37,7 +37,7 @@ impl PageTableEntry {
|
||||
pub fn empty() -> Self {
|
||||
PageTableEntry { bits: 0 }
|
||||
}
|
||||
///Return 44bit ppn
|
||||
///Return 44bit ppn
|
||||
pub fn ppn(&self) -> PhysPageNum {
|
||||
(self.bits >> 10 & ((1usize << 44) - 1)).into()
|
||||
}
|
||||
@ -150,13 +150,13 @@ impl PageTable {
|
||||
(aligned_pa_usize + offset).into()
|
||||
})
|
||||
}
|
||||
/// Get root ppn
|
||||
/// Get root ppn
|
||||
pub fn token(&self) -> usize {
|
||||
8usize << 60 | self.root_ppn.0
|
||||
}
|
||||
}
|
||||
/// Translate a pointer to a mutable u8 Vec through page table
|
||||
pub fn translated_byte_buffer(token: usize, ptr: *const u8, len: usize) -> Vec<&'static mut [u8]> {
|
||||
/// Translate a pointer to a mutable u8 Vec through page table
|
||||
pub fn translated_byte_buffer(token: usize, ptr: *const u8, len: usize) -> Vec<&'static mut [u8]> {
|
||||
let page_table = PageTable::from_token(token);
|
||||
let mut start = ptr as usize;
|
||||
let end = start + len;
|
||||
|
@ -5,13 +5,13 @@
|
||||
//!
|
||||
//! A single global instance of [`TaskManager`] called `TASK_MANAGER` controls
|
||||
//! all the tasks in the whole operating system.
|
||||
//!
|
||||
//! A single global instance of [`Processor`] called `PROCESSOR` monitors running
|
||||
//! task(s) for each core.
|
||||
//!
|
||||
//! A single global instance of [`PidAllocator`] called `PID_ALLOCATOR` allocates
|
||||
//!
|
||||
//! A single global instance of [`Processor`] called `PROCESSOR` monitors running
|
||||
//! task(s) for each core.
|
||||
//!
|
||||
//! A single global instance of [`PidAllocator`] called `PID_ALLOCATOR` allocates
|
||||
//! pid for user apps.
|
||||
//!
|
||||
//!
|
||||
//! Be careful when you see `__switch` ASM function in `switch.S`. Control flow around this function
|
||||
//! might not be what you expect.
|
||||
mod context;
|
||||
@ -27,14 +27,15 @@ use crate::fs::{open_file, OpenFlags};
|
||||
use alloc::sync::Arc;
|
||||
pub use context::TaskContext;
|
||||
use lazy_static::*;
|
||||
pub use manager::{fetch_task,TaskManager};
|
||||
pub use manager::{fetch_task, TaskManager};
|
||||
use switch::__switch;
|
||||
use task::{TaskControlBlock, TaskStatus};
|
||||
|
||||
pub use manager::add_task;
|
||||
pub use pid::{pid_alloc, KernelStack, PidHandle,PidAllocator};
|
||||
pub use pid::{pid_alloc, KernelStack, PidAllocator, PidHandle};
|
||||
pub use processor::{
|
||||
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,Processor
|
||||
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,
|
||||
Processor,
|
||||
};
|
||||
/// Suspend the current 'Running' task and run the next task in task list.
|
||||
pub fn suspend_current_and_run_next() {
|
||||
@ -89,7 +90,7 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
///Globle process that init user shell
|
||||
///Globle process that init user shell
|
||||
pub static ref INITPROC: Arc<TaskControlBlock> = Arc::new({
|
||||
let inode = open_file("initproc", OpenFlags::RDONLY).unwrap();
|
||||
let v = inode.read_all();
|
||||
|
@ -63,7 +63,7 @@ pub fn kernel_stack_position(app_id: usize) -> (usize, usize) {
|
||||
let bottom = top - KERNEL_STACK_SIZE;
|
||||
(bottom, top)
|
||||
}
|
||||
///Kernelstack for app
|
||||
///Kernelstack for app
|
||||
pub struct KernelStack {
|
||||
pid: usize,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//!Implementation of [`TaskControlBlock`]
|
||||
//!Implementation of [`TaskControlBlock`]
|
||||
use super::TaskContext;
|
||||
use super::{pid_alloc, KernelStack, PidHandle};
|
||||
use crate::config::TRAP_CONTEXT;
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
//! RISC-V timer-related functionality
|
||||
|
||||
use crate::config::CLOCK_FREQ;
|
||||
|
@ -106,7 +106,7 @@ pub fn trap_handler() -> ! {
|
||||
#[no_mangle]
|
||||
/// set the new addr of __restore asm function in TRAMPOLINE page,
|
||||
/// set the reg a0 = trap_cx_ptr, reg a1 = phy addr of usr page table,
|
||||
/// finally, jump to new addr of __restore asm function
|
||||
/// finally, jump to new addr of __restore asm function
|
||||
pub fn trap_return() -> ! {
|
||||
set_user_trap_entry();
|
||||
let trap_cx_ptr = TRAP_CONTEXT;
|
||||
@ -130,7 +130,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() -> ! {
|
||||
use riscv::register::sepc;
|
||||
println!("stval = {:#x}, sepc = {:#x}", stval::read(), sepc::read());
|
||||
|
Loading…
Reference in New Issue
Block a user