remove interp and all wasm related code

This commit is contained in:
Able 2023-05-08 04:35:37 -05:00
parent 4a8b56a474
commit 88df7c2c34
11 changed files with 5 additions and 409 deletions

View file

@ -54,6 +54,7 @@ Unix believes in plain text emails. Quotes are `>`
### Unix why are your mouse a file?
This list is incomplete
`/dev/input/event1` The PS2 Mouse
`/dev/input/event3` The USB Mouse
`/dev/input/psaux` The PS2 Mouse
`/dev/input/psmouse` The PS2 Mouse
`/dev/input/mice` The Not(?) PS2 Mouse I think?

View file

@ -6,10 +6,8 @@ use {
use log::info;
use crate::interp::wasm;
pub unsafe fn init() {
log::info!("Initialising IDT");
info!("Initialising IDT");
IDT.load();
Lazy::force(&LAPIC);
x86_64::instructions::interrupts::enable();

View file

@ -1,6 +1,6 @@
use alloc::{string::String, vec::Vec};
use {crate::alloc::string::ToString, core::fmt, hashbrown::HashMap, xml::XMLElement};
use {crate::alloc::string::ToString, core::fmt, hashbrown::HashMap};
pub type Device = xml::XMLElement;
#[derive(Debug)]

View file

@ -1,6 +1,5 @@
use {
crate::arch::hardware_random_u64,
alloc::vec::Vec,
core::fmt::{self, Formatter},
};
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]

View file

@ -1,76 +0,0 @@
use {
crate::interp::{HFIDT, OBJECTS},
alloc::string::String,
log::trace,
wasmi::{Caller, TypedFunc},
};
use super::{HostState, WasmContext};
pub fn host_register_idt_handler(
caller: Caller<'_, HostState>,
interupt_number: i32,
address_start: i32,
length_of_string: i32,
) -> i32 {
// TODO: get the proc_id to address which function it is
// TODO: Register the function name and proc_id into the idt handler
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
let mem_array = mem.data(&caller);
let mut name = String::new();
for i in address_start..(address_start + length_of_string) {
let ch = mem_array[i as usize] as char;
name.push(ch);
}
let index = interupt_number as usize;
let hf = HFIDT.lock();
// hf.insert(index);
trace!("{}", name);
0
}
use crate::interp::Handle;
pub fn host_make_object(
mut caller: Caller<'_, HostState>,
address_start: i32,
length_of_string: i32,
) -> i64 {
trace!(
"Called with addr {{ start {} length {} }}",
address_start,
length_of_string
);
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
let mem_array = mem.data(&caller);
let mut name = String::new();
for i in address_start..(address_start + length_of_string) {
let ch = mem_array[i as usize] as char;
name.push(ch);
}
trace!("Object Name {}", name);
let hand = Handle::new();
{
let binding = OBJECTS;
let mut olock = binding.lock();
let obj = xml::XMLElement::new(name);
olock.push(Some(obj))
}
caller.data_mut().handles.push(hand);
// hand.into()
hand.as_u64().try_into().unwrap()
}
pub type WFIDT = TypedFunc<(), ()>;
fn get_fn_from_wc(wc: WasmContext, function_name: String) -> WFIDT {
wc.instance
.get_typed_func(wc.store, &function_name)
.unwrap()
}

View file

@ -1,200 +0,0 @@
mod host_functions;
mod objects;
use {
crate::{
handle::{self, Handle},
interp::{host_functions::host_make_object, objects::OBJECTS},
},
alloc::{string::String, vec::Vec},
hashbrown::HashMap,
log::trace,
spin::{Lazy, Mutex},
wasmi::{Caller, Error, Func, Instance, Linker, Module, Store, TypedFunc},
xml::XMLElement,
};
// Seperate use statement
use alloc::vec;
#[derive(Debug)]
pub struct WasmContext {
pub proc_id: Option<u64>,
pub instance: Instance,
pub store: Store<HostState>,
}
pub fn wasm() -> Result<(), wasmi::Error> {
use wasmi::{Config, Engine};
let mut conf = Config::default();
conf.wasm_bulk_memory(true);
// conf.,
let engine = Engine::new(&conf);
// trace!("Engine constructed");
// let wasm = include_bytes!("../../wasm_syscall_test.wasm");
let wasm = include_bytes!("../../../test.wasm");
// trace!("Loading WASM binary");
let module = Module::new(&engine, &wasm[..]).unwrap();
// trace!("Constructing wasm module");
let hs = HostState { handles: vec![] };
let mut store = Store::new(&engine, hs);
// trace!("constructing host store");
let read_mem_addr = Func::wrap(
&mut store,
|caller: Caller<'_, HostState>, param: i32| -> i32 { read_memory_address(caller, param) },
);
let mut linker = <Linker<HostState>>::new(&engine);
linker.define(
"host",
"read_mem_addr",
Func::wrap(
&mut store,
|caller: Caller<'_, HostState>, param: i32| -> i32 {
read_memory_address(caller, param)
},
),
)?;
linker.define(
"host",
"register_idt_handler",
Func::wrap(&mut store, host_functions::host_register_idt_handler),
)?;
linker.define(
"host",
"read_object_attribute",
Func::wrap(&mut store, host_read_object_attribute),
)?;
linker.define(
"host",
"create_object",
Func::wrap(&mut store, host_make_object),
)?;
let instance = linker
.instantiate(&mut store, &module)?
.ensure_no_start(&mut store)?;
let version = instance.get_global(&store, "VERSION");
// trace!("Version: {:?}", version);
let hello = instance.get_typed_func::<(), i64>(&store, "start")?;
let ret = hello.call(&mut store, ())?;
trace!("Called start got return of {:?}", ret);
Ok(())
}
#[derive(Clone, Debug)]
pub struct HostState {
handles: Vec<Handle>,
}
pub fn read_memory_address(caller: Caller<'_, HostState>, address: i32) -> i32 {
trace!("Address: {}", address);
// let obj = host_make_object(caller, 16, 23);
0
}
pub fn host_read_object_attribute(
caller: Caller<'_, HostState>,
handle: i64,
address_start: i32,
length_of_string: i32,
) -> (i32, i32) {
{
let binding = OBJECTS;
let mut olock = binding.lock();
// olock.get(&handle);
}
let mem = caller.get_export("memory").unwrap().into_memory().unwrap();
let mem_array = mem.data(&caller);
let mut name = String::new();
for i in address_start..(address_start + length_of_string) {
let ch = mem_array[i as usize] as char;
name.push(ch);
}
(0, 0)
}
pub fn build_wasm_context(bytes: Vec<u8>) -> Result<WasmContext, wasmi::Error> {
use wasmi::{Config, Engine};
let mut conf = Config::default();
conf.wasm_bulk_memory(true);
// conf.,
let engine = Engine::new(&conf);
// trace!("Engine constructed");
// let wasm = include_bytes!("../../wasm_syscall_test.wasm");
let wasm = include_bytes!("../../../test.wasm");
// trace!("Loading WASM binary");
let module = Module::new(&engine, &wasm[..]).unwrap();
// trace!("Constructing wasm module");
let hs = HostState { handles: vec![] };
let mut store = Store::new(&engine, hs);
// trace!("constructing host store");
let read_mem_addr = Func::wrap(
&mut store,
|caller: Caller<'_, HostState>, param: i32| -> i32 { read_memory_address(caller, param) },
);
let mut linker = <Linker<HostState>>::new(&engine);
linker.define(
"host",
"read_mem_addr",
Func::wrap(
&mut store,
|caller: Caller<'_, HostState>, param: i32| -> i32 {
read_memory_address(caller, param)
},
),
)?;
linker.define(
"host",
"read_object_attribute",
Func::wrap(&mut store, host_read_object_attribute),
)?;
linker.define(
"host",
"create_object",
Func::wrap(&mut store, host_make_object),
)?;
let instance = linker
.instantiate(&mut store, &module)?
.ensure_no_start(&mut store)?;
let wc = WasmContext {
instance,
store,
proc_id: None,
};
Ok(wc)
}
pub type HostFunctionIDT = HashMap<usize, WCFunction>;
pub struct WCFunction {
wc: WasmContext,
function: TypedFunc<(), ()>,
}
pub static HFIDT: Lazy<Mutex<HostFunctionIDT>> = Lazy::new(|| {
let mut hfidt = HashMap::new();
Mutex::new(hfidt)
});

