From: HimbeerserverDE Date: Sun, 18 Sep 2022 16:49:37 +0000 (+0200) Subject: Global vga::Writer X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=fe4c3320fc0626c864d1a622f508c2cf6b8fa1ae;p=loadnothing.git Global vga::Writer --- diff --git a/stage2/Cargo.toml b/stage2/Cargo.toml index 730ba62..4add51d 100644 --- a/stage2/Cargo.toml +++ b/stage2/Cargo.toml @@ -16,4 +16,6 @@ lto = true codegen-units = 1 [dependencies] +lazy_static = { version = "1.0", features = ["spin_no_std"] } volatile = "0.4.5" +spin = "0.9.4" diff --git a/stage2/src/main.rs b/stage2/src/main.rs index 5e519f7..d05e3b2 100644 --- a/stage2/src/main.rs +++ b/stage2/src/main.rs @@ -14,7 +14,7 @@ fn panic(_info: &PanicInfo) -> ! { #[no_mangle] pub extern "C" fn _start() -> ! { - vga::test_print(); + vga::WRITER.lock().write_string("Hello Stage2!"); unsafe { loop { diff --git a/stage2/src/vga.rs b/stage2/src/vga.rs index 901b91a..f20dec7 100644 --- a/stage2/src/vga.rs +++ b/stage2/src/vga.rs @@ -1,6 +1,8 @@ use core::ops::{AddAssign, Deref, DerefMut, Shl, Sub}; +use lazy_static::lazy_static; use volatile::Volatile; +use spin::Mutex; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -135,13 +137,11 @@ impl Writer { } } -pub fn test_print() { - let mut writer = Writer { +lazy_static! { + pub static ref WRITER: Mutex = Mutex::new(Writer { row_position: 1, column_position: 0, - color_code: ColorCode::new(Color::Yellow, Color::Black), + color_code: ColorCode::new(Color::LightGray, Color::Black), buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, - }; - - writer.write_string("Hello Stage2!"); + }); }