From e83717b454722b8c61844686377c2ac58f18454f Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Tue, 23 Aug 2022 20:56:57 -0700 Subject: Migrate the processor-independent code Due to the similarity with my ARM-based OS ghOSt, I am migrating similar code out to a common crate Not all has been moved out yet --- Cargo.toml | 3 ++- src/kernel.rs | 2 -- src/serial/buffer.rs | 12 +++++------- src/sync.rs | 3 +++ src/vga/buffer.rs | 38 +++----------------------------------- 5 files changed, 13 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 344823c..3b9d0c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,10 @@ bootloader = "0.9.8" volatile = "0.2.6" x86_64 = "0.14.2" uart_16550 = "0.2.0" +os_pic = {git="https://git.christiancunningham.xyz/os_pic.git"} [package.metadata.bootimage] #run-command = ["qemu-system-x86_64", "-drive", "format=raw,file={}", "-serial", "mon:stdio"] -run-args = ["-serial", "mon:stdio"] +run-args = ["-serial", "mon:stdio", "-display", "none"] test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "mon:stdio", "-display","none"] test-success-exit-code = 33 diff --git a/src/kernel.rs b/src/kernel.rs index c040a4b..57cc04f 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -57,8 +57,6 @@ pub extern "C" fn _start() -> ! { #[cfg(not(test))] { - WRITER.write_string("Hello World!"); - WRITER.write_string("\n\nHi\n"); println!("{}", 5); } diff --git a/src/serial/buffer.rs b/src/serial/buffer.rs index b0f704e..b52728a 100644 --- a/src/serial/buffer.rs +++ b/src/serial/buffer.rs @@ -12,13 +12,11 @@ impl Serial { } } -impl NullLock { - pub fn init(&self) { - self.lock(|serial| { - let mut serial_port = unsafe { SerialPort::new(0x3F8) }; - serial_port.init(); - serial.buffer = Some(serial_port); - }); +impl crate::sync::interface::Initializable for Serial { + fn init(&mut self) { + let mut serial_port = unsafe { SerialPort::new(0x3F8) }; + serial_port.init(); + self.buffer = Some(serial_port); } } diff --git a/src/sync.rs b/src/sync.rs index 5afa620..cb245da 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,3 +1,5 @@ +pub use os_pic::sync::*; +/* //! # Synchronization module //! //! Provides synchronization objects for thread-safe memory sharing. @@ -63,3 +65,4 @@ impl interface::Mutex for NullLock { f(data) } } +*/ diff --git a/src/vga/buffer.rs b/src/vga/buffer.rs index 1ae4ff8..2512123 100644 --- a/src/vga/buffer.rs +++ b/src/vga/buffer.rs @@ -86,36 +86,6 @@ impl VgaWriter { } } -impl NullLock { - #[allow(dead_code)] - pub fn write_byte(&self, byte: u8) { - self.lock(|writer| { - writer.write_byte(byte); - }); - } - - #[allow(dead_code)] - fn new_line(&self) { - self.lock(|writer| { - writer.new_line(); - }); - } - - #[allow(dead_code)] - fn clear_row(&self, row: usize) { - self.lock(|writer| { - writer.clear_row(row); - }); - } - - #[allow(dead_code)] - pub fn write_string(&self, s: &str) { - self.lock(|writer| { - writer.write_string(s); - }); - } -} - impl fmt::Write for VgaWriter { fn write_str(&mut self, s: &str) -> fmt::Result { self.write_string(s); @@ -123,11 +93,9 @@ impl fmt::Write for VgaWriter { } } -impl NullLock { - pub fn init(&self) { - self.lock(|writer| { - writer.buffer = Some(unsafe { &mut *(0xb8000 as *mut Buffer) }); - }) +impl crate::sync::interface::Initializable for VgaWriter { + fn init(&mut self) { + self.buffer = Some(unsafe { &mut *(0xb8000 as *mut Buffer) }); } } -- cgit v1.2.1