adding time syscall
This commit is contained in:
parent
3ce2026d32
commit
65259360eb
|
@ -8,6 +8,7 @@ pub struct HostExternals {}
|
||||||
|
|
||||||
const ADD_FUNC_INDEX: usize = 0;
|
const ADD_FUNC_INDEX: usize = 0;
|
||||||
const SEND_SIGNAL_INDEX: usize = 1;
|
const SEND_SIGNAL_INDEX: usize = 1;
|
||||||
|
const GET_TIME_INDEX: usize = 2;
|
||||||
|
|
||||||
impl Externals for HostExternals {
|
impl Externals for HostExternals {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
|
@ -31,6 +32,17 @@ impl Externals for HostExternals {
|
||||||
let ret = RuntimeValue::I32(0);
|
let ret = RuntimeValue::I32(0);
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GET_TIME_INDEX => {
|
||||||
|
use core::sync::atomic::Ordering::*;
|
||||||
|
|
||||||
|
x86_64::instructions::interrupts::disable();
|
||||||
|
let tick_time = crate::kmain::TICK.load(Relaxed);
|
||||||
|
x86_64::instructions::interrupts::enable();
|
||||||
|
|
||||||
|
let ret = RuntimeValue::I64(tick_time.try_into().unwrap());
|
||||||
|
Ok(Some(ret))
|
||||||
|
}
|
||||||
_ => panic!("Unimplemented function at {}", index),
|
_ => panic!("Unimplemented function at {}", index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +53,8 @@ impl HostExternals {
|
||||||
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
|
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
|
||||||
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||||
SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
|
||||||
|
GET_TIME_INDEX => (&[], Some(ValueType::I32)),
|
||||||
|
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
signature.params() == params && signature.return_type() == ret_ty
|
signature.params() == params && signature.return_type() == ret_ty
|
||||||
|
|
Loading…
Reference in a new issue