mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Use volatile operations for accessing the VGA buffer
(cherry picked from commit d7a445b1bb)
This commit is contained in:
@@ -10,6 +10,7 @@ multiboot2 = "0.1.0"
|
|||||||
once = "0.2.1"
|
once = "0.2.1"
|
||||||
rlibc = "0.1.4"
|
rlibc = "0.1.4"
|
||||||
spin = "0.3.4"
|
spin = "0.3.4"
|
||||||
|
volatile = "0.1.0"
|
||||||
|
|
||||||
[dependencies.hole_list_allocator]
|
[dependencies.hole_list_allocator]
|
||||||
path = "libs/hole_list_allocator"
|
path = "libs/hole_list_allocator"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
|
extern crate volatile;
|
||||||
extern crate spin;
|
extern crate spin;
|
||||||
extern crate multiboot2;
|
extern crate multiboot2;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
use core::ptr::Unique;
|
use core::ptr::Unique;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
use volatile::Volatile;
|
||||||
|
|
||||||
const BUFFER_HEIGHT: usize = 25;
|
const BUFFER_HEIGHT: usize = 25;
|
||||||
const BUFFER_WIDTH: usize = 80;
|
const BUFFER_WIDTH: usize = 80;
|
||||||
@@ -50,8 +51,8 @@ pub unsafe fn print_error(fmt: fmt::Arguments) {
|
|||||||
writer.write_fmt(fmt);
|
writer.write_fmt(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
@@ -89,10 +90,12 @@ impl Writer {
|
|||||||
let row = BUFFER_HEIGHT - 1;
|
let row = BUFFER_HEIGHT - 1;
|
||||||
let col = self.column_position;
|
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,
|
ascii_character: byte,
|
||||||
color_code: self.color_code,
|
color_code: color_code,
|
||||||
};
|
});
|
||||||
self.column_position += 1;
|
self.column_position += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,9 +106,12 @@ impl Writer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new_line(&mut self) {
|
fn new_line(&mut self) {
|
||||||
for row in 0..(BUFFER_HEIGHT - 1) {
|
for row in 1..BUFFER_HEIGHT {
|
||||||
let buffer = self.buffer();
|
for col in 0..BUFFER_WIDTH {
|
||||||
buffer.chars[row] = buffer.chars[row + 1]
|
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.clear_row(BUFFER_HEIGHT - 1);
|
||||||
self.column_position = 0;
|
self.column_position = 0;
|
||||||
@@ -116,7 +122,9 @@ impl Writer {
|
|||||||
ascii_character: b' ',
|
ascii_character: b' ',
|
||||||
color_code: self.color_code,
|
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);
|
struct ColorCode(u8);
|
||||||
|
|
||||||
impl ColorCode {
|
impl ColorCode {
|
||||||
@@ -138,7 +146,7 @@ impl ColorCode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct ScreenChar {
|
struct ScreenChar {
|
||||||
ascii_character: u8,
|
ascii_character: u8,
|
||||||
@@ -146,5 +154,5 @@ struct ScreenChar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user