From 762e6a27eaf32c06c2c11f2787c4a6bf48ab54cd Mon Sep 17 00:00:00 2001 From: Able Date: Sat, 9 Apr 2022 23:49:17 -0500 Subject: [PATCH] ableOS input update --- ableos/src/wasm_jumploader/host_functions.rs | 36 +++++++++++++++++++ userland/root_fs/ext2.img | Bin 4194304 -> 4194304 bytes 2 files changed, 36 insertions(+) diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index de47fdae..e69da8cb 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 17e4829dc1d242289975904d4318c976a4953afb..a35c7b642e90b8e9724c60e323725c4142ea0a31 100644 GIT binary patch delta 1212 zcmcIizi$*r6rMM;w>x)hd&iCe=Mv&s`!G0|uI|o62*|!QPZ|P_Tf)>o&I3bH2x7-c9eM!dz#&LipQ6^j*G>g6Q!-&;2D3QJR-Fv*Csw_RcSyyYkWJOWDeR z-M&=}3nNBYUT-du(cZ7$Z0HlvG8My#xnJ0+&&ni$B->)_5hVe#xw@XtZaCKT`OS+9 zm*+3e&4015ES&7Nu}709PU#0wZX&-@$tVjZXQJFag|q7Lmb?ivex}I)V$Wol$>C?BCm^| zge6<*&{-Y$N(6olyjQBsrm9GE)HFn32kNz#oN8HxL=N0ah+@jk01& z_NbX2;rmkfry#5K+n?ZS_Ndoip=Uk5u7Y)~&Uy#z z()#hf>ME?7ZzaYW<08f-jD3uIFz&^;590u1gK%D-4k8`;g{GHZ0#TbTp8x;= delta 1404 zcmZY6e{{`t9LMqR_j~Vl?}qKpkD1>y*9^1G4A*8he8^CU{H(25NTi~u)V+nbUvJfI zas7xWR)0e%Y!na2MLnpoB_WoGNecVmmu*7cU>`xGQ8penqIHxT?gRl)m4wtV5Lk zV{v|Q*%sHgk4+{xVLRV_W$MJTu$@vJ8oSVycH)kT^M56aN=&pex4d*gd8rKtF1Qhc z*qZWE&+)U4--+Y}y#B}}Z=ioA7obh~D0d|-wh_9e&oc*n9z`=%>+Io7g% z#c#NR-|+{o;u`+MU$~ANxQV~<4{o6rmdCPeIB>y@7{tN@FX9l7I;e|!Nbp!eE0Mv6 zB-BR(G(;mLqcKv@1WnNl&Cvoa(F&<(jWo1@A8nD2cE~_`bU;UBq7$+_LCeZ!$U$f1 zq6_lS72VJs0rWsV3eXdU=!GH_qc{4XFAVyjKkmW+lwcqRVKDB-Jwaj!hGH1*#c+(k zeHe*R7>zL)i*dLg51!d%S5dUS4^CkcrkUv)D=@tOoEt1F+MR#V(N=&Af}<1 zMq-lpn#T5#>KyOMqT3Pnm5HW^HW6(q+Dx>$XbaJnqOC+zMO%xeiMA2-i?$U_7i}k+ zA=+NFgJ?(5OwmrFS)$pZIij6Kb49y|=81L{?Izk?G$7hTG+(qpw5MpHXs=CLH1l7< CH4D!G