diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index 1c21f317..83072b59 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -8,6 +8,7 @@ pub struct HostExternals {} const ADD_FUNC_INDEX: usize = 0; const SEND_SIGNAL_INDEX: usize = 1; +const GET_TIME_INDEX: usize = 2; impl Externals for HostExternals { fn invoke_index( @@ -31,6 +32,17 @@ impl Externals for HostExternals { let ret = RuntimeValue::I32(0); 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), } } @@ -41,6 +53,8 @@ impl HostExternals { let (params, ret_ty): (&[ValueType], Option) = match index { ADD_FUNC_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, }; signature.params() == params && signature.return_type() == ret_ty