diff --git a/src/arch/x86_64/debug.rs b/src/arch/x86_64/debug.rs index 198ca29aad7d58df885b4a624b0a720e84a89d54..2398d92dd9254aeaaf7733ce8b4c194a5be5ab67 100644 --- a/src/arch/x86_64/debug.rs +++ b/src/arch/x86_64/debug.rs @@ -33,9 +33,9 @@ impl<'a> fmt::Write for Writer<'a> { #[cfg(feature = "graphical_debug")] fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { if let Some(ref mut display) = *self.display { - display.write_str(s) - } else { - self.serial.write_str(s) + let _ = display.write_str(s); } + + self.serial.write_str(s) } } diff --git a/src/arch/x86_64/graphical_debug/debug.rs b/src/arch/x86_64/graphical_debug/debug.rs index 338b9a1e188d4ead7a9cf568e5c299dc5bfb57e5..21dcf94dc358ad0aa0303525546979151e80a512 100644 --- a/src/arch/x86_64/graphical_debug/debug.rs +++ b/src/arch/x86_64/graphical_debug/debug.rs @@ -23,6 +23,10 @@ impl DebugDisplay { } } + pub fn into_display(self) -> Display { + self.display + } + pub fn write(&mut self, c: char) { if self.x >= self.w || c == '\n' { self.x = 0; @@ -63,7 +67,7 @@ impl DebugDisplay { ); self.display.sync( - self.x, self.y, + self.x * 8, self.y * 16, 8, 16 ); diff --git a/src/arch/x86_64/graphical_debug/mod.rs b/src/arch/x86_64/graphical_debug/mod.rs index a8b2a7014ea7ebe17d47806ddae7571a54b7cfc1..9c1e1d78e489528d4587544f85206891bc06d070 100644 --- a/src/arch/x86_64/graphical_debug/mod.rs +++ b/src/arch/x86_64/graphical_debug/mod.rs @@ -19,8 +19,6 @@ 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) { - //TODO: Unmap mode_info and map physbaseptr in kernel space - println!("Starting graphical debug"); let width; @@ -37,35 +35,58 @@ pub fn init(active_table: &mut ActivePageTable) { result.flush(active_table); } - let mode_info = unsafe { &*(mode_info_addr as *const VBEModeInfo) }; + { + 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; + } - width = mode_info.xresolution as usize; - height = mode_info.yresolution as usize; - physbaseptr = mode_info.physbaseptr as usize; + { + let page = Page::containing_address(VirtualAddress::new(mode_info_addr)); + let result = active_table.unmap_return(page); + result.flush(active_table); + } } { let size = width * height; + let onscreen = physbaseptr + ::KERNEL_OFFSET; { - let start_page = Page::containing_address(VirtualAddress::new(physbaseptr)); - let end_page = Page::containing_address(VirtualAddress::new(physbaseptr + size * 4)); + let start_page = Page::containing_address(VirtualAddress::new(onscreen)); + let end_page = Page::containing_address(VirtualAddress::new(onscreen + size * 4)); for page in Page::range_inclusive(start_page, end_page) { - let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().get())); - let result = active_table.map_to(page, frame, EntryFlags::PRESENT | EntryFlags::NO_EXECUTE | EntryFlags::WRITABLE | EntryFlags::HUGE_PAGE); + let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().get() - ::KERNEL_OFFSET)); + let flags = EntryFlags::PRESENT | EntryFlags::NO_EXECUTE | EntryFlags::WRITABLE | EntryFlags::HUGE_PAGE; + let result = active_table.map_to(page, frame, flags); result.flush(active_table); } } - unsafe { fast_set64(physbaseptr as *mut u64, 0, size/2) }; + unsafe { fast_set64(onscreen as *mut u64, 0, size/2) }; - *DEBUG_DISPLAY.lock() = Some(DebugDisplay::new(Display::new(width, height, physbaseptr))); + let display = Display::new(width, height, onscreen); + let debug_display = DebugDisplay::new(display); + *DEBUG_DISPLAY.lock() = Some(debug_display); } } -pub fn fini(_active_table: &mut ActivePageTable) { - //TODO: Unmap physbaseptr - *DEBUG_DISPLAY.lock() = None; +pub fn fini(active_table: &mut ActivePageTable) { + if let Some(debug_display) = DEBUG_DISPLAY.lock().take() { + let display = debug_display.into_display(); + let onscreen = display.onscreen.as_mut_ptr() as usize; + let size = display.width * display.height; + { + let start_page = Page::containing_address(VirtualAddress::new(onscreen)); + let end_page = Page::containing_address(VirtualAddress::new(onscreen + size * 4)); + for page in Page::range_inclusive(start_page, end_page) { + let result = active_table.unmap_return(page); + result.flush(active_table); + } + } + } println!("Finished graphical debug"); } diff --git a/src/arch/x86_64/graphical_debug/primitive.rs b/src/arch/x86_64/graphical_debug/primitive.rs index 16c2536a24accfc3f3acd7c24652e2f71be27b3f..922e89c55f1bfc9694ac701f577a281857841006 100644 --- a/src/arch/x86_64/graphical_debug/primitive.rs +++ b/src/arch/x86_64/graphical_debug/primitive.rs @@ -10,18 +10,6 @@ pub unsafe fn fast_copy(dst: *mut u8, src: *const u8, len: usize) { : "intel", "volatile"); } -#[cfg(target_arch = "x86_64")] -#[inline(always)] -#[cold] -pub unsafe fn fast_copy64(dst: *mut u64, src: *const u64, len: usize) { - asm!("cld - rep movsq" - : - : "{rdi}"(dst as usize), "{rsi}"(src as usize), "{rcx}"(len) - : "cc", "memory", "rdi", "rsi", "rcx" - : "intel", "volatile"); -} - #[cfg(target_arch = "x86_64")] #[inline(always)] #[cold]