View file

@ -1,14 +0,0 @@
use {
alloc::vec::Vec,
spin::{Lazy, Mutex},
};
// Seperate use statement
use alloc::vec;
pub type HostObjects = Vec<Option<xml::XMLElement>>;
pub const OBJECTS: Lazy<Mutex<HostObjects>> = Lazy::new(|| {
let mut obj = vec![];
Mutex::new(obj)
});

View file

@ -3,12 +3,11 @@
// use std::collections::HashMap;
use {
alloc::vec::Vec,
log::{info, trace},
log::info,
spin::{Lazy, Mutex},
};
use crate::{arch, device_tree::DeviceTree, schedule::Scheduler};
use crate::device_tree::DeviceTree;
use crate::alloc::string::ToString;
@ -43,11 +42,6 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
crate::arch::sloop()
}
pub const SCHEDULER: Lazy<Mutex<Scheduler>> = Lazy::new(|| {
let mut sch = Scheduler::new();
Mutex::new(sch)
});
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
let mut dt = DeviceTree::new();
Mutex::new(dt)

View file

@ -18,11 +18,9 @@ mod allocator;
mod arch;
pub mod device_tree;
pub mod handle;
pub mod interp;
mod kmain;
mod logger;
mod memory;
mod schedule;
mod task;
pub mod utils;

