diff --git a/MANIFESTO.md b/MANIFESTO.md index 05cd16c32..c34e3b457 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 651b1559e..9abdc1ba7 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 c0c286f97..208318fbb 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 6f1f67da7..d402a39a6 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 401e7b40f..000000000 --- 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 97e7cb58a..000000000 --- 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 810f1452f..000000000 --- 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 eb5497968..77aa4ffc3 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 306858686..10f2db02b 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 05f1b2982..000000000 --- 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 da05794df..000000000 Binary files a/test.wasm and /dev/null differ