diff --git a/src/arch/x86_64/graphical_debug/mod.rs b/src/arch/x86_64/graphical_debug/mod.rs index 1bf3cf78740927ca22bbe16b8bdaaa78c33af10e..40a1123607f7f4b8c3a0ce09d1e39a3676a5ab46 100644 --- a/src/arch/x86_64/graphical_debug/mod.rs +++ b/src/arch/x86_64/graphical_debug/mod.rs @@ -1,3 +1,4 @@ +use core::str; use spin::Mutex; use crate::memory::Frame; @@ -7,31 +8,45 @@ use crate::paging::mapper::PageFlushAll; pub use self::debug::DebugDisplay; use self::display::Display; -use self::mode_info::VBEModeInfo; use self::primitive::fast_set64; pub mod debug; pub mod display; -pub mod mode_info; pub mod primitive; pub static FONT: &'static [u8] = include_bytes!("../../../../res/unifont.font"); pub static DEBUG_DISPLAY: Mutex<Option<DebugDisplay>> = Mutex::new(None); -pub fn init(active_table: &mut ActivePageTable) { +pub fn init(active_table: &mut ActivePageTable, env: &[u8]) { println!("Starting graphical debug"); - let width; - let height; - let physbaseptr; + let mut width = 0; + let mut height = 0; + let mut physbaseptr = 0; - { - let mode_info_addr = 0x5200 + crate::PHYS_OFFSET; - let mode_info = unsafe { &*(mode_info_addr as *const VBEModeInfo) }; - width = mode_info.xresolution as usize; - height = mode_info.yresolution as usize; - physbaseptr = mode_info.physbaseptr as usize; + //TODO: should errors be reported? + for line in str::from_utf8(env).unwrap_or("").lines() { + let mut parts = line.splitn(2, '='); + let name = parts.next().unwrap_or(""); + let value = parts.next().unwrap_or(""); + + if name == "FRAMEBUFFER_ADDR" { + physbaseptr = usize::from_str_radix(value, 16).unwrap_or(0); + } + + if name == "FRAMEBUFFER_WIDTH" { + width = usize::from_str_radix(value, 16).unwrap_or(0); + } + + if name == "FRAMEBUFFER_HEIGHT" { + height = usize::from_str_radix(value, 16).unwrap_or(0); + } + } + + if physbaseptr == 0 || width == 0 || height == 0 { + println!("Framebuffer not found"); + return; } println!("Framebuffer {}x{} at {:X}", width, height, physbaseptr); diff --git a/src/arch/x86_64/graphical_debug/mode_info.rs b/src/arch/x86_64/graphical_debug/mode_info.rs deleted file mode 100644 index 7d59af64526523ac3d76d6f2c016473a13d353a0..0000000000000000000000000000000000000000 --- a/src/arch/x86_64/graphical_debug/mode_info.rs +++ /dev/null @@ -1,37 +0,0 @@ -/// The info of the VBE mode -#[derive(Copy, Clone, Default, Debug)] -#[repr(packed)] -pub struct VBEModeInfo { - attributes: u16, - win_a: u8, - win_b: u8, - granularity: u16, - winsize: u16, - segment_a: u16, - segment_b: u16, - winfuncptr: u32, - bytesperscanline: u16, - pub xresolution: u16, - pub yresolution: u16, - xcharsize: u8, - ycharsize: u8, - numberofplanes: u8, - bitsperpixel: u8, - numberofbanks: u8, - memorymodel: u8, - banksize: u8, - numberofimagepages: u8, - unused: u8, - redmasksize: u8, - redfieldposition: u8, - greenmasksize: u8, - greenfieldposition: u8, - bluemasksize: u8, - bluefieldposition: u8, - rsvdmasksize: u8, - rsvdfieldposition: u8, - directcolormodeinfo: u8, - pub physbaseptr: u32, - offscreenmemoryoffset: u32, - offscreenmemsize: u16, -} diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index 0a1fe8f1aeb4d5c1e668bbae8736ea9ced29c4ad..e0332c7d080b11c34e1cde509f338cfff80461ab 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -149,9 +149,12 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { // Activate memory logging log::init(); + // Convert env to slice + let env = slice::from_raw_parts((env_base + crate::PHYS_OFFSET) as *const u8, env_size); + // Use graphical debug #[cfg(feature="graphical_debug")] - graphical_debug::init(&mut active_table); + graphical_debug::init(&mut active_table, env); #[cfg(feature = "system76_ec_debug")] device::system76_ec::init(); @@ -175,7 +178,7 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { BSP_READY.store(true, Ordering::SeqCst); - slice::from_raw_parts((env_base + crate::PHYS_OFFSET) as *const u8, env_size) + env }; crate::kmain(CPU_COUNT.load(Ordering::SeqCst), env);