diff --git a/Cargo.lock b/Cargo.lock index 40ce4f0..20cb404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,8 @@ name = "KarxOS" version = "0.1.0" dependencies = [ "bootloader", + "lazy_static", + "spin", "volatile", ] @@ -16,6 +18,21 @@ version = "0.9.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7c452074efc3c0bfb241fb7bc87df04741c7c85e926f6a07c05f8fbd6008240" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "volatile" version = "0.2.7" diff --git a/Cargo.toml b/Cargo.toml index a33ecea..436089f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ edition = "2018" [dependencies] bootloader = "0.9.8" volatile = "0.2.6" +spin = "0.5.2" + +[dependencies.lazy_static] +version = "1.0" +features = ["spin_no_std"] diff --git a/src/main.rs b/src/main.rs index 8ced2f5..e3550ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,9 @@ fn panic(_info: &PanicInfo) -> ! { #[no_mangle] pub extern "C" fn _start() -> ! { - vga_buffer::print_something(); + use core::fmt::Write; + vga_buffer::WRITER.lock().write_str("Hello there\n").unwrap(); + writeln!(vga_buffer::WRITER.lock(), "General Kenobi").unwrap(); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index b9e76d7..79b1a87 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -1,5 +1,7 @@ use volatile::Volatile; use core::fmt; +use lazy_static::lazy_static; +use spin::Mutex; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -118,16 +120,11 @@ impl fmt::Write for Writer { } } -pub fn print_something() { - use core::fmt::Write; - let mut writer = Writer { +lazy_static! { + pub static ref WRITER: Mutex = Mutex::new(Writer { column_position: 0, color_code: ColorCode::new(Color::White, Color::Black), buffer: unsafe { &mut *(0xb8000 as *mut Buffer) } - }; - - writeln!(writer, "Hello world!").unwrap(); - writeln!(writer, "Hello again!").unwrap(); - + }); }