From e4300d3515978ca288145afb88b006102ee17519 Mon Sep 17 00:00:00 2001 From: lcy1996 <992195697@qq.com> Date: Fri, 5 Oct 2018 10:58:15 +0800 Subject: [PATCH 1/2] Add more comment in kernel but not finished --- kernel/src/arch/riscv32/context.rs | 1 + kernel/src/fs.rs | 2 ++ kernel/src/lib.rs | 16 ++++++++++------ kernel/src/process/mod.rs | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/kernel/src/arch/riscv32/context.rs b/kernel/src/arch/riscv32/context.rs index 4a00cfa..0a6037d 100644 --- a/kernel/src/arch/riscv32/context.rs +++ b/kernel/src/arch/riscv32/context.rs @@ -11,6 +11,7 @@ pub struct TrapFrame { } /// 用于在内核栈中构造新线程的中断帧 +/// The trapframe for building new process in kernel impl TrapFrame { fn new_kernel_thread(entry: extern fn(usize) -> !, arg: usize, sp: usize) -> Self { use core::mem::zeroed; diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index fe20c6c..748cc12 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -15,6 +15,7 @@ _binary_user_riscv_img_end: "#); pub fn shell() { + // load riscv32/x86_64 user program #[cfg(target_arch = "riscv32")] let device = { extern { @@ -36,6 +37,7 @@ pub fn shell() { const BUF_SIZE: usize = 0x40000; let layout = Layout::from_size_align(BUF_SIZE, 0x1000).unwrap(); let buf = unsafe{ slice::from_raw_parts_mut(alloc(layout), BUF_SIZE) }; + // start interaction loop { print!(">> "); use console::get_line; diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 4a23294..28ef150 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -61,16 +61,20 @@ pub mod arch; pub mod arch; pub fn kmain() -> ! { + // Init the first kernel process(idle proc) process::init(); + // enable the interrupt unsafe { arch::interrupt::enable(); } - fs::shell(); + // the test is not supported in riscv32(maybe) + //thread::test::local_key(); + //thread::test::unpack(); + //sync::test::philosopher_using_mutex(); + //sync::test::philosopher_using_monitor(); + //sync::mpsc::test::test_all(); -// thread::test::local_key(); -// thread::test::unpack(); -// sync::test::philosopher_using_mutex(); -// sync::test::philosopher_using_monitor(); -// sync::mpsc::test::test_all(); + // come into shell + fs::shell(); loop {} } diff --git a/kernel/src/process/mod.rs b/kernel/src/process/mod.rs index 569f3d2..41355f4 100644 --- a/kernel/src/process/mod.rs +++ b/kernel/src/process/mod.rs @@ -9,6 +9,10 @@ mod context; type Processor = Processor_; +/* +* @brief: +* initialize a new kernel process (idleproc) +*/ pub fn init() { PROCESSOR.call_once(|| SpinNoIrqLock::new({ From b3e2ca8aa07a1080c2bef5b25b119cbeb6e75695 Mon Sep 17 00:00:00 2001 From: lcy1996 <992195697@qq.com> Date: Fri, 5 Oct 2018 11:08:50 +0800 Subject: [PATCH 2/2] Merge conflict --- crate/process/src/processor.rs | 2 +- crate/sync/src/main.rs | 2 ++ crate/sync/src/monitor.rs | 3 +++ crate/sync/src/mutex.rs | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crate/process/src/processor.rs b/crate/process/src/processor.rs index 9083dad..2117528 100644 --- a/crate/process/src/processor.rs +++ b/crate/process/src/processor.rs @@ -176,7 +176,7 @@ impl Processor_ { to.status = Status::Running; self.scheduler.remove(pid); - info!("switch from {} to {} {:x?}", pid0, pid, to.context); + //info!("switch from {} to {} {:x?}", pid0, pid, to.context); unsafe { from.context.switch(&mut to.context); } } diff --git a/crate/sync/src/main.rs b/crate/sync/src/main.rs index 49c86fa..0837505 100644 --- a/crate/sync/src/main.rs +++ b/crate/sync/src/main.rs @@ -1,3 +1,5 @@ +//! entrance to test the communication in processes with solving five philosophers problem + mod mutex; mod monitor; diff --git a/crate/sync/src/monitor.rs b/crate/sync/src/monitor.rs index 2c7cb8d..b984fbc 100644 --- a/crate/sync/src/monitor.rs +++ b/crate/sync/src/monitor.rs @@ -1,3 +1,5 @@ +//! solve the five philosophers problem with monitor + use std::thread; use std::sync::{Mutex, Condvar, Arc}; use std::time::Duration; @@ -51,6 +53,7 @@ struct Table { fork_condvar: Vec, } +// the main function to test pub fn main() { let table = Arc::new(Table { fork_status: Mutex::new(vec![false; 5]), diff --git a/crate/sync/src/mutex.rs b/crate/sync/src/mutex.rs index 06b3223..eeef0f4 100644 --- a/crate/sync/src/mutex.rs +++ b/crate/sync/src/mutex.rs @@ -1,3 +1,5 @@ +//! solve the five philosophers problem with mutex + use std::thread; use std::sync::{Mutex, Arc}; use std::time::Duration; @@ -35,6 +37,7 @@ struct Table { forks: Vec>, } +// the main function to test pub fn main() { let table = Arc::new(Table { forks: vec![