summaryrefslogtreecommitdiff
path: root/kernel/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/io')
-rw-r--r--kernel/src/io/serial.rs3
-rw-r--r--kernel/src/io/vga_text.rs32
2 files changed, 20 insertions, 15 deletions
diff --git a/kernel/src/io/serial.rs b/kernel/src/io/serial.rs
index bab770d..e1d4660 100644
--- a/kernel/src/io/serial.rs
+++ b/kernel/src/io/serial.rs
@@ -14,9 +14,8 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
}
}
-#[test_case]
fn trivial_assertion() {
- use crate::vga_text::OStream;
+ use crate::io::vga_text::OStream;
let mut stdout = OStream::new();
stdout.clear();
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index f60e6e1..b6715fd 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -18,8 +18,8 @@ pub enum Color {
White = 15,
}
-pub const WIDTH = 80;
-pub const HEIGHT = 25;
+pub const WIDTH: usize = 80;
+pub const HEIGHT: usize = 25;
#[derive(Clone, Copy)]
pub struct CharState(pub u8);
@@ -47,7 +47,7 @@ pub struct VgaChar {
impl VgaChar {
pub fn from_state_and_byte(state: CharState, byte: u8) -> Self {
- Self{ state, byte }
+ Self { state, byte }
}
}
@@ -62,12 +62,12 @@ impl OStream {
Self {
pos: (0, 0),
cursor: Self::at(0),
- state: CharState::from_colors(Color::White, Color::Black)
+ state: CharState::from_colors(Color::White, Color::Black),
}
}
fn at(n: usize) -> *mut VgaChar {
- (0xbWIDTH00 + (n << 1)) as *mut VgaChar
+ (0xb8000 + (n << 1)) as *mut VgaChar
}
fn compute_cursor(&mut self) {
@@ -78,19 +78,21 @@ impl OStream {
self.pos.0 = core::cmp::min(col, WIDTH - 1);
self.compute_cursor()
}
-
pub fn set_row(&mut self, row: u8) {
self.pos.1 = core::cmp::min(row, HEIGHT - 1);
self.compute_cursor()
}
pub fn set_cursor(&mut self, col: u8, row: u8) {
- self.pos = (core::cmp::min(col, WIDTH - 1), core::cmp::min(row, HEIGHT - 1));
+ self.pos = (
+ core::cmp::min(col, WIDTH - 1),
+ core::cmp::min(row, HEIGHT - 1),
+ );
self.compute_cursor()
}
pub fn set_char(&mut self, c: VgaChar) {
- unsafe {self.cursor.write_volatile(c)}
+ unsafe { self.cursor.write_volatile(c) }
}
pub fn put_char(&mut self, c: VgaChar) {
@@ -113,7 +115,7 @@ impl OStream {
pub fn clear(&self) {
let c = VgaChar::from_state_and_byte(self.state, b' ');
for i in 0..(WIDTH * HEIGHT) {
- unsafe {Self::at(i).write_volatile(c)}
+ unsafe { Self::at(i).write_volatile(c) }
}
}
@@ -121,7 +123,7 @@ impl OStream {
if self.pos.1 >= HEIGHT - 1 {
self.set_col(0);
for i in 0..1920 {
- unsafe {Self::at(i).write_volatile(*Self::at(i + WIDTH))}
+ unsafe { Self::at(i).write_volatile(*Self::at(i + WIDTH)) }
}
} else {
self.set_cursor(0, self.pos.1 + 1);
@@ -150,12 +152,16 @@ impl OStream {
n = 0;
}
if b == b'\n' || i == slast {
- if b != b'\n' { n += 1 }
+ if b != b'\n' {
+ n += 1
+ }
self.set_col(((WIDTH - n) / 2) as u8);
self.print(&line[..n]);
self.new_line();
- if i == slast { return; }
- line = &line[(n+1)..];
+ if i == slast {
+ return;
+ }
+ line = &line[(n + 1)..];
n = 0;
}
n += 1;