parent
97b838981f
commit
37a6df252f
@ -1,48 +1,21 @@
|
|||||||
use alloc::String;
|
use alloc::String;
|
||||||
use memory::MemorySet;
|
pub use self::context::*;
|
||||||
use self::process::*;
|
|
||||||
pub use self::processor::*;
|
pub use self::processor::*;
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
use sync::SpinNoIrqLock;
|
use sync::{SpinNoIrqLock, Mutex, MutexGuard, SpinNoIrq};
|
||||||
|
|
||||||
mod process;
|
mod context;
|
||||||
mod processor;
|
mod processor;
|
||||||
mod scheduler;
|
mod scheduler;
|
||||||
|
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
PROCESSOR.call_once(|| {
|
PROCESSOR.call_once(||
|
||||||
SpinNoIrqLock::new({
|
SpinNoIrqLock::new(Processor::new(unsafe { Context::new_init() }))
|
||||||
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
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
|
pub static PROCESSOR: Once<SpinNoIrqLock<Processor>> = Once::new();
|
||||||
|
|
||||||
extern fn idle_thread(_arg: usize) -> ! {
|
pub fn processor() -> MutexGuard<'static, Processor, SpinNoIrq> {
|
||||||
println!("Hello, I'm idle.");
|
PROCESSOR.try().unwrap().lock()
|
||||||
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());
|
|
||||||
}
|
}
|
@ -1,14 +1,24 @@
|
|||||||
use process::PROCESSOR;
|
use process::*;
|
||||||
|
use arch::interrupt::TrapFrame;
|
||||||
|
|
||||||
pub fn timer() {
|
pub fn timer() {
|
||||||
let mut processor = PROCESSOR.try().unwrap().lock();
|
let mut processor = processor();
|
||||||
processor.tick();
|
processor.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn before_return() {
|
pub fn before_return() {
|
||||||
use process::PROCESSOR;
|
|
||||||
if let Some(processor) = PROCESSOR.try() {
|
if let Some(processor) = PROCESSOR.try() {
|
||||||
processor.lock().schedule();
|
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