2018-11-19 13:21:06 +04:00
|
|
|
use crate::process::*;
|
|
|
|
use crate::arch::interrupt::TrapFrame;
|
|
|
|
use crate::arch::cpu;
|
|
|
|
use log::*;
|
2018-07-12 20:00:42 +04:00
|
|
|
|
2018-10-25 20:49:19 +04:00
|
|
|
pub static mut TICK: usize = 0;
|
|
|
|
|
2019-03-07 05:47:36 +04:00
|
|
|
pub fn uptime_msec() -> usize {
|
|
|
|
unsafe {crate::trap::TICK / crate::consts::USEC_PER_TICK / 1000}
|
|
|
|
}
|
|
|
|
|
2018-07-12 20:00:42 +04:00
|
|
|
pub fn timer() {
|
2018-10-25 20:49:19 +04:00
|
|
|
if cpu::id() == 0 {
|
|
|
|
unsafe { TICK += 1; }
|
|
|
|
}
|
2018-11-02 12:36:46 +04:00
|
|
|
processor().tick();
|
2018-07-12 20:00:42 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 08:07:21 +04:00
|
|
|
pub fn error(tf: &TrapFrame) -> ! {
|
2018-10-26 19:43:12 +04:00
|
|
|
error!("{:#x?}", tf);
|
2019-01-24 15:03:45 +04:00
|
|
|
let pid = processor().tid();
|
2018-10-26 19:43:12 +04:00
|
|
|
error!("On CPU{} Process {}", cpu::id(), pid);
|
2018-10-23 20:27:25 +04:00
|
|
|
|
2018-10-25 20:49:19 +04:00
|
|
|
processor().manager().exit(pid, 0x100);
|
2018-10-23 20:27:25 +04:00
|
|
|
processor().yield_now();
|
|
|
|
unreachable!();
|
2018-11-02 12:36:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serial(c: char) {
|
2019-03-07 19:32:47 +04:00
|
|
|
if c == '\r' {
|
|
|
|
// in linux, we use '\n' instead
|
|
|
|
crate::fs::STDIN.push('\n');
|
|
|
|
} else {
|
|
|
|
crate::fs::STDIN.push(c);
|
|
|
|
}
|
2018-07-12 20:00:42 +04:00
|
|
|
}
|