diff --git a/src/interrupts/mod.rs b/src/interrupts/mod.rs index abec001e..2a0223ea 100644 --- a/src/interrupts/mod.rs +++ b/src/interrupts/mod.rs @@ -72,21 +72,17 @@ struct ExceptionStackFrame { stack_segment: u64, } -use vga_buffer::print_error; - extern "C" fn divide_by_zero_handler(stack_frame: *const ExceptionStackFrame) -> ! { - unsafe { - print_error(format_args!("EXCEPTION: DIVIDE BY ZERO\n{:#?}", *stack_frame)); - } + let stack_frame = unsafe { &*stack_frame }; + println!("\nEXCEPTION: DIVIDE BY ZERO\n{:#?}", stack_frame); loop {} } extern "C" fn invalid_opcode_handler(stack_frame: *const ExceptionStackFrame) -> ! { - unsafe { - print_error(format_args!("EXCEPTION: INVALID OPCODE at {:#x}\n{:#?}", - (*stack_frame).instruction_pointer, - *stack_frame)); - } + let stack_frame = unsafe { &*stack_frame }; + println!("\nEXCEPTION: INVALID OPCODE at {:#x}\n{:#?}", + stack_frame.instruction_pointer, + stack_frame); loop {} } @@ -101,13 +97,12 @@ bitflags! { } extern "C" fn page_fault_handler(stack_frame: *const ExceptionStackFrame, error_code: u64) -> ! { + let stack_frame = unsafe { &*stack_frame }; use x86::controlregs; - unsafe { - print_error(format_args!("EXCEPTION: PAGE FAULT while accessing {:#x}\nerror code: \ + println!("\nEXCEPTION: PAGE FAULT while accessing {:#x}\nerror code: \ {:?}\n{:#?}", - controlregs::cr2(), - PageFaultErrorCode::from_bits(error_code).unwrap(), - *stack_frame)); - } + unsafe { controlregs::cr2() }, + PageFaultErrorCode::from_bits(error_code).unwrap(), + stack_frame); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 1d9d117e..e3cc06cc 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -43,18 +43,6 @@ pub fn clear_screen() { } } -pub unsafe fn print_error(fmt: fmt::Arguments) { - use core::fmt::Write; - - let mut writer = Writer { - column_position: 0, - color_code: ColorCode::new(Color::Red, Color::Black), - buffer: Unique::new(0xb8000 as *mut _), - }; - writer.new_line(); - writer.write_fmt(fmt); -} - #[allow(dead_code)] #[derive(Debug, Clone, Copy)] #[repr(u8)]