From 88df7c2c34d5d580a01e58f90f931e21ebd891d4 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 8 May 2023 04:35:37 -0500 Subject: [PATCH] remove interp and all wasm related code --- MANIFESTO.md | 1 + kernel/src/arch/x86_64/interrupts.rs | 4 +- kernel/src/device_tree.rs | 2 +- kernel/src/handle.rs | 1 - kernel/src/interp/host_functions.rs | 76 ---------- kernel/src/interp/mod.rs | 200 --------------------------- kernel/src/interp/objects.rs | 14 -- kernel/src/kmain.rs | 10 +- kernel/src/lib.rs | 2 - kernel/src/schedule.rs | 104 -------------- test.wasm | Bin 198 -> 0 bytes 11 files changed, 5 insertions(+), 409 deletions(-) delete mode 100644 kernel/src/interp/host_functions.rs delete mode 100644 kernel/src/interp/mod.rs delete mode 100644 kernel/src/interp/objects.rs delete mode 100644 kernel/src/schedule.rs delete mode 100644 test.wasm diff --git a/MANIFESTO.md b/MANIFESTO.md index 05cd16c3..c34e3b45 100644 --- a/MANIFESTO.md +++ b/MANIFESTO.md @@ -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? diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 651b1559..9abdc1ba 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -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(); diff --git a/kernel/src/device_tree.rs b/kernel/src/device_tree.rs index c0c286f9..208318fb 100644 --- a/kernel/src/device_tree.rs +++ b/kernel/src/device_tree.rs @@ -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)] diff --git a/kernel/src/handle.rs b/kernel/src/handle.rs index 6f1f67da..d402a39a 100644 --- a/kernel/src/handle.rs +++ b/kernel/src/handle.rs @@ -1,6 +1,5 @@ use { crate::arch::hardware_random_u64, - alloc::vec::Vec, core::fmt::{self, Formatter}, }; #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)] diff --git a/kernel/src/interp/host_functions.rs b/kernel/src/interp/host_functions.rs deleted file mode 100644 index 401e7b40..00000000 --- a/kernel/src/interp/host_functions.rs +++ /dev/null @@ -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() -} diff --git a/kernel/src/interp/mod.rs b/kernel/src/interp/mod.rs deleted file mode 100644 index 97e7cb58..00000000 --- a/kernel/src/interp/mod.rs +++ /dev/null @@ -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, - pub instance: Instance, - pub store: Store, -} - -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 = >::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, -} - -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) -> Result { - 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 = >::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; -pub struct WCFunction { - wc: WasmContext, - function: TypedFunc<(), ()>, -} - -pub static HFIDT: Lazy> = Lazy::new(|| { - let mut hfidt = HashMap::new(); - - Mutex::new(hfidt) -}); diff --git a/kernel/src/interp/objects.rs b/kernel/src/interp/objects.rs deleted file mode 100644 index 810f1452..00000000 --- a/kernel/src/interp/objects.rs +++ /dev/null @@ -1,14 +0,0 @@ -use { - alloc::vec::Vec, - spin::{Lazy, Mutex}, -}; - -// Seperate use statement -use alloc::vec; - -pub type HostObjects = Vec>; - -pub const OBJECTS: Lazy> = Lazy::new(|| { - let mut obj = vec![]; - Mutex::new(obj) -}); diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index eb549796..77aa4ffc 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -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> = Lazy::new(|| { - let mut sch = Scheduler::new(); - Mutex::new(sch) -}); - pub static DEVICE_TREE: Lazy> = Lazy::new(|| { let mut dt = DeviceTree::new(); Mutex::new(dt) diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 30685868..10f2db02 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -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; diff --git a/kernel/src/schedule.rs b/kernel/src/schedule.rs deleted file mode 100644 index 05f1b298..00000000 --- a/kernel/src/schedule.rs +++ /dev/null @@ -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, - 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 { - 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(), -} diff --git a/test.wasm b/test.wasm deleted file mode 100644 index da05794df633a154cf69362ca3273f286f0b4344..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 198 zcmXAhK?=e!6h!|djV)G11i=%C*XYh$G-(@9Aq0|Nu$$)MT^L(t^LR51ndm@7xD^@+ zNsE*)YdNQsNfT!Al*P+OJ_c)s)>+q@VF*NpB6j)6he?o%Yyy)!K<*#7Q}d5nDxzkW2}=cP%8kU@ol(~(3FZ74E${`VACh1& A0ssI2