parent
97b838981f
commit
37a6df252f
@ -1,48 +1,21 @@
|
||||
use alloc::String;
|
||||
use memory::MemorySet;
|
||||
use self::process::*;
|
||||
pub use self::context::*;
|
||||
pub use self::processor::*;
|
||||
use spin::Once;
|
||||
use sync::SpinNoIrqLock;
|
||||
use sync::{SpinNoIrqLock, Mutex, MutexGuard, SpinNoIrq};
|
||||
|
||||
mod process;
|
||||
mod context;
|
||||
mod processor;
|
||||
mod scheduler;
|
||||
|
||||
|
||||
pub fn init() {
|
||||
PROCESSOR.call_once(|| {
|
||||
SpinNoIrqLock::new({
|
||||
let initproc = Process::new_init();
|
||||
let idleproc = Process::new("idle", idle_thread, 0);
|
||||
let mut processor = Processor::new();
|
||||
processor.add(initproc);
|
||||
processor.add(idleproc);
|
||||
processor
|
||||
})
|
||||
});
|
||||
PROCESSOR.call_once(||
|
||||
SpinNoIrqLock::new(Processor::new(unsafe { Context::new_init() }))
|
||||
);
|
||||
}
|
||||
|
||||
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
|
||||
|
||||
extern fn idle_thread(_arg: usize) -> ! {
|
||||
println!("Hello, I'm idle.");
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub fn add_user_process(name: impl AsRef<str>, data: &[u8]) {
|
||||
let mut processor = PROCESSOR.try().unwrap().lock();
|
||||
let mut new = Process::new_user(data);
|
||||
new.name = String::from(name.as_ref());
|
||||
processor.add(new);
|
||||
}
|
||||
|
||||
pub fn add_kernel_process(entry: extern fn(usize) -> !, arg: usize) -> Pid {
|
||||
let mut processor = PROCESSOR.try().unwrap().lock();
|
||||
let new = Process::new("", entry, arg);
|
||||
processor.add(new)
|
||||
}
|
||||
|
||||
pub fn print() {
|
||||
debug!("{:#x?}", *PROCESSOR.try().unwrap().lock());
|
||||
pub fn processor() -> MutexGuard<'static, Processor, SpinNoIrq> {
|
||||
PROCESSOR.try().unwrap().lock()
|
||||
}
|
@ -1,14 +1,24 @@
|
||||
use process::PROCESSOR;
|
||||
|
||||
use process::*;
|
||||
use arch::interrupt::TrapFrame;
|
||||
|
||||
pub fn timer() {
|
||||
let mut processor = PROCESSOR.try().unwrap().lock();
|
||||
let mut processor = processor();
|
||||
processor.tick();
|
||||
}
|
||||
|
||||
pub fn before_return() {
|
||||
use process::PROCESSOR;
|
||||
if let Some(processor) = PROCESSOR.try() {
|
||||
processor.lock().schedule();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(tf: &TrapFrame) {
|
||||
if let Some(processor) = PROCESSOR.try() {
|
||||
let mut processor = processor.lock();
|
||||
let pid = processor.current_pid();
|
||||
error!("Process {} error:\n{:#x?}", pid, tf);
|
||||
processor.exit(pid, 0x100); // TODO: Exit code for error
|
||||
} else {
|
||||
panic!("Exception when processor not inited\n{:#x?}", tf);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue