93 lines
2.3 KiB
Rust
93 lines
2.3 KiB
Rust
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;
|
|
}
|
|
};
|
|
}
|