From 4a8b56a4746dc628ce44eaaead5df460bbbf8f86 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 8 May 2023 03:53:15 -0500 Subject: [PATCH] dynamically support display discovery --- kernel/src/arch/x86_64/graphics.rs | 23 +++++++++++++++-------- kernel/src/arch/x86_64/mod.rs | 10 +++++----- kernel/src/device_tree.rs | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/kernel/src/arch/x86_64/graphics.rs b/kernel/src/arch/x86_64/graphics.rs index 3a4fccf93..998f35482 100644 --- a/kernel/src/arch/x86_64/graphics.rs +++ b/kernel/src/arch/x86_64/graphics.rs @@ -1,20 +1,27 @@ -use virtio_drivers::transport::Transport; - -use crate::arch::virtio::AbleosHal; - -use {embedded_graphics::pixelcolor::Rgb888, virtio_drivers::device::gpu::VirtIOGpu}; +use {limine::NonNullPtr, virtio_drivers::transport::Transport}; use { + crate::{arch::virtio::AbleosHal, kmain::DEVICE_TREE}, able_graphics_library::raw_pixel::Display, - embedded_graphics::prelude::*, - limine::FramebufferRequest, + embedded_graphics::{pixelcolor::Rgb888, prelude::*}, + limine::{Framebuffer, FramebufferRequest}, spin::{Lazy, Mutex}, + virtio_drivers::device::gpu::VirtIOGpu, }; pub static DISPLAY: Lazy> = Lazy::new(|| { static FB_REQ: FramebufferRequest = FramebufferRequest::new(0); - let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; + let fb1: &NonNullPtr = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; + { + use crate::alloc::string::ToString; + let mut dt = DEVICE_TREE.lock(); + let mut disp = xml::XMLElement::new("display_0"); + disp.set_attribute("width", fb1.width); + disp.set_attribute("height", fb1.height); + disp.set_attribute("bits per pixel", fb1.bpp); + dt.devices.insert("Displays".to_string(), alloc::vec![disp]); + } let m = Mutex::new(Display { fb: fb1.address.as_ptr().unwrap().cast(), size: Size::new(fb1.width as u32, fb1.height as u32), diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index b0549f101..f9447937a 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -114,12 +114,10 @@ unsafe extern "C" fn _kernel_start() -> ! { graphics::init(); let mut dis = DISPLAY.lock(); use {able_graphics_library::raw_pixel, embedded_graphics::prelude::RgbColor}; - dis.set_color(Rgb888::GREEN); - - dis.line(1, 1, 10, 10, 4); - // dis.line(1, 200, 100, 10, 1); - // dis.line(1, 1, 200, 10, 1); + dis.line(1, 1, 700, 1000, 1); + // dis.line(10, 10, 100, 10, 10); + // dis.line(100, 10, 1, 1, 10); } crate::kmain::kmain( @@ -162,3 +160,5 @@ pub fn hardware_random_u64() -> u64 { ret } + +pub fn get_edid() {} diff --git a/kernel/src/device_tree.rs b/kernel/src/device_tree.rs index 62c01f898..c0c286f97 100644 --- a/kernel/src/device_tree.rs +++ b/kernel/src/device_tree.rs @@ -45,6 +45,7 @@ use crate::utils::TAB; impl fmt::Display for DeviceTree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f); for (device_type, devices) in &self.devices { writeln!(f, "\r{TAB}{}/\r", device_type)?; for device in devices {