2018-04-27 19:10:39 +04:00
|
|
|
use memory::MemoryController;
|
|
|
|
use spin::{Once, Mutex};
|
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-13 17:13:57 +04:00
|
|
|
pub fn init(mut mc: MemoryController) {
|
2018-04-27 19:10:39 +04:00
|
|
|
PROCESSOR.call_once(|| {Mutex::new({
|
2018-05-13 17:13:57 +04:00
|
|
|
let initproc = Process::new_init(&mut mc);
|
|
|
|
let idleproc = Process::new("idle", idle_thread, &mut mc);
|
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-18 07:49:27 +04:00
|
|
|
MC.call_once(|| Mutex::new(mc));
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|
|
|
|
|
2018-05-21 12:30:30 +04:00
|
|
|
pub static PROCESSOR: Once<Mutex<Processor>> = Once::new();
|
|
|
|
pub static MC: Once<Mutex<MemoryController>> = Once::new();
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-05-22 19:48:39 +04:00
|
|
|
extern fn idle_thread() -> ! {
|
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();
|
|
|
|
let mut mc = MC.try().unwrap().lock();
|
|
|
|
let mut new = Process::new_user(data, &mut mc);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print() {
|
|
|
|
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|