Skip to content

Commit

Permalink
QEMU looping;
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelZalla committed Apr 17, 2024
1 parent 6ce43c5 commit 78d507c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
bootloader = "0.9"
spin = "0.9.8"
volatile = "0.2.6"
volatile = "0.5.2"

[dependencies.lazy_static]
version = "1.4.0"
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use core::panic::PanicInfo;
mod vga_buffer;

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
fn panic(_info: &PanicInfo) -> ! {
vga_buffer::print_something();

loop {}
}

#[no_mangle]
pub extern "C" fn _start() -> ! {
println!("Hello world{}", "!");

panic!("Some panic message");
}
34 changes: 8 additions & 26 deletions src/vga_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use core::fmt;

use volatile::Volatile;

use lazy_static::lazy_static;

use spin::Mutex;
use volatile::VolatilePtr;

#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -50,7 +46,7 @@ const BUFFER_WIDTH: usize = 80;

#[repr(transparent)]
struct Buffer {
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
chars: [[VolatilePtr<'static, ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
}

pub struct Writer {
Expand Down Expand Up @@ -128,28 +124,14 @@ impl fmt::Write for Writer {
}
}

lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
pub fn print_something() {
let mut writer = Writer {
column_position: 0,
color_code: ColorCode::new(Color::Yellow, Color::Black),
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
});
}

#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::vga_buffer::_print(format_args!($($arg)*)));
}

#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}

#[doc(hidden)]
pub fn _print(args: fmt::Arguments) {
use core::fmt::Write;
};

WRITER.lock().write_fmt(args).unwrap();
writer.write_byte(b'H');
writer.write_string("ello ");
writer.write_string("Wörld!");
}

0 comments on commit 78d507c

Please sign in to comment.