Use volatile operations for accessing the VGA buffer

(cherry picked from commit d7a445b1bb)
This commit is contained in:
Philipp Oppermann
2016-10-06 19:53:16 +02:00
parent a5c96a048e
commit 11516adc53
3 changed files with 21 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ multiboot2 = "0.1.0"
once = "0.3.2"
rlibc = "0.1.4"
spin = "0.3.4"
volatile = "0.1.0"
[dependencies.hole_list_allocator]
path = "libs/hole_list_allocator"

View File

@@ -16,6 +16,7 @@
#![no_std]
extern crate rlibc;
extern crate volatile;
extern crate spin;
extern crate multiboot2;
#[macro_use]

View File

@@ -10,6 +10,7 @@
use core::ptr::Unique;
use core::fmt;
use spin::Mutex;
use volatile::Volatile;
const BUFFER_HEIGHT: usize = 25;
const BUFFER_WIDTH: usize = 80;
@@ -50,8 +51,8 @@ pub unsafe fn print_error(fmt: fmt::Arguments) {
writer.write_fmt(fmt);
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum Color {
Black = 0,
@@ -89,10 +90,12 @@ impl Writer {
let row = BUFFER_HEIGHT - 1;
let col = self.column_position;
self.buffer().chars[row][col] = ScreenChar {
let color_code = self.color_code;
self.buffer().chars[row][col].write(ScreenChar {
ascii_character: byte,
color_code: self.color_code,
};
color_code: color_code,
});
self.column_position += 1;
}
}
@@ -103,9 +106,12 @@ impl Writer {
}
fn new_line(&mut self) {
for row in 0..(BUFFER_HEIGHT - 1) {
let buffer = self.buffer();
buffer.chars[row] = buffer.chars[row + 1]
for row in 1..BUFFER_HEIGHT {
for col in 0..BUFFER_WIDTH {
let buffer = self.buffer();
let character = buffer.chars[row][col].read();
buffer.chars[row - 1][col].write(character);
}
}
self.clear_row(BUFFER_HEIGHT - 1);
self.column_position = 0;
@@ -116,7 +122,9 @@ impl Writer {
ascii_character: b' ',
color_code: self.color_code,
};
self.buffer().chars[row] = [blank; BUFFER_WIDTH];
for col in 0..BUFFER_WIDTH {
self.buffer().chars[row][col].write(blank);
}
}
}
@@ -129,7 +137,7 @@ impl fmt::Write for Writer {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
struct ColorCode(u8);
impl ColorCode {
@@ -138,7 +146,7 @@ impl ColorCode {
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
#[repr(C)]
struct ScreenChar {
ascii_character: u8,
@@ -146,5 +154,5 @@ struct ScreenChar {
}
struct Buffer {
chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
}