add support for the device tree
This commit is contained in:
parent
40cc412ab3
commit
9686349476
|
@ -6,6 +6,7 @@ use {
|
|||
core::fmt,
|
||||
hashbrown::HashMap,
|
||||
};
|
||||
|
||||
/// A device object.
|
||||
/// TODO define device
|
||||
pub type Device = xml::XMLElement;
|
||||
|
@ -23,27 +24,29 @@ impl DeviceTree {
|
|||
let mut dt = Self {
|
||||
devices: HashMap::new(),
|
||||
};
|
||||
device_tree!(dt, [
|
||||
"Mice",
|
||||
"Keyboards",
|
||||
"Controllers",
|
||||
"Generic HIDs",
|
||||
"Disk Drives",
|
||||
"CD Drives",
|
||||
"Batteries",
|
||||
"Monitors",
|
||||
"GPUs",
|
||||
"CPUs",
|
||||
"USB",
|
||||
"Serial Ports",
|
||||
"Cameras",
|
||||
"Biometric Devices",
|
||||
]);
|
||||
device_tree!(
|
||||
dt,
|
||||
[
|
||||
"Mice",
|
||||
"Keyboards",
|
||||
"Controllers",
|
||||
"Generic HIDs",
|
||||
"Disk Drives",
|
||||
"CD Drives",
|
||||
"Batteries",
|
||||
"Monitors",
|
||||
"GPUs",
|
||||
"CPUs",
|
||||
"USB",
|
||||
"Serial Ports",
|
||||
"Cameras",
|
||||
"Biometric Devices",
|
||||
]
|
||||
);
|
||||
dt
|
||||
}
|
||||
}
|
||||
use crate::{utils::TAB, device_tree};
|
||||
use crate::tab;
|
||||
use crate::{device_tree, tab, utils::TAB};
|
||||
impl fmt::Display for DeviceTree {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f)?;
|
|
@ -6,6 +6,7 @@ use crate::{
|
|||
allocator,
|
||||
holeybytes::kernel_services::{
|
||||
block_read,
|
||||
dt_msg_handler::dt_msg_handler,
|
||||
service_definition_service::{sds_msg_handler, SERVICES},
|
||||
},
|
||||
};
|
||||
|
@ -134,6 +135,12 @@ pub fn handler(vm: &mut Vm) {
|
|||
}
|
||||
#[cfg(not(target_arch = "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 => {
|
||||
let mut buffs = IPC_BUFFERS.lock();
|
||||
match buffs.get_mut(&buffer_id) {
|
||||
|
|
92
kernel/src/holeybytes/kernel_services/dt_msg_handler.rs
Normal file
92
kernel/src/holeybytes/kernel_services/dt_msg_handler.rs
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
use alloc::{vec, vec::Vec};
|
||||
|
||||
pub mod dt_msg_handler;
|
||||
pub mod mem_serve;
|
||||
pub mod service_definition_service;
|
||||
|
||||
|
|
1
sysdata/libraries/dt_api/README.md
Normal file
1
sysdata/libraries/dt_api/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# dt_api
|
8
sysdata/libraries/dt_api/src/lib.hb
Normal file
8
sysdata/libraries/dt_api/src/lib.hb
Normal 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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("rel:../../stn/src/lib.hb")
|
||||
stn := @use("rel:../../stn/src/lib.hb");
|
||||
.{string, memory, buffer} := stn
|
||||
|
||||
WindowID := struct {
|
||||
|
@ -13,8 +13,6 @@ create_window := fn(channel: int): void {
|
|||
|
||||
windowing_system_buffer := buffer.search("XHorizon\0")
|
||||
|
||||
|
||||
|
||||
if windowing_system_buffer == 0 {
|
||||
} else {
|
||||
msg := "\{01}\0"
|
||||
|
|
1
sysdata/programs/dt_buffer_test/README.md
Normal file
1
sysdata/programs/dt_buffer_test/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# dt_buffer_test
|
11
sysdata/programs/dt_buffer_test/meta.toml
Normal file
11
sysdata/programs/dt_buffer_test/meta.toml
Normal 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"
|
8
sysdata/programs/dt_buffer_test/src/main.hb
Normal file
8
sysdata/programs/dt_buffer_test/src/main.hb
Normal 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
|
||||
}
|
|
@ -39,3 +39,7 @@ path = "boot:///horizon.hbf"
|
|||
|
||||
[boot.limine.ableos.modules.horizon_testing_program]
|
||||
path = "boot:///horizon_testing_program.hbf"
|
||||
|
||||
|
||||
[boot.limine.ableos.modules.dt_buffer_test]
|
||||
path = "boot:///dt_buffer_test.hbf"
|
||||
|
|
Loading…
Reference in a new issue