Skip to content
Snippets Groups Projects
Commit 9c7c010c authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fix graphical debug sync error, add unmapping, map with write combine

parent 819f77da
No related branches found
No related tags found
No related merge requests found
...@@ -33,9 +33,9 @@ impl<'a> fmt::Write for Writer<'a> { ...@@ -33,9 +33,9 @@ impl<'a> fmt::Write for Writer<'a> {
#[cfg(feature = "graphical_debug")] #[cfg(feature = "graphical_debug")]
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
if let Some(ref mut display) = *self.display { if let Some(ref mut display) = *self.display {
display.write_str(s) let _ = display.write_str(s);
} else {
self.serial.write_str(s)
} }
self.serial.write_str(s)
} }
} }
...@@ -23,6 +23,10 @@ impl DebugDisplay { ...@@ -23,6 +23,10 @@ impl DebugDisplay {
} }
} }
pub fn into_display(self) -> Display {
self.display
}
pub fn write(&mut self, c: char) { pub fn write(&mut self, c: char) {
if self.x >= self.w || c == '\n' { if self.x >= self.w || c == '\n' {
self.x = 0; self.x = 0;
...@@ -63,7 +67,7 @@ impl DebugDisplay { ...@@ -63,7 +67,7 @@ impl DebugDisplay {
); );
self.display.sync( self.display.sync(
self.x, self.y, self.x * 8, self.y * 16,
8, 16 8, 16
); );
......
...@@ -19,8 +19,6 @@ pub static FONT: &'static [u8] = include_bytes!("../../../../res/unifont.font"); ...@@ -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 static DEBUG_DISPLAY: Mutex<Option<DebugDisplay>> = Mutex::new(None);
pub fn init(active_table: &mut ActivePageTable) { pub fn init(active_table: &mut ActivePageTable) {
//TODO: Unmap mode_info and map physbaseptr in kernel space
println!("Starting graphical debug"); println!("Starting graphical debug");
let width; let width;
...@@ -37,35 +35,58 @@ pub fn init(active_table: &mut ActivePageTable) { ...@@ -37,35 +35,58 @@ pub fn init(active_table: &mut ActivePageTable) {
result.flush(active_table); 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; let page = Page::containing_address(VirtualAddress::new(mode_info_addr));
physbaseptr = mode_info.physbaseptr as usize; let result = active_table.unmap_return(page);
result.flush(active_table);
}
} }
{ {
let size = width * height; let size = width * height;
let onscreen = physbaseptr + ::KERNEL_OFFSET;
{ {
let start_page = Page::containing_address(VirtualAddress::new(physbaseptr)); let start_page = Page::containing_address(VirtualAddress::new(onscreen));
let end_page = Page::containing_address(VirtualAddress::new(physbaseptr + size * 4)); let end_page = Page::containing_address(VirtualAddress::new(onscreen + size * 4));
for page in Page::range_inclusive(start_page, end_page) { for page in Page::range_inclusive(start_page, end_page) {
let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().get())); let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().get() - ::KERNEL_OFFSET));
let result = active_table.map_to(page, frame, EntryFlags::PRESENT | EntryFlags::NO_EXECUTE | EntryFlags::WRITABLE | EntryFlags::HUGE_PAGE); 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); 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) { pub fn fini(active_table: &mut ActivePageTable) {
//TODO: Unmap physbaseptr if let Some(debug_display) = DEBUG_DISPLAY.lock().take() {
*DEBUG_DISPLAY.lock() = None; 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"); println!("Finished graphical debug");
} }
...@@ -10,18 +10,6 @@ pub unsafe fn fast_copy(dst: *mut u8, src: *const u8, len: usize) { ...@@ -10,18 +10,6 @@ pub unsafe fn fast_copy(dst: *mut u8, src: *const u8, len: usize) {
: "intel", "volatile"); : "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")] #[cfg(target_arch = "x86_64")]
#[inline(always)] #[inline(always)]
#[cold] #[cold]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment