From b954aef6964d02239723bbd4db423af9d263e66d Mon Sep 17 00:00:00 2001 From: WangRunji Date: Thu, 5 Apr 2018 01:12:42 +0800 Subject: [PATCH] Add cursor for VGA --- src/arch/x86_64/driver/vga.rs | 12 ++++++++++++ src/io/vga_writer.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/src/arch/x86_64/driver/vga.rs b/src/arch/x86_64/driver/vga.rs index a405efe..76b383b 100644 --- a/src/arch/x86_64/driver/vga.rs +++ b/src/arch/x86_64/driver/vga.rs @@ -1,6 +1,7 @@ use spin::Mutex; use core::ptr::Unique; use volatile::Volatile; +use x86_64::instructions::port::{outw, outb}; pub const VGA_BUFFER: Unique = unsafe{ Unique::new_unchecked(0xb8000 as *mut _) @@ -77,6 +78,17 @@ impl VgaBuffer { pub fn byte_at(&self, row: usize, col: usize) -> u8 { self.chars[row][col].read().ascii_char } + pub fn set_cursor_at(&self, row: usize, col: usize) { + assert!(row < BUFFER_HEIGHT && col < BUFFER_WIDTH); + let pos = row * BUFFER_WIDTH + col; + unsafe { + // Reference: Rustboot project + outw(0x3D4, 15u16); // WARNING verify should be u16 + outb(0x3D5, pos as u8); + outw(0x3D4, 14u16); + outb(0x3D5, (pos >> 8) as u8); + } + } } #[cfg(test)] diff --git a/src/io/vga_writer.rs b/src/io/vga_writer.rs index 482483d..df603c6 100644 --- a/src/io/vga_writer.rs +++ b/src/io/vga_writer.rs @@ -38,6 +38,7 @@ impl VgaWriter { self.buffer.write(row, col, byte); self.column_position += 1; + self.buffer.set_cursor_at(row, col); } } }