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

This commit is contained in:
Jeremy Soller
2018-03-11 12:12:54 -06:00
parent 819f77daf3
commit 9c7c010cc0
4 changed files with 44 additions and 31 deletions

View File

@@ -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)
}
}

View File

@@ -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
);

View File

@@ -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");
}

View File

@@ -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]