View file

@ -1,104 +0,0 @@
use core::arch;
// WasmContext
use crate::{arch::sloop, interp::WasmContext};
use alloc::vec::Vec;
use log::trace;
pub type ProcId = u64;
pub struct Scheduler {
running: Vec<WasmContext>,
halted: Vec<(ContextWake, WasmContext)>,
// time_halt: Vec<(ContextWake, WasmContext)>,
next_proc_id: ProcId,
}
impl Scheduler {
pub fn new() -> Scheduler {
Self {
running: Vec::new(),
halted: Vec::new(),
// time_halt: Vec::new(),
next_proc_id: 0,
}
}
pub fn run(&mut self) -> ! {
loop {
let proc = self.running.pop();
// self.time_halt.sort();
match proc {
Some(proc) => {
// trace!("SWAP WasmContext");
self.running.push(proc);
}
None => {
panic!("nothing scheduled.");
sloop();
}
}
}
}
fn sleep_inner(&self, id: ProcId) -> Result<usize, SchedulerError> {
let proc_len = self.running.len();
let mut proc_found = true;
let mut sleep_index = 0;
let mut i = 0;
for wc in &self.running {
if wc.proc_id == Some(id) {
sleep_index = i;
proc_found = true;
break;
}
if i == proc_len {
proc_found = false;
trace!("no process with ID {} found", id);
return Err(SchedulerError::ProcessIDNotFound(id));
}
i += 1;
}
Ok(sleep_index)
}
pub fn sleep(&mut self, id: ProcId, time: u64) -> Result<(), SchedulerError> {
match self.sleep_inner(id) {
Ok(sid) => self
.halted
.push((ContextWake::Time(time), self.running.remove(sid))),
Err(error) => return Err(error),
}
Ok(())
}
pub fn schedule(&mut self, wc: WasmContext, cw: ContextWake) -> Result<(), SchedulerError> {
if wc.proc_id != None {
panic!("Already Scheduled with PROC_ID {}", wc.proc_id.unwrap());
}
trace!("Scheduling WC with ProcID {}", self.next_proc_id);
if cw == ContextWake::None {
self.running.push(wc)
} else {
self.halted.push((cw, wc));
}
self.next_proc_id += 1;
Ok(())
}
}
#[derive(PartialEq)]
pub enum ContextWake {
/// Used when spawning a new process to have it instantly start
None,
Time(u64),
ObjectEvent,
}
pub enum SchedulerError {
ProcessIDNotFound(ProcId),
AlreadyScheduled(),
}

BIN
test.wasm

Binary file not shown.