From 54844b46a032a944379f9591e332bc0b0d0d2521 Mon Sep 17 00:00:00 2001 From: able Date: Thu, 7 Sep 2023 14:36:53 -0500 Subject: [PATCH] ECALL work and expanded errors on HBVM shutdown --- kernel/src/holeybytes.rs | 65 ++++++++++++++++++++++++++++++++++++---- kernel/src/ipc/buffer.rs | 2 +- kernel/src/kmain.rs | 6 ++++ kernel/src/lib.rs | 2 ++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/kernel/src/holeybytes.rs b/kernel/src/holeybytes.rs index eb80658c..236cc168 100644 --- a/kernel/src/holeybytes.rs +++ b/kernel/src/holeybytes.rs @@ -1,6 +1,6 @@ use { alloc::boxed::Box, - core::{future::Future, task::Poll}, + core::{default, future::Future, task::Poll}, hbvm::{ mem::{ softpaging::{icache::ICache, HandlePageFault, SoftPagedMem}, @@ -17,7 +17,6 @@ pub struct ExecThread<'p> { } unsafe impl<'p> Send for ExecThread<'p> {} - impl<'p> ExecThread<'p> { pub unsafe fn new(program: &'p [u8], entrypoint: Address) -> Self { ExecThread { @@ -44,11 +43,67 @@ impl<'p> Future for ExecThread<'p> { cx: &mut core::task::Context<'_>, ) -> Poll { match self.vm.run() { - Err(err) => return Poll::Ready(Err(err)), + Err(err) => { + log::error!( + "HBVM Error\r +Register dump: {:?}", + self.vm.registers + ); + + return Poll::Ready(Err(err)); + } Ok(VmRunOk::End) => return Poll::Ready(Ok(())), Ok(VmRunOk::Ecall) => { - log::info!("Ecall"); - log::info!("{:?}", self.vm.registers); + let r255 = self.vm.registers[255]; + let r254 = self.vm.registers[254]; + let r253 = self.vm.registers[253]; + + log::debug!("Ecall number {:?}", r255); + log::trace!("Register dump: {:?}", self.vm.registers); + + match r255.cast::() { + 0 => { + // TODO: explode computer + // hello world ecall + for x in 0u64..=255 { + self.vm.registers[x as usize] = x.into(); + } + } + 1 => { + // Make buffer + log::trace!( + "bounded: {}\n\r +length: {:?}", + match unsafe { r254.u64 } { + 0 => { + false + } + 1 => { + true + } + _ => { + // TODO: throw this back to the runtime + panic!("Bad"); + } + }, + r253 + ) + } + 2 => { + // Delete buffer + log::warn!("Syscall 2"); + } + 3 => { + log::warn!("Syscall 3"); + } + 4 => { + log::warn!("Syscall 4"); + } + + _ => { + log::error!("Syscall unknown {:?}", r255) + } + } } Ok(VmRunOk::Timer) => (), } diff --git a/kernel/src/ipc/buffer.rs b/kernel/src/ipc/buffer.rs index 646749d6..fc7a46a6 100644 --- a/kernel/src/ipc/buffer.rs +++ b/kernel/src/ipc/buffer.rs @@ -5,7 +5,7 @@ use { crossbeam_queue::{ArrayQueue, SegQueue}, }; -enum BufferTypes { +pub enum BufferTypes { Unbound(SegQueue), Bound(ArrayQueue), } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index be037f1a..2f018b20 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -63,6 +63,12 @@ pub static DEVICE_TREE: Lazy> = Lazy::new(|| { Mutex::new(dt) }); +use {crate::ipc::buffer::BufferTypes, alloc::vec::Vec}; +pub static IPC_BUFFERS: Lazy>> = Lazy::new(|| { + let bufs = Vec::new(); + Mutex::new(bufs) +}); + #[test_case] fn trivial_assertion() { trace!("trivial assertion... "); diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 7b040176..4b08366f 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -42,6 +42,8 @@ pub const VERSION: Version = Version { #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { + arch::register_dump(); + if let Some(loc) = info.location() { let _ = crate::arch::log(format_args!( "Location: {}: {}, {}\r\n",