1
0
Fork 0
forked from koniifer/ableos

add support for the device tree

This commit is contained in:
Able 2024-09-13 18:11:23 -05:00
parent 40cc412ab3
commit 9686349476
11 changed files with 155 additions and 21 deletions

View file

@ -6,6 +6,7 @@ use {
core::fmt, core::fmt,
hashbrown::HashMap, hashbrown::HashMap,
}; };
/// A device object. /// A device object.
/// TODO define device /// TODO define device
pub type Device = xml::XMLElement; pub type Device = xml::XMLElement;
@ -23,7 +24,9 @@ impl DeviceTree {
let mut dt = Self { let mut dt = Self {
devices: HashMap::new(), devices: HashMap::new(),
}; };
device_tree!(dt, [ device_tree!(
dt,
[
"Mice", "Mice",
"Keyboards", "Keyboards",
"Controllers", "Controllers",
@ -38,12 +41,12 @@ impl DeviceTree {
"Serial Ports", "Serial Ports",
"Cameras", "Cameras",
"Biometric Devices", "Biometric Devices",
]); ]
);
dt dt
} }
} }
use crate::{utils::TAB, device_tree}; use crate::{device_tree, tab, utils::TAB};
use crate::tab;
impl fmt::Display for DeviceTree { impl fmt::Display for DeviceTree {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f)?; writeln!(f)?;

View file

@ -6,6 +6,7 @@ use crate::{
allocator, allocator,
holeybytes::kernel_services::{ holeybytes::kernel_services::{
block_read, block_read,
dt_msg_handler::dt_msg_handler,
service_definition_service::{sds_msg_handler, SERVICES}, service_definition_service::{sds_msg_handler, SERVICES},
}, },
}; };
@ -134,6 +135,12 @@ pub fn handler(vm: &mut Vm) {
} }
#[cfg(not(target_arch = "x86_64"))] #[cfg(not(target_arch = "x86_64"))]
3 => unimplemented!("TODO: implement whatever buffer 3 does for no x86_64"), 3 => unimplemented!("TODO: implement whatever buffer 3 does for no x86_64"),
5 => match dt_msg_handler(vm, mem_addr, length) {
Ok(()) => {}
Err(err) => log::error!("Improper dt query"),
},
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) {

View file

@ -0,0 +1,92 @@
use {
crate::holeybytes::{kernel_services::block_read, Vm},
alloc::{
borrow::ToOwned,
string::{String, ToString},
vec::Vec,
},
log::debug,
};
pub enum DtError {
QueryFailure,
}
pub fn dt_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), DtError> {
let mut msg_vec = block_read(mem_addr, length);
let mut bytes: Vec<u8> = Vec::new();
for byte in msg_vec {
if byte == 0 {
break;
}
bytes.push(byte)
}
let query_string = String::from_utf8(bytes).unwrap();
log::trace!("Query {}", query_string);
let ret = query_parse(query_string);
log::trace!("Query response {}", ret);
vm.registers[1] = hbvm::value::Value(ret);
Ok(())
}
fn query_parse(query_string: String) -> u64 {
let qt_parse_step_one = query_string.split("/");
let mut qt_parse_step_two: Vec<String> = Vec::new();
for a in qt_parse_step_one {
qt_parse_step_two.push(a.to_string());
}
let first_fragment: &str = &qt_parse_step_two[0];
let ret = match first_fragment {
"framebuffer" => framebuffer_parse(qt_parse_step_two),
"cpu" => cpu_parse(qt_parse_step_two),
_ => 0,
};
return ret;
}
fn cpu_parse(qt_parse_step_two: Vec<String>) -> u64 {
let second_fragment: &str = &qt_parse_step_two[1];
match second_fragment {
// "architecture" => {
// return 0;
// }
_ => {
return 0;
}
};
}
fn framebuffer_parse(qt_parse_step_two: Vec<String>) -> u64 {
use {
crate::kmain::FB_REQ,
limine::{Framebuffer, NonNullPtr},
};
let fbs = &FB_REQ.get_response().get().unwrap().framebuffers();
let second_fragment: &str = &qt_parse_step_two[1];
match second_fragment {
"fb0" => {
let fb_front = &fbs[0];
let third_fragment: &str = &qt_parse_step_two[2];
let ret = match third_fragment {
"ptr" => {
let ptr = fb_front.address.as_ptr().unwrap();
ptr as usize as u64
}
"width" => fb_front.width,
"height" => fb_front.height,
_ => 0,
};
return ret;
}
_ => {
return 0;
}
};
}

View file

@ -1,5 +1,6 @@
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
pub mod dt_msg_handler;
pub mod mem_serve; pub mod mem_serve;
pub mod service_definition_service; pub mod service_definition_service;

View file

@ -0,0 +1 @@
# dt_api

View file

@ -0,0 +1,8 @@
stn := @use("rel:../../stn/src/lib.hb");
.{string, memory, buffer} := stn
dt_get := fn(query: ^u8): int {
message_length := string.length(query)
return @eca(int, 3, 5, query, message_length)
}

View file

@ -1,4 +1,4 @@
stn := @use("rel:../../stn/src/lib.hb") stn := @use("rel:../../stn/src/lib.hb");
.{string, memory, buffer} := stn .{string, memory, buffer} := stn
WindowID := struct { WindowID := struct {
@ -13,8 +13,6 @@ create_window := fn(channel: int): void {
windowing_system_buffer := buffer.search("XHorizon\0") windowing_system_buffer := buffer.search("XHorizon\0")
if windowing_system_buffer == 0 { if windowing_system_buffer == 0 {
} else { } else {
msg := "\{01}\0" msg := "\{01}\0"

View file

@ -0,0 +1 @@
# dt_buffer_test

View file

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

View file

@ -0,0 +1,8 @@
dt_api := @use("../../../libraries/dt_api/src/lib.hb")
main := fn(): int {
dt_api.dt_get("framebuffer/fb0/width\0")
dt_api.dt_get("cpu/architecture\0")
return 0
}

View file

@ -39,3 +39,7 @@ path = "boot:///horizon.hbf"
[boot.limine.ableos.modules.horizon_testing_program] [boot.limine.ableos.modules.horizon_testing_program]
path = "boot:///horizon_testing_program.hbf" path = "boot:///horizon_testing_program.hbf"
[boot.limine.ableos.modules.dt_buffer_test]
path = "boot:///dt_buffer_test.hbf"