fix(pit): fix interrupt race conditions

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2021-12-04 22:57:51 +01:00
parent 618e528f35
commit 019dca5e7d
4 changed files with 22 additions and 6 deletions

@ -66,4 +66,7 @@ extern "x86-interrupt" fn timer_interrupt_handler(
_stack_frame: InterruptStackFrame) _stack_frame: InterruptStackFrame)
{ {
print!("."); print!(".");
unsafe {
PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
}
} }

@ -14,7 +14,13 @@ use vga::{Color, ColorCode};
fn panic_handler(info: &PanicInfo) -> ! { fn panic_handler(info: &PanicInfo) -> ! {
vga::change_color(ColorCode::new(Color::LightRed, Color::Black)); vga::change_color(ColorCode::new(Color::LightRed, Color::Black));
println!("{}", info); println!("{}", info);
loop {} hlt_loop();
}
pub fn hlt_loop() -> ! {
loop {
x86_64::instructions::hlt();
}
} }
pub fn init() { pub fn init() {

@ -35,10 +35,13 @@ lazy_static! {
#[doc(hidden)] #[doc(hidden)]
pub fn _print(args: ::core::fmt::Arguments) { pub fn _print(args: ::core::fmt::Arguments) {
use core::fmt::Write; use core::fmt::Write;
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
SERIAL1 SERIAL1
.lock() .lock()
.write_fmt(args) .write_fmt(args)
.expect("Printing to serial failed"); .expect("Printing to serial failed");
});
} }
/// Prints to the host through the serial interface. /// Prints to the host through the serial interface.

@ -28,7 +28,11 @@ macro_rules! println {
#[doc(hidden)] #[doc(hidden)]
pub fn _print(args: fmt::Arguments) { pub fn _print(args: fmt::Arguments) {
use core::fmt::Write; use core::fmt::Write;
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
WRITER.lock().write_fmt(args).unwrap(); WRITER.lock().write_fmt(args).unwrap();
});
} }
pub fn change_color(color: ColorCode) { pub fn change_color(color: ColorCode) {
WRITER.lock().change_color(color) WRITER.lock().change_color(color)