forked from AbleOS/ableos
changes
This commit is contained in:
parent
fb8a835926
commit
6fd47695a6
|
@ -21,7 +21,7 @@ pub fn handler(vm: &mut Vm) {
|
|||
let ecall_number = vm.registers[2].cast::<u64>();
|
||||
|
||||
// debug!("Ecall number {:?}", ecall_number);
|
||||
// trace!("Register dump: {:?}", vm.registers);
|
||||
//info!("Register dump: {:?}", vm.registers);
|
||||
|
||||
match ecall_number {
|
||||
0 => {
|
||||
|
@ -57,7 +57,7 @@ pub fn handler(vm: &mut Vm) {
|
|||
};
|
||||
let buff_id = arch::hardware_random_u64();
|
||||
buffs.insert(buff_id, abc);
|
||||
debug!("Buffer ID: {}", buff_id);
|
||||
info!("Buffer ID: {}", buff_id);
|
||||
vm.registers[1] = hbvm::value::Value(buff_id);
|
||||
}
|
||||
2 => {
|
||||
|
@ -133,7 +133,6 @@ pub fn handler(vm: &mut Vm) {
|
|||
}
|
||||
buffer_id => {
|
||||
let mut buffs = IPC_BUFFERS.lock();
|
||||
|
||||
match buffs.get_mut(&buffer_id) {
|
||||
Some(buff) => {
|
||||
let mut msg_vec = vec![];
|
||||
|
@ -163,8 +162,20 @@ pub fn handler(vm: &mut Vm) {
|
|||
let max_length = vm.registers[5].cast::<u64>();
|
||||
|
||||
let mut buffs = IPC_BUFFERS.lock();
|
||||
let mut buff = buffs.get_mut(&buffer_id).unwrap();
|
||||
let msg = buff.pop();
|
||||
let mut buff: &mut IpcBuffer;
|
||||
|
||||
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() {
|
||||
info!("{}", max_length);
|
||||
error!("Message is too long to map in.");
|
||||
|
|
|
@ -3,7 +3,11 @@ use {
|
|||
alloc::string::ToString,
|
||||
arch::hardware_random_u64,
|
||||
holeybytes::{ecah::LogError, kernel_services::block_read, Vm},
|
||||
ipc::{protocol, protocol::Protocol},
|
||||
ipc::{
|
||||
buffer::IpcBuffer,
|
||||
protocol::{self, Protocol},
|
||||
},
|
||||
kmain::IPC_BUFFERS,
|
||||
},
|
||||
alloc::string::String,
|
||||
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();
|
||||
msg_vec.remove(0);
|
||||
|
||||
info!("Length {}", msg_vec.len());
|
||||
// info!("Length {}", msg_vec.len());
|
||||
|
||||
use ServiceEventType::*;
|
||||
match sds_event_type {
|
||||
|
@ -66,6 +70,10 @@ impl From<u8> for ServiceEventType {
|
|||
// 1 =>
|
||||
2 => Self::DeleteService,
|
||||
3 => Self::SearchServices,
|
||||
10 => {
|
||||
info!("TEST");
|
||||
panic!()
|
||||
}
|
||||
1_u8 | 4_u8..=u8::MAX => todo!(),
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +82,15 @@ impl From<u8> for ServiceEventType {
|
|||
fn sds_create_service(protocol: String) -> u64 {
|
||||
let buff_id = hardware_random_u64();
|
||||
let mut services = SERVICES.lock();
|
||||
let mut buffers = IPC_BUFFERS.lock();
|
||||
|
||||
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);
|
||||
// let a: protocol::Protocol = protocol.into();
|
||||
buff_id
|
||||
|
@ -87,6 +100,7 @@ fn sds_search_service(protocol: String) -> u64 {
|
|||
let mut services = SERVICES.lock();
|
||||
let compare = Protocol::from(protocol.clone());
|
||||
for (bid, protocol_canidate) in &services.0 {
|
||||
trace!("BID-{bid} protocol_canidate {:?}", protocol_canidate);
|
||||
if protocol_canidate == &compare {
|
||||
trace!("BufferID({}) => {}", bid, protocol.clone());
|
||||
return *bid;
|
||||
|
|
|
@ -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 {
|
||||
BufferTypes::Unbound(buff) => buff.pop(),
|
||||
BufferTypes::Bound(buff) => buff.pop(),
|
||||
};
|
||||
match msg {
|
||||
Some(msg) => return msg,
|
||||
None => panic!("Recieving msg error. No messages!"),
|
||||
Some(msg) => return Ok(msg),
|
||||
None => return Err(IpcError::NoMessagesInBuffer),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Interprocess Communication Errors
|
||||
#[derive(Debug)]
|
||||
pub enum IpcError {
|
||||
/// An invalid message error returned to the sender
|
||||
InvalidMessage,
|
||||
NoMessagesInBuffer,
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@ use {
|
|||
hashbrown::HashMap,
|
||||
log::info,
|
||||
};
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Type {}
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Funct {
|
||||
takes: Vec<String>,
|
||||
gives: Vec<String>,
|
||||
}
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Protocol {
|
||||
types: HashMap<String, Type>,
|
||||
fns: HashMap<String, Funct>,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
string := @use("rel:string.hb")
|
||||
buffer := @use("rel:buffer.hb")
|
||||
|
||||
log := fn(message: ^u8, level: u8): void {
|
||||
message_length := string.length(message);
|
||||
|
|
|
@ -23,11 +23,26 @@ main := fn(): int {
|
|||
a := buffer.create("XNumber\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.
|
||||
b := buffer.search("XNumber\0")
|
||||
|
||||
if a == b {
|
||||
serial_println("Stopping Serial Driver.\0")
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
11
sysdata/programs/serial_driver_test/meta.toml
Normal file
11
sysdata/programs/serial_driver_test/meta.toml
Normal 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"
|
21
sysdata/programs/serial_driver_test/src/main.hb
Normal file
21
sysdata/programs/serial_driver_test/src/main.hb
Normal 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
|
||||
}
|
|
@ -28,3 +28,7 @@ path = "boot:///diskio_driver.hbf"
|
|||
|
||||
[boot.limine.ableos.modules.fb_driver]
|
||||
path = "boot:///fb_driver.hbf"
|
||||
|
||||
|
||||
[boot.limine.ableos.modules.serial_driver_test]
|
||||
path = "boot:///serial_driver_test.hbf"
|
||||
|
|
Loading…
Reference in a new issue