ableOS input update

master
Able 2022-04-09 23:49:17 -05:00
parent 9e3584ed9b
commit 8e3e7346ec
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
2 changed files with 36 additions and 0 deletions

View File

@ -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<ValueType>) =
(&[], 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",

Binary file not shown.