From 8a3e3a2324fd59039c7a4ad4a21062048f10853b Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 12 Apr 2018 15:49:37 +0200 Subject: [PATCH] cursor.rs, no more cpuio in vga --- kernel-rs/src/vga/cursor.rs | 30 ++++++++++++++++++++++++++++++ kernel-rs/src/vga/mod.rs | 13 +++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 kernel-rs/src/vga/cursor.rs diff --git a/kernel-rs/src/vga/cursor.rs b/kernel-rs/src/vga/cursor.rs new file mode 100644 index 00000000..850c45cc --- /dev/null +++ b/kernel-rs/src/vga/cursor.rs @@ -0,0 +1,30 @@ +// https://wiki.osdev.org/Text_Mode_Cursor +// Protected mode cursor abstraction + +use io::{Io, Pio}; + +pub static mut CURSOR: Cursor = Cursor::new(0x3D4); + +pub struct Cursor { + cmd: Pio, + data: Pio, +} + +impl Cursor { + pub const fn new(port: u16) -> Cursor { + Cursor { + cmd: Pio::new(port), + data: Pio::new(port + 1), + } + } + + pub fn flush(&mut self, position: usize) { + // 14 awaits the rightmost 8bits + self.cmd.write(14); + self.data.write((position >> 8) as u8 & 0xff); + + // 15 awaits the leftmost 8bits + self.cmd.write(15); + self.data.write((position >> 0) as u8 & 0xff); + } +} diff --git a/kernel-rs/src/vga/mod.rs b/kernel-rs/src/vga/mod.rs index 9b5c780e..1a2dedc8 100644 --- a/kernel-rs/src/vga/mod.rs +++ b/kernel-rs/src/vga/mod.rs @@ -1,8 +1,9 @@ pub mod color; +pub mod cursor; pub use self::color::{Color, ColorCode}; +use self::cursor::CURSOR; -use cpuio; use console; pub static mut VGA: Writer = self::Writer::new(); @@ -156,13 +157,9 @@ impl Writer { } fn flush_cursor(&self) { - let cursor_position = self.buffer_pos / 2; - // 14 awaits the rightmost 8bits - cpuio::outb(0x3D4, 14); - cpuio::outb(0x3D5, (cursor_position >> 8) as u8); - // 15 awaits the leftmost 8bits - cpuio::outb(0x3D4, 15); - cpuio::outb(0x3D5, (cursor_position >> 0) as u8 & 0x00ff); + unsafe { + CURSOR.flush(self.buffer_pos / 2); + } } pub fn flush(&mut self) {