diff --git a/Cargo.lock b/Cargo.lock index 96dd20db7..26d448cca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -425,12 +425,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/ableos/holey-bytes#0b9601e10565c1d368ec75c1e7e7606054037371" +source = "git+https://git.ablecorp.us/ableos/holey-bytes#35f3d59a547e285310551177e31bd3522d62fa08" [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/ableos/holey-bytes#0b9601e10565c1d368ec75c1e7e7606054037371" +source = "git+https://git.ablecorp.us/ableos/holey-bytes#35f3d59a547e285310551177e31bd3522d62fa08" dependencies = [ "hbbytecode", ] diff --git a/kernel/src/holeybytes/ecalls.rs b/kernel/src/holeybytes/ecalls.rs new file mode 100644 index 000000000..3c821df01 --- /dev/null +++ b/kernel/src/holeybytes/ecalls.rs @@ -0,0 +1,41 @@ +use { + crate::{ + ipc::buffer::{BufferTypes, IpcBuffer}, + kmain::IPC_BUFFERS, + }, + hbvm::value::Value, +}; + +pub fn make_ipc_buffer(registers: [Value; 256]) { + let r255 = registers[255]; + let r254 = registers[254]; + let r253 = registers[253]; + + let bounded = match unsafe { r254.u64 } { + 0 => false, + 1 => true, + _ => { + panic!("Bad"); + } + }; + + let length = unsafe { r254.u64 }; + + let mut buffs = IPC_BUFFERS.lock(); + match bounded { + false => { + let abc = IpcBuffer::new(false, 0); + buffs.push(abc); + } + true => { + let abc = IpcBuffer::new(true, length); + buffs.push(abc); + } + }; +} + +pub fn delete_ipc_buffer(registers: [Value; 256]) { + log::warn!("Unstable ecall"); + //TODO: fully define out how to layout the ecall for deleting buffers + //and figure out what happens if there are still messages in the queue +} diff --git a/kernel/src/holeybytes.rs b/kernel/src/holeybytes/mod.rs similarity index 77% rename from kernel/src/holeybytes.rs rename to kernel/src/holeybytes/mod.rs index 236cc168d..c63ea97ce 100644 --- a/kernel/src/holeybytes.rs +++ b/kernel/src/holeybytes/mod.rs @@ -1,3 +1,5 @@ +use crate::kmain::IPC_BUFFERS; + use { alloc::boxed::Box, core::{default, future::Future, task::Poll}, @@ -10,6 +12,8 @@ use { }, }; +mod ecalls; + const TIMER_QUOTIENT: usize = 100; pub struct ExecThread<'p> { @@ -71,33 +75,11 @@ Register dump: {:?}", } 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 - ) + ecalls::make_ipc_buffer(self.vm.registers); } 2 => { // Delete buffer - log::warn!("Syscall 2"); - } - 3 => { - log::warn!("Syscall 3"); - } - 4 => { - log::warn!("Syscall 4"); + ecalls::delete_ipc_buffer(self.vm.registers); } _ => { diff --git a/kernel/src/ipc/buffer.rs b/kernel/src/ipc/buffer.rs index fc7a46a60..8d17e73ac 100644 --- a/kernel/src/ipc/buffer.rs +++ b/kernel/src/ipc/buffer.rs @@ -16,6 +16,34 @@ pub struct IpcBuffer { } impl IpcBuffer { + pub fn new(bounded: bool, length: u64) -> Self { + log::debug!( + "New IPCBuffer\r + bounded: {}\r + length: {:?}\r", + bounded, + length + ); + + match (bounded, length) { + (false, a) => { + let buftype = BufferTypes::Unbound(SegQueue::new()); + + Self { + protocol: Protocol {}, + buffer: buftype, + } + } + (true, length) => { + let buftype = BufferTypes::Bound(ArrayQueue::new(length as usize)); + Self { + protocol: Protocol {}, + buffer: buftype, + } + } + } + } + /// Validate a message to match the `IPC.protocol` pub fn validate_messages(&mut self) -> Result<(), IpcError> { Ok(()) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 2f018b20b..b3e63e971 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -2,8 +2,7 @@ use hbvm::mem::Address; -use crate::holeybytes::ExecThread; - +use crate::{capabilities, holeybytes::ExecThread, ipc::buffer::IpcBuffer}; // use crate::arch::sloop; use { crate::{ @@ -27,6 +26,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { let _bmcmd: XMLElement; if bm.cmd.len() >= 2 { // TODO: pass into the program + // Pass CMDLine into an IPCBuffer and put the ptr to the IPCBuffer in r200 _bmcmd = build_cmd(name, bm.cmd.clone()); } } @@ -40,8 +40,6 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { // TODO: schedule the filesystem driver from the initramfs // TODO: schedule the init system from the initramfs - // capabilities::example(); - let mut executor = crate::task::Executor::default(); unsafe { for module in boot_modules.into_iter().take(2) { @@ -63,8 +61,8 @@ 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(|| { +use alloc::vec::Vec; +pub static IPC_BUFFERS: Lazy>> = Lazy::new(|| { let bufs = Vec::new(); Mutex::new(bufs) }); diff --git a/repbuild/holeybytes/ecall.hb b/repbuild/holeybytes/ecall.hb index 6550b824e..d0e4f62bf 100644 Binary files a/repbuild/holeybytes/ecall.hb and b/repbuild/holeybytes/ecall.hb differ diff --git a/shell.nix b/shell.nix index ce1e77a84..7e386e84a 100644 --- a/shell.nix +++ b/shell.nix @@ -1,9 +1,9 @@ { pkgs ? import { } }: pkgs.mkShell rec { buildInputs = with pkgs; [ - clang - llvmPackages.bintools - rustup + clang + llvmPackages.bintools + rustup qemu_full # OMVFFull # OMVF