summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-10-31 21:24:16 +0100
committerDennis Kobert <dennis@kobert.dev>2019-10-31 21:24:16 +0100
commita6e19a2f1de622f98d91523b58c95fe3999aea20 (patch)
tree5ff24817a9d81f2187d11024b73032b3bad92cc2
parent6c09097e5441eafc971c8d5d414963a4e66a892f (diff)
Add x86_64 crate
-rw-r--r--kernel/Cargo.toml3
-rw-r--r--kernel/src/io/serial.rs3
-rw-r--r--kernel/src/io/vga_text.rs32
-rw-r--r--kernel/src/lib.rs2
4 files changed, 24 insertions, 16 deletions
diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml
index 2b883f4..e14865e 100644
--- a/kernel/Cargo.toml
+++ b/kernel/Cargo.toml
@@ -11,6 +11,9 @@ crate-type = ["staticlib"]
[package.metadata.cargo-xbuild]
sysroot_path = "target/sysroot"
+[dependencies]
+x86_64 = "0.7.5"
+
[dependencies.compiler_builtins]
version = "0.1.19"
git = "https://github.com/rust-lang/compiler-builtins"
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;
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 92ce010..8d8ec17 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -4,7 +4,7 @@
extern crate compiler_builtins;
-mod vga_text;
+mod io;
use core::fmt::Write;