2018-06-02 21:10:20 +04:00
|
|
|
use memory::MemorySet;
|
2018-05-31 16:23:26 +04:00
|
|
|
use spin::Once;
|
2018-05-31 18:22:19 +04:00
|
|
|
use sync::SpinNoIrqLock;
|
2018-05-13 11:06:44 +04:00
|
|
|
use core::slice;
|
2018-05-18 07:49:27 +04:00
|
|
|
use alloc::String;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
|
|
|
use self::process::*;
|
2018-05-21 12:30:30 +04:00
|
|
|
pub use self::processor::*;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
|
|
|
mod process;
|
|
|
|
mod processor;
|
2018-05-23 07:20:36 +04:00
|
|
|
mod scheduler;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
|
|
|
|
2018-06-02 21:10:20 +04:00
|
|
|
pub fn init(mut ms: MemorySet) {
|
2018-05-31 18:22:19 +04:00
|
|
|
PROCESSOR.call_once(|| {
|
|
|
|
SpinNoIrqLock::new({
|
2018-06-02 21:10:20 +04:00
|
|
|
let initproc = Process::new_init(ms);
|
|
|
|
let idleproc = Process::new("idle", idle_thread, 0);
|
2018-05-18 07:49:27 +04:00
|
|
|
let mut processor = Processor::new();
|
2018-04-27 19:10:39 +04:00
|
|
|
processor.add(initproc);
|
|
|
|
processor.add(idleproc);
|
|
|
|
processor
|
|
|
|
})});
|
|
|
|
}
|
|
|
|
|
2018-05-31 18:22:19 +04:00
|
|
|
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-05-31 16:26:25 +04:00
|
|
|
extern fn idle_thread(arg: usize) -> ! {
|
2018-04-27 19:10:39 +04:00
|
|
|
loop {
|
|
|
|
println!("idle ...");
|
|
|
|
let mut i = 0;
|
2018-05-20 13:14:05 +04:00
|
|
|
while i < 1 << 22 {
|
2018-04-27 19:10:39 +04:00
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 23:41:41 +04:00
|
|
|
}
|
|
|
|
|
2018-05-19 12:32:18 +04:00
|
|
|
pub fn add_user_process(name: impl AsRef<str>, data: &[u8]) {
|
2018-05-18 07:49:27 +04:00
|
|
|
let mut processor = PROCESSOR.try().unwrap().lock();
|
2018-06-02 21:10:20 +04:00
|
|
|
let mut new = Process::new_user(data);
|
2018-05-19 12:32:18 +04:00
|
|
|
new.name = String::from(name.as_ref());
|
2018-05-18 07:49:27 +04:00
|
|
|
processor.add(new);
|
|
|
|
}
|
|
|
|
|
2018-05-31 16:26:25 +04:00
|
|
|
pub fn add_kernel_process(entry: extern fn(usize) -> !, arg: usize) -> Pid {
|
|
|
|
let mut processor = PROCESSOR.try().unwrap().lock();
|
2018-06-02 21:10:20 +04:00
|
|
|
let mut new = Process::new("", entry, arg);
|
2018-05-31 16:26:25 +04:00
|
|
|
processor.add(new)
|
|
|
|
}
|
|
|
|
|
2018-05-18 07:49:27 +04:00
|
|
|
pub fn print() {
|
|
|
|
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|