1
0
Fork 0
forked from koniifer/ableos
This commit is contained in:
Able 2024-08-19 13:13:58 -05:00
parent fb8a835926
commit 6fd47695a6
9 changed files with 93 additions and 14 deletions

View file

@ -21,7 +21,7 @@ pub fn handler(vm: &mut Vm) {
let ecall_number = vm.registers[2].cast::<u64>(); let ecall_number = vm.registers[2].cast::<u64>();
// debug!("Ecall number {:?}", ecall_number); // debug!("Ecall number {:?}", ecall_number);
// trace!("Register dump: {:?}", vm.registers); //info!("Register dump: {:?}", vm.registers);
match ecall_number { match ecall_number {
0 => { 0 => {
@ -57,7 +57,7 @@ pub fn handler(vm: &mut Vm) {
}; };
let buff_id = arch::hardware_random_u64(); let buff_id = arch::hardware_random_u64();
buffs.insert(buff_id, abc); buffs.insert(buff_id, abc);
debug!("Buffer ID: {}", buff_id); info!("Buffer ID: {}", buff_id);
vm.registers[1] = hbvm::value::Value(buff_id); vm.registers[1] = hbvm::value::Value(buff_id);
} }
2 => { 2 => {
@ -133,7 +133,6 @@ pub fn handler(vm: &mut Vm) {
} }
buffer_id => { buffer_id => {
let mut buffs = IPC_BUFFERS.lock(); let mut buffs = IPC_BUFFERS.lock();
match buffs.get_mut(&buffer_id) { match buffs.get_mut(&buffer_id) {
Some(buff) => { Some(buff) => {
let mut msg_vec = vec![]; let mut msg_vec = vec![];
@ -163,8 +162,20 @@ pub fn handler(vm: &mut Vm) {
let max_length = vm.registers[5].cast::<u64>(); let max_length = vm.registers[5].cast::<u64>();
let mut buffs = IPC_BUFFERS.lock(); let mut buffs = IPC_BUFFERS.lock();
let mut buff = buffs.get_mut(&buffer_id).unwrap(); let mut buff: &mut IpcBuffer;
let msg = buff.pop();
if buffs.get_mut(&buffer_id).is_some() {
buff = buffs.get_mut(&buffer_id).unwrap();
} else {
info!("AHHH");
vm.registers[1] = hbvm::value::Value(0);
return;
}
let pop = buff.pop();
if pop.is_err() {
return;
}
let msg = pop.unwrap();
if msg.len() > max_length.try_into().unwrap() { if msg.len() > max_length.try_into().unwrap() {
info!("{}", max_length); info!("{}", max_length);
error!("Message is too long to map in."); error!("Message is too long to map in.");

View file

@ -3,7 +3,11 @@ use {
alloc::string::ToString, alloc::string::ToString,
arch::hardware_random_u64, arch::hardware_random_u64,
holeybytes::{ecah::LogError, kernel_services::block_read, Vm}, holeybytes::{ecah::LogError, kernel_services::block_read, Vm},
ipc::{protocol, protocol::Protocol}, ipc::{
buffer::IpcBuffer,
protocol::{self, Protocol},
},
kmain::IPC_BUFFERS,
}, },
alloc::string::String, alloc::string::String,
hashbrown::HashMap, hashbrown::HashMap,
@ -22,7 +26,7 @@ pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(),
let sds_event_type: ServiceEventType = msg_vec[0].into(); let sds_event_type: ServiceEventType = msg_vec[0].into();
msg_vec.remove(0); msg_vec.remove(0);
info!("Length {}", msg_vec.len()); // info!("Length {}", msg_vec.len());
use ServiceEventType::*; use ServiceEventType::*;
match sds_event_type { match sds_event_type {
@ -66,6 +70,10 @@ impl From<u8> for ServiceEventType {
// 1 => // 1 =>
2 => Self::DeleteService, 2 => Self::DeleteService,
3 => Self::SearchServices, 3 => Self::SearchServices,
10 => {
info!("TEST");
panic!()
}
1_u8 | 4_u8..=u8::MAX => todo!(), 1_u8 | 4_u8..=u8::MAX => todo!(),
} }
} }
@ -74,10 +82,15 @@ impl From<u8> for ServiceEventType {
fn sds_create_service(protocol: String) -> u64 { fn sds_create_service(protocol: String) -> u64 {
let buff_id = hardware_random_u64(); let buff_id = hardware_random_u64();
let mut services = SERVICES.lock(); let mut services = SERVICES.lock();
let mut buffers = IPC_BUFFERS.lock();
let protocol_ = Protocol::from(protocol.clone()); let protocol_ = Protocol::from(protocol.clone());
let mut buff = IpcBuffer::new(false, 0);
services.0.insert(buff_id, protocol_.clone());
buff.protocol = protocol_.clone();
buffers.insert(buff_id, buff);
services.0.insert(buff_id, protocol_);
trace!("BufferID({}) => {}", buff_id, protocol); trace!("BufferID({}) => {}", buff_id, protocol);
// let a: protocol::Protocol = protocol.into(); // let a: protocol::Protocol = protocol.into();
buff_id buff_id
@ -87,6 +100,7 @@ fn sds_search_service(protocol: String) -> u64 {
let mut services = SERVICES.lock(); let mut services = SERVICES.lock();
let compare = Protocol::from(protocol.clone()); let compare = Protocol::from(protocol.clone());
for (bid, protocol_canidate) in &services.0 { for (bid, protocol_canidate) in &services.0 {
trace!("BID-{bid} protocol_canidate {:?}", protocol_canidate);
if protocol_canidate == &compare { if protocol_canidate == &compare {
trace!("BufferID({}) => {}", bid, protocol.clone()); trace!("BufferID({}) => {}", bid, protocol.clone());
return *bid; return *bid;

View file

@ -54,19 +54,21 @@ impl IpcBuffer {
} }
}; };
} }
pub fn pop(&mut self) -> Message { pub fn pop(&mut self) -> Result<Message, IpcError> {
let msg = match &self.buffer { let msg = match &self.buffer {
BufferTypes::Unbound(buff) => buff.pop(), BufferTypes::Unbound(buff) => buff.pop(),
BufferTypes::Bound(buff) => buff.pop(), BufferTypes::Bound(buff) => buff.pop(),
}; };
match msg { match msg {
Some(msg) => return msg, Some(msg) => return Ok(msg),
None => panic!("Recieving msg error. No messages!"), None => return Err(IpcError::NoMessagesInBuffer),
} }
} }
} }
/// Interprocess Communication Errors /// Interprocess Communication Errors
#[derive(Debug)]
pub enum IpcError { pub enum IpcError {
/// An invalid message error returned to the sender /// An invalid message error returned to the sender
InvalidMessage, InvalidMessage,
NoMessagesInBuffer,
} }

View file

@ -3,14 +3,14 @@ use {
hashbrown::HashMap, hashbrown::HashMap,
log::info, log::info,
}; };
#[derive(PartialEq)] #[derive(Debug, PartialEq, Clone)]
pub struct Type {} pub struct Type {}
#[derive(PartialEq)] #[derive(Debug, PartialEq, Clone)]
pub struct Funct { pub struct Funct {
takes: Vec<String>, takes: Vec<String>,
gives: Vec<String>, gives: Vec<String>,
} }
#[derive(PartialEq)] #[derive(Debug, PartialEq, Clone)]
pub struct Protocol { pub struct Protocol {
types: HashMap<String, Type>, types: HashMap<String, Type>,
fns: HashMap<String, Funct>, fns: HashMap<String, Funct>,

View file

@ -1,4 +1,5 @@
string := @use("rel:string.hb") string := @use("rel:string.hb")
buffer := @use("rel:buffer.hb")
log := fn(message: ^u8, level: u8): void { log := fn(message: ^u8, level: u8): void {
message_length := string.length(message); message_length := string.length(message);

View file

@ -23,11 +23,26 @@ main := fn(): int {
a := buffer.create("XNumber\0") a := buffer.create("XNumber\0")
serial_println("Starting Serial Driver.\0") serial_println("Starting Serial Driver.\0")
mem := memory.request_page(1)
loop {
ptr := @eca(int, 4, a, mem, 4096)
if ptr == 0 {
serial_println("No message\0")
}
if ptr > 0 {
serial_println("Yes message\0")
serial_println(mem)
break
}
}
// Note that the first byte is reserved, pad accordingly. // Note that the first byte is reserved, pad accordingly.
b := buffer.search("XNumber\0") b := buffer.search("XNumber\0")
if a == b { if a == b {
serial_println("Stopping Serial Driver.\0") serial_println("Stopping Serial Driver.\0")
} }
return 0 return 0
} }

View file

@ -0,0 +1,11 @@
[package]
name = "serial_driver_test"
authors = ["able"]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -0,0 +1,21 @@
stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer} := stn
frame_buffer := @as(^u8, @bitcast(18446603339442421760))
log_info := fn(): void {
a := buffer.search("XNumber\0")
if a == 0 {
} else {
msg := "XABC\0"
msg_length := string.length(msg)
@eca(void, 3, a, msg, msg_length)
}
return
}
main := fn(): int {
log_info()
return 0
}

View file

@ -28,3 +28,7 @@ path = "boot:///diskio_driver.hbf"
[boot.limine.ableos.modules.fb_driver] [boot.limine.ableos.modules.fb_driver]
path = "boot:///fb_driver.hbf" path = "boot:///fb_driver.hbf"
[boot.limine.ableos.modules.serial_driver_test]
path = "boot:///serial_driver_test.hbf"