From d1d1bd7fd70b3b01958106cdfdc601ebf118dd84 Mon Sep 17 00:00:00 2001 From: able Date: Mon, 23 Oct 2023 09:12:43 -0500 Subject: [PATCH] cursed-ness --- kernel/src/arch/x86_64/mod.rs | 33 +++++++++++++++---- kernel/src/holeybytes/ecalls.rs | 41 ------------------------ kernel/src/holeybytes/mod.rs | 55 ++++++++++++++++++++++++++++---- kernel/src/kmain.rs | 7 ++-- repbuild/holeybytes/ecall.hb | Bin 90 -> 90 bytes repbuild/src/main.rs | 1 + 6 files changed, 79 insertions(+), 58 deletions(-) delete mode 100644 kernel/src/holeybytes/ecalls.rs diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 16ec21d..18809cf 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -1,8 +1,9 @@ -use embedded_graphics::pixelcolor::Rgb888; - use { crate::{arch::x86_64::graphics::DISPLAY, bootmodules::BootModule}, core::arch::asm, + embedded_graphics::pixelcolor::Rgb888, + log::warn, + rdrand::RdSeed, }; pub mod memory; @@ -186,11 +187,29 @@ pub fn spin_loop() -> ! { pub fn hardware_random_u64() -> u64 { use {log::trace, rdrand::RdRand}; - let gen = RdRand::new().unwrap(); - let ret = gen.try_next_u64().unwrap(); - trace!("Random {}", ret); - - ret + let gen = RdRand::new(); + match gen { + Ok(gen) => { + let ret = gen.try_next_u64().unwrap(); + trace!("Random {}", ret); + return ret; + } + Err(err) => { + warn!("RDRand not supported."); + // Try rdseed + let gen = RdSeed::new(); + match gen { + Ok(gen) => { + let ret = gen.try_next_u64().unwrap(); + trace!("Random {}", ret); + return ret; + } + Err(err) => { + panic!("Neither RDRand or RDSeed are supported") + } + } + } + } } pub fn get_edid() {} diff --git a/kernel/src/holeybytes/ecalls.rs b/kernel/src/holeybytes/ecalls.rs deleted file mode 100644 index 3c821df..0000000 --- a/kernel/src/holeybytes/ecalls.rs +++ /dev/null @@ -1,41 +0,0 @@ -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/mod.rs b/kernel/src/holeybytes/mod.rs index c63ea97..fc8e2e8 100644 --- a/kernel/src/holeybytes/mod.rs +++ b/kernel/src/holeybytes/mod.rs @@ -1,19 +1,17 @@ -use crate::kmain::IPC_BUFFERS; - use { + crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS}, alloc::boxed::Box, core::{default, future::Future, task::Poll}, hbvm::{ mem::{ softpaging::{icache::ICache, HandlePageFault, SoftPagedMem}, - Address, + Address, Memory, }, Vm, VmRunError, VmRunOk, }, + log::{debug, info, trace, warn}, }; -mod ecalls; - const TIMER_QUOTIENT: usize = 100; pub struct ExecThread<'p> { @@ -75,13 +73,56 @@ Register dump: {:?}", } 1 => { // Make buffer - ecalls::make_ipc_buffer(self.vm.registers); + let r255 = self.vm.registers[255]; + let r254 = self.vm.registers[254]; + let r253 = self.vm.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(); + let abc; + + match bounded { + false => { + abc = IpcBuffer::new(false, 0); + } + true => { + abc = IpcBuffer::new(true, length); + } + }; + let buff_id = arch::hardware_random_u64(); + buffs.insert(buff_id, abc); + debug!("Buffer ID: {}", buff_id); } 2 => { // Delete buffer - ecalls::delete_ipc_buffer(self.vm.registers); } + 3 => { + // Send a message to a buffer + let r254 = self.vm.registers[254]; + let r253 = self.vm.registers[253]; + let r252 = self.vm.registers[252]; + let buffer_id = unsafe { r254.u64 }; + let mem_addr = unsafe { r253.u64 }; + let length = unsafe { r252.u64 as usize }; + trace!("{:?}", mem_addr); + use alloc::vec::Vec; + + if buffer_id == 1 { + info!("Logging") + } + } + // 4 + // 5 _ => { log::error!("Syscall unknown {:?}", r255) } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 53e2786..192dc31 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -1,6 +1,6 @@ //! AbleOS Kernel Entrypoint -use hbvm::mem::Address; +use {hashbrown::HashMap, hbvm::mem::Address}; use crate::{capabilities, holeybytes::ExecThread, ipc::buffer::IpcBuffer}; // use crate::arch::sloop; @@ -65,8 +65,9 @@ pub static DEVICE_TREE: Lazy> = Lazy::new(|| { }); use alloc::vec::Vec; -pub static IPC_BUFFERS: Lazy>> = Lazy::new(|| { - let bufs = Vec::new(); +pub type IpcBuffers = HashMap; +pub static IPC_BUFFERS: Lazy> = Lazy::new(|| { + let bufs = HashMap::new(); Mutex::new(bufs) }); diff --git a/repbuild/holeybytes/ecall.hb b/repbuild/holeybytes/ecall.hb index 918327121a7e679f599e215b98623f0187efefaa..77c83ec84dbb6ba34ba457f5234db74c654f12d2 100644 GIT binary patch literal 90 ncmd;=jtiLG;X=W_a3NUGy4lo}87{Upe literal 90 scmd;=jtiLG;X(qTdl))hT7sk?r=>Q7=02R0icK`qY diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 88d9ea2..2758e25 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -191,6 +191,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { "-drive", "file=target/disk.img,format=raw", "-m", "4G", "-smp", "cores=4", + "-cpu", "Broadwell-v4" ]); } Target::Riscv64Virt => {