diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-11-27 01:46:33 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-11-27 01:46:33 +0100 |
commit | 2701fe07b4c8c9b6a36112c98fbfc900acbd6cf3 (patch) | |
tree | d8b6d0c2ba3f79110a5c3b0c885749a14b8de25d | |
parent | 0cb231bd3de9bcd4c39064399211fbd2fbc6237e (diff) |
-rw-r--r-- | kernel/src/interrupts/idt.rs | 2 | ||||
-rw-r--r-- | kernel/src/interrupts/interrupt_handlers.rs | 12 | ||||
-rw-r--r-- | kernel/src/lib.rs | 1 | ||||
-rw-r--r-- | kernel/src/main.rs | 2 | ||||
-rw-r--r-- | kernel/src/testing/panic.rs | 5 |
5 files changed, 19 insertions, 3 deletions
diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs index e41f957..c901916 100644 --- a/kernel/src/interrupts/idt.rs +++ b/kernel/src/interrupts/idt.rs @@ -26,6 +26,8 @@ lazy_static! { .set_stack_index(gdt::PAGE_FAULT_IST_INDEX); } idt[InterruptType::Timer.as_usize()].set_handler_fn(interrupt_handlers::timer_handler); + idt[InterruptType::Keyboard.as_usize()] + .set_handler_fn(interrupt_handlers::keyboard_handler); idt }; diff --git a/kernel/src/interrupts/interrupt_handlers.rs b/kernel/src/interrupts/interrupt_handlers.rs index 4624723..e7af0e1 100644 --- a/kernel/src/interrupts/interrupt_handlers.rs +++ b/kernel/src/interrupts/interrupt_handlers.rs @@ -1,11 +1,21 @@ use super::InterruptType; use crate::io::qemu; +use core::fmt::Write; use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode}; +use x86_64::structures::port; pub extern "x86-interrupt" fn timer_handler(stack_frame: &mut InterruptStackFrame) { - panic!("Timer interrupt recieved\n\n"); + write!(crate::io::vga_text::OStream::new(), "Timer"); if let Some(apic) = unsafe { super::apic::get_local_apic() } { apic.end_of_interrupt() } } + +pub extern "x86-interrupt" fn keyboard_handler(stack_frame: &mut InterruptStackFrame) { + let code: u8 = unsafe { port::PortRead::read_from_port(0x60) }; + write!(crate::io::vga_text::OStream::new(), "{}", code); + if let Some(apic) = unsafe { super::apic::get_local_apic() } { + apic.end_of_interrupt() + } +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index adf14b4..f03ef36 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,5 +1,4 @@ #![no_main] -#![feature(compiler_builtins_lib)] #![feature(custom_test_frameworks)] #![feature(abi_x86_interrupt)] #![feature(panic_info_message)] diff --git a/kernel/src/main.rs b/kernel/src/main.rs index c6c00c2..8b21eef 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -1,5 +1,4 @@ #![no_main] -#![feature(compiler_builtins_lib)] #![feature(custom_test_frameworks)] #![feature(abi_x86_interrupt)] #![feature(panic_info_message)] @@ -32,6 +31,7 @@ extern "C" fn _start() -> ! { let mut stdout = OStream::new(); stdout.print(b"apic initialisation complete\n"); + x86_64::instructions::interrupts::int3(); if cfg!(test) { qemu::exit_qemu(qemu::QemuExitCode::Success); diff --git a/kernel/src/testing/panic.rs b/kernel/src/testing/panic.rs index 729a45f..de07ba8 100644 --- a/kernel/src/testing/panic.rs +++ b/kernel/src/testing/panic.rs @@ -4,8 +4,10 @@ use core::panic::PanicInfo; use qemu::{exit_qemu, QemuExitCode}; use serial::SerialStream; use vga_text::OStream; +use x86_64::instructions::interrupts; pub fn serial_should_panic(info: &PanicInfo) -> ! { + interrupts::disable(); let mut stdout = SerialStream::new(); write!(stdout, "\nOK\nsuccessfully panicked\n").unwrap(); exit_qemu(QemuExitCode::Success); @@ -13,6 +15,7 @@ pub fn serial_should_panic(info: &PanicInfo) -> ! { } pub fn serial_panic(info: &PanicInfo) -> ! { + interrupts::disable(); crate::io::panic_screen::show(info.message()); let mut stdout = SerialStream::new(); write!( @@ -26,11 +29,13 @@ pub fn serial_panic(info: &PanicInfo) -> ! { } pub fn should_panic(_info: &PanicInfo) -> ! { + interrupts::disable(); exit_qemu(QemuExitCode::Success); loop {} } pub fn panic(info: &PanicInfo) -> ! { + interrupts::disable(); crate::io::panic_screen::show(info.message()); loop {} } |