ableOS input update
This commit is contained in:
parent
20482f57a3
commit
762e6a27ea
|
@ -12,6 +12,8 @@ const SEND_SIGNAL_INDEX: usize = 1;
|
||||||
const GET_TIME_INDEX: usize = 2;
|
const GET_TIME_INDEX: usize = 2;
|
||||||
const GET_RANDOM_INDEX: usize = 3;
|
const GET_RANDOM_INDEX: usize = 3;
|
||||||
|
|
||||||
|
const GET_INPUT_INDEX: usize = 4;
|
||||||
|
|
||||||
impl Externals for HostExternals {
|
impl Externals for HostExternals {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -54,10 +56,27 @@ impl Externals for HostExternals {
|
||||||
// let ret = RuntimeValue::I32(rand.try_into().unwrap());
|
// let ret = RuntimeValue::I32(rand.try_into().unwrap());
|
||||||
Ok(Some(ret))
|
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),
|
_ => panic!("Unimplemented function at {}", index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::rhai_shell::KEYBUFF;
|
||||||
|
|
||||||
use crate::arch::generate_process_pass;
|
use crate::arch::generate_process_pass;
|
||||||
impl HostExternals {
|
impl HostExternals {
|
||||||
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
|
||||||
|
@ -127,6 +146,22 @@ impl HostExternals {
|
||||||
}
|
}
|
||||||
return true;
|
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,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +174,7 @@ impl ModuleImportResolver for HostExternals {
|
||||||
"send_signal" => SEND_SIGNAL_INDEX,
|
"send_signal" => SEND_SIGNAL_INDEX,
|
||||||
"get_time" => GET_TIME_INDEX,
|
"get_time" => GET_TIME_INDEX,
|
||||||
"get_random" => GET_RANDOM_INDEX,
|
"get_random" => GET_RANDOM_INDEX,
|
||||||
|
"get_input" => GET_INPUT_INDEX,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error::Instantiation(format!(
|
return Err(Error::Instantiation(format!(
|
||||||
"Export {} not found",
|
"Export {} not found",
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue