1
0
Fork 0
forked from koniifer/ableos

made console_out print the bytes of its arg as ascii

This commit is contained in:
elfein727 2022-01-01 19:07:56 -08:00
parent f2dfad3162
commit 8680e6f470
3 changed files with 144 additions and 134 deletions

Binary file not shown.

View file

@ -1,3 +1,6 @@
use alloc::string::String;
use wasmi::TrapKind;
use { use {
alloc::format, alloc::format,
wasm_sys::SysCall, wasm_sys::SysCall,
@ -23,13 +26,13 @@ impl Externals for HostFunctions {
fn invoke_index( fn invoke_index(
&mut self, &mut self,
index: usize, index: usize,
_args: RuntimeArgs, args: RuntimeArgs,
) -> Result<Option<RuntimeValue>, Trap> { ) -> Result<Option<RuntimeValue>, Trap> {
match index.into() { match index.into() {
// Take in one arg discard the rest // Take in one arg discard the rest
SysCall::KILL => { SysCall::KILL => {
info!("Program run at runtime called a system call"); info!("Program run at runtime called a system call");
debug!("Runtime arguments: {:?}", _args); debug!("Runtime arguments: {:?}", args);
Ok(None) Ok(None)
} }
// Do nothing // Do nothing
@ -42,7 +45,13 @@ impl Externals for HostFunctions {
} }
SysCall::CONSOLE_OUT => { SysCall::CONSOLE_OUT => {
info!("Out"); // Eventually change this to 2- ptr and len
if args.len() != 1 {
return Err(Trap::new(TrapKind::UnexpectedSignature));
}
let arg: u64 = args.nth(0);
let buf = unsafe { String::from_utf8_unchecked(arg.to_le_bytes().to_vec()) };
println!["{}", buf];
Ok(None) Ok(None)
} }
SysCall::CONSOLE_GET_TITLE => Ok(None), SysCall::CONSOLE_GET_TITLE => Ok(None),

View file

@ -9,6 +9,7 @@ macro_rules! syscall_enum {
syscall_enum![@get_last $($VariantTail),*] syscall_enum![@get_last $($VariantTail),*]
}; };
($($Variant:ident=$Value:expr,)*) => { ($($Variant:ident=$Value:expr,)*) => {
#[allow(clippy::upper_case_acronyms)]
#[repr(usize)] #[repr(usize)]
pub enum SysCall { pub enum SysCall {
$($Variant = $Value),* $($Variant = $Value),*