more attempts to get wasm running
This commit is contained in:
parent
1abbe176bc
commit
c627aa6133
|
@ -46,11 +46,6 @@ dependencies = [
|
|||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.1.4"
|
||||
|
@ -74,16 +69,6 @@ name = "nodrop"
|
|||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.41"
|
||||
|
@ -99,7 +84,6 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -158,7 +142,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "wasmi"
|
||||
version = "0.5.1"
|
||||
dependencies = [
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libm 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -211,12 +194,10 @@ dependencies = [
|
|||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cpuio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "22b8e308ccfc5acf3b82f79c0eac444cf6114cb2ac67a230ca6c177210068daa"
|
||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
|
||||
"checksum libm 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
|
||||
"checksum linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "47314ec1d29aa869ee7cb5a5be57be9b1055c56567d59c3fb6689926743e0bea"
|
||||
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
|
||||
"checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
"checksum num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f9c3f34cdd24f334cb265d9bf8bfa8a241920d026916785747a92f0e55541a1a"
|
||||
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
|
||||
"checksum num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454"
|
||||
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
|
||||
|
|
|
@ -21,7 +21,7 @@ unsafe impl GlobalAlloc for Dummy {
|
|||
}
|
||||
|
||||
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||
pub const HEAP_SIZE: usize = 32 * 1024 * 1024; // 32 MiB
|
||||
|
||||
pub fn init_heap(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
|
|
68
src/main.rs
68
src/main.rs
|
@ -6,10 +6,14 @@
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use bootloader::{entry_point, BootInfo};
|
||||
use core::panic::PanicInfo;
|
||||
use xe_os::println;
|
||||
use xe_os::{print, println};
|
||||
use wasmi::{
|
||||
Error as InterpreterError, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
|
||||
ModuleImportResolver, ModuleInstance, ModuleRef, RuntimeArgs, RuntimeValue, Signature, Trap,
|
||||
ValueType,
|
||||
};
|
||||
|
||||
entry_point!(kernel_main);
|
||||
|
||||
|
@ -21,11 +25,30 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|||
test_main();
|
||||
|
||||
println!("It did not crash!");
|
||||
|
||||
run_wasm();
|
||||
|
||||
println!("THE WASM RAN :DDDD");
|
||||
xe_os::hlt_loop();
|
||||
}
|
||||
|
||||
fn run_wasm() {
|
||||
use alloc::vec::Vec;
|
||||
|
||||
let bytes = include_bytes!("../data/h.wasm");
|
||||
let b: Vec<u8> = bytes.iter().cloned().collect();
|
||||
println!("loaded wasm into a Vec");
|
||||
|
||||
let module = wasmi::Module::from_buffer(&b).unwrap();
|
||||
let mut imports = ImportsBuilder::new();
|
||||
imports.push_resolver("h", &H);
|
||||
|
||||
let instance = ModuleInstance::new(&module, &imports)
|
||||
.expect("failed to load wasm module")
|
||||
.assert_no_start();
|
||||
|
||||
println!("invoking export");
|
||||
let _ = instance.invoke_export("h", &[], &mut H);
|
||||
}
|
||||
|
||||
// our existing panic handler
|
||||
|
@ -42,3 +65,44 @@ fn panic(info: &PanicInfo) -> ! {
|
|||
fn panic(info: &PanicInfo) -> ! {
|
||||
xe_os::test_panic_handler(info);
|
||||
}
|
||||
|
||||
struct H;
|
||||
const H_FUNC: usize = 0;
|
||||
|
||||
impl Externals for H {
|
||||
fn invoke_index(
|
||||
&mut self,
|
||||
index: usize,
|
||||
args: RuntimeArgs,
|
||||
) -> Result<Option<RuntimeValue>, Trap> {
|
||||
use core::char::from_u32;
|
||||
match index {
|
||||
H_FUNC => {
|
||||
let ch_t: i32 = args.nth(0);
|
||||
let ch = from_u32(ch_t as u32);
|
||||
print!("{}", ch.unwrap());
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
_ => panic!("unknown function called"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleImportResolver for H {
|
||||
fn resolve_func(
|
||||
&self,
|
||||
field_name: &str,
|
||||
_signature: &Signature,
|
||||
) -> Result<FuncRef, InterpreterError> {
|
||||
let func_ref = match field_name {
|
||||
"h" => FuncInstance::alloc_host(
|
||||
Signature::new(&[ValueType::I32][..], None),
|
||||
H_FUNC,
|
||||
),
|
||||
_ => panic!("unknwon function asked for"),
|
||||
};
|
||||
|
||||
Ok(func_ref)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue