cursed-ness

This commit is contained in:
able 2023-10-23 09:12:43 -05:00
parent ebfc9c1c4e
commit d1d1bd7fd7
6 changed files with 79 additions and 58 deletions

View file

@ -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() {}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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<Mutex<DeviceTree>> = Lazy::new(|| {
});
use alloc::vec::Vec;
pub static IPC_BUFFERS: Lazy<Mutex<Vec<IpcBuffer>>> = Lazy::new(|| {
let bufs = Vec::new();
pub type IpcBuffers = HashMap<u64, IpcBuffer>;
pub static IPC_BUFFERS: Lazy<Mutex<IpcBuffers>> = Lazy::new(|| {
let bufs = HashMap::new();
Mutex::new(bufs)
});

Binary file not shown.

View file

@ -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 => {