From 019dca5e7d243a82c87de18c9784896d905ef2de Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Sat, 4 Dec 2021 22:57:51 +0100 Subject: [PATCH] fix(pit): fix interrupt race conditions Signed-off-by: Julien CLEMENT --- src/interrupts.rs | 3 +++ src/lib.rs | 8 +++++++- src/serial.rs | 11 +++++++---- src/vga.rs | 6 +++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index ac58e4b..48d05b9 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -66,4 +66,7 @@ extern "x86-interrupt" fn timer_interrupt_handler( _stack_frame: InterruptStackFrame) { print!("."); + unsafe { + PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8()); + } } diff --git a/src/lib.rs b/src/lib.rs index e7166c1..446e338 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,13 @@ use vga::{Color, ColorCode}; fn panic_handler(info: &PanicInfo) -> ! { vga::change_color(ColorCode::new(Color::LightRed, Color::Black)); println!("{}", info); - loop {} + hlt_loop(); +} + +pub fn hlt_loop() -> ! { + loop { + x86_64::instructions::hlt(); + } } pub fn init() { diff --git a/src/serial.rs b/src/serial.rs index 3a0e2fa..c2cc565 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -35,10 +35,13 @@ lazy_static! { #[doc(hidden)] pub fn _print(args: ::core::fmt::Arguments) { use core::fmt::Write; - SERIAL1 - .lock() - .write_fmt(args) - .expect("Printing to serial failed"); + use x86_64::instructions::interrupts; + interrupts::without_interrupts(|| { + SERIAL1 + .lock() + .write_fmt(args) + .expect("Printing to serial failed"); + }); } /// Prints to the host through the serial interface. diff --git a/src/vga.rs b/src/vga.rs index b5b9d9b..0cdf0b7 100644 --- a/src/vga.rs +++ b/src/vga.rs @@ -28,7 +28,11 @@ macro_rules! println { #[doc(hidden)] pub fn _print(args: fmt::Arguments) { use core::fmt::Write; - WRITER.lock().write_fmt(args).unwrap(); + use x86_64::instructions::interrupts; + + interrupts::without_interrupts(|| { + WRITER.lock().write_fmt(args).unwrap(); + }); } pub fn change_color(color: ColorCode) { WRITER.lock().change_color(color)