diff --git a/src/arch/aarch64/rmm.rs b/src/arch/aarch64/rmm.rs index b81260519bae90562478df341d33786351b6fbe8..bc38a05d3807970fd385db209d853a0e571d9c70 100644 --- a/src/arch/aarch64/rmm.rs +++ b/src/arch/aarch64/rmm.rs @@ -177,25 +177,17 @@ unsafe fn inner<A: Arch>( // Ensure graphical debug region remains paged #[cfg(feature = "graphical_debug")] { - use crate::devices::graphical_debug::DEBUG_DISPLAY; + use crate::devices::graphical_debug::FRAMEBUFFER; use super::paging::entry::EntryFlags; - let (base, size) = if let Some(debug_display) = &*DEBUG_DISPLAY.lock() { - let data = &debug_display.display.onscreen; - ( - data.as_ptr() as usize - crate::PHYS_OFFSET, - data.len() * 4 - ) - } else { - (0, 0) - }; + let (phys, virt, size) = *FRAMEBUFFER.lock(); let pages = (size + A::PAGE_SIZE - 1) / A::PAGE_SIZE; for i in 0..pages { - let phys = PhysicalAddress::new(base + i * A::PAGE_SIZE); - let virt = A::phys_to_virt(phys); - let flags = PageFlags::new().write(true) - .custom_flag(EntryFlags::HUGE_PAGE.bits(), true); + let phys = PhysicalAddress::new(phys + i * A::PAGE_SIZE); + let virt = VirtualAddress::new(virt + i * A::PAGE_SIZE); + let flags = PageFlags::new().write(true); + //TODO: Write combining flag let flush = mapper.map_phys( virt, phys, diff --git a/src/arch/x86/rmm.rs b/src/arch/x86/rmm.rs index 701b254db58b1e049849ebbcfe0b428c53b9098e..660fe7c3d98d195aa6edaa5addaaf947f61a625f 100644 --- a/src/arch/x86/rmm.rs +++ b/src/arch/x86/rmm.rs @@ -173,24 +173,17 @@ unsafe fn inner<A: Arch>( // Ensure graphical debug region remains paged #[cfg(feature = "graphical_debug")] { - use crate::devices::graphical_debug::DEBUG_DISPLAY; + use crate::devices::graphical_debug::FRAMEBUFFER; use super::paging::entry::EntryFlags; - let (base, size) = if let Some(debug_display) = &*DEBUG_DISPLAY.lock() { - let data = &debug_display.display.onscreen; - ( - data.as_ptr() as usize - crate::PHYS_OFFSET, - data.len() * 4 - ) - } else { - (0, 0) - }; + let (phys, virt, size) = *FRAMEBUFFER.lock(); let pages = (size + A::PAGE_SIZE - 1) / A::PAGE_SIZE; for i in 0..pages { - let phys = PhysicalAddress::new(base + i * A::PAGE_SIZE); - let virt = A::phys_to_virt(phys); + let phys = PhysicalAddress::new(phys + i * A::PAGE_SIZE); + let virt = VirtualAddress::new(virt + i * A::PAGE_SIZE); let flags = PageFlags::new().write(true) + // Write combining flag .custom_flag(EntryFlags::HUGE_PAGE.bits(), true); let flush = mapper.map_phys( virt, diff --git a/src/arch/x86_64/rmm.rs b/src/arch/x86_64/rmm.rs index 7827a7e8520feb7a43030cd9ff169819adaac21a..480f61f6359b7f37d97708948e30385e3853b31a 100644 --- a/src/arch/x86_64/rmm.rs +++ b/src/arch/x86_64/rmm.rs @@ -164,24 +164,17 @@ unsafe fn inner<A: Arch>( // Ensure graphical debug region remains paged #[cfg(feature = "graphical_debug")] { - use crate::devices::graphical_debug::DEBUG_DISPLAY; + use crate::devices::graphical_debug::FRAMEBUFFER; use super::paging::entry::EntryFlags; - let (base, size) = if let Some(debug_display) = &*DEBUG_DISPLAY.lock() { - let data = &debug_display.display.onscreen; - ( - data.as_ptr() as usize - crate::PHYS_OFFSET, - data.len() * 4 - ) - } else { - (0, 0) - }; + let (phys, virt, size) = *FRAMEBUFFER.lock(); let pages = (size + A::PAGE_SIZE - 1) / A::PAGE_SIZE; for i in 0..pages { - let phys = PhysicalAddress::new(base + i * A::PAGE_SIZE); - let virt = A::phys_to_virt(phys); + let phys = PhysicalAddress::new(phys + i * A::PAGE_SIZE); + let virt = VirtualAddress::new(virt + i * A::PAGE_SIZE); let flags = PageFlags::new().write(true) + // Write combining flag .custom_flag(EntryFlags::HUGE_PAGE.bits(), true); let flush = mapper.map_phys( virt, diff --git a/src/devices/graphical_debug/mod.rs b/src/devices/graphical_debug/mod.rs index 4b1e3ee5efa131402d7ed3c5e32ab7d22edee77a..8f25d73ba99e2f3b6c34b4b1382f2e194bd34d49 100644 --- a/src/devices/graphical_debug/mod.rs +++ b/src/devices/graphical_debug/mod.rs @@ -11,12 +11,15 @@ pub static FONT: &'static [u8] = include_bytes!("../../../res/unifont.font"); pub static DEBUG_DISPLAY: Mutex<Option<DebugDisplay>> = Mutex::new(None); +pub static FRAMEBUFFER: Mutex<(usize, usize, usize)> = Mutex::new((0, 0, 0)); + pub fn init(env: &[u8]) { println!("Starting graphical debug"); + let mut phys = 0; + let mut virt = 0; let mut width = 0; let mut height = 0; - let mut physbaseptr = 0; //TODO: should errors be reported? for line in str::from_utf8(env).unwrap_or("").lines() { @@ -25,7 +28,11 @@ pub fn init(env: &[u8]) { let value = parts.next().unwrap_or(""); if name == "FRAMEBUFFER_ADDR" { - physbaseptr = usize::from_str_radix(value, 16).unwrap_or(0); + phys = usize::from_str_radix(value, 16).unwrap_or(0); + } + + if name == "FRAMEBUFFER_VIRT" { + virt = usize::from_str_radix(value, 16).unwrap_or(0); } if name == "FRAMEBUFFER_WIDTH" { @@ -37,17 +44,17 @@ pub fn init(env: &[u8]) { } } - if physbaseptr == 0 || width == 0 || height == 0 { + *FRAMEBUFFER.lock() = (phys, virt, width * height * 4); + + if phys == 0 || virt == 0 || width == 0 || height == 0 { println!("Framebuffer not found"); return; } - println!("Framebuffer {}x{} at {:X}", width, height, physbaseptr); + println!("Framebuffer {}x{} at {:X} mapped to {:X}", width, height, phys, virt); { - let virtbaseptr = physbaseptr + crate::PHYS_OFFSET; - - let display = Display::new(width, height, virtbaseptr as *mut u32); + let display = Display::new(width, height, virt as *mut u32); let debug_display = DebugDisplay::new(display); *DEBUG_DISPLAY.lock() = Some(debug_display); }