diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index de47fda..e69da8c 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -12,6 +12,8 @@ const SEND_SIGNAL_INDEX: usize = 1; const GET_TIME_INDEX: usize = 2; const GET_RANDOM_INDEX: usize = 3; +const GET_INPUT_INDEX: usize = 4; + impl Externals for HostExternals { fn invoke_index( &mut self, @@ -54,10 +56,27 @@ impl Externals for HostExternals { // let ret = RuntimeValue::I32(rand.try_into().unwrap()); Ok(Some(ret)) } + + GET_INPUT_INDEX => { + // println!("SYSCALL: get input"); + let input = + x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()); + if let Some(chr) = input { + println!("SYSCALL: input: {}", chr); + } + + let ret = RuntimeValue::I32(input.unwrap_or(0x00 as char) as i32); + + Ok(Some(ret)) + } + _ => panic!("Unimplemented function at {}", index), } } } + +use crate::rhai_shell::KEYBUFF; + use crate::arch::generate_process_pass; impl HostExternals { fn check_signature(&self, index: usize, signature: &Signature) -> bool { @@ -127,6 +146,22 @@ impl HostExternals { } return true; } + GET_INPUT_INDEX => { + let (params, ret_ty): (&[ValueType], Option) = + (&[], Some(ValueType::I32)); + if params.len() != signature.params().len() { + return false; + } + if ret_ty != signature.return_type() { + return false; + } + for (ty, param) in params.iter().zip(signature.params()) { + if *ty != *param { + return false; + } + } + return true; + } _ => false, } } @@ -139,6 +174,7 @@ impl ModuleImportResolver for HostExternals { "send_signal" => SEND_SIGNAL_INDEX, "get_time" => GET_TIME_INDEX, "get_random" => GET_RANDOM_INDEX, + "get_input" => GET_INPUT_INDEX, _ => { return Err(Error::Instantiation(format!( "Export {} not found", diff --git a/userland/root_fs/ext2.img b/userland/root_fs/ext2.img index 17e4829..a35c7b6 100644 Binary files a/userland/root_fs/ext2.img and b/userland/root_fs/ext2.img differ