keyboard now works with interrupts, cool

This commit is contained in:
Jack Halford 2018-04-05 13:16:04 +02:00
parent 0f79f2843c
commit 4885defefa
7 changed files with 101 additions and 90 deletions

View file

@ -28,7 +28,7 @@ pub fn cpu_info() -> Result {
}
if let Some(info) = cpuid.get_feature_info() {
print!("Features:");
print!("CPU Features:");
if info.has_fpu() { print!(" fpu") };
if info.has_vme() { print!(", vme") };
if info.has_de() { print!(", de") };

View file

@ -36,13 +36,14 @@ pub unsafe fn init() {
MASTER.data.write(master_mask); wait();
SLAVE.data.write(slave_mask); wait();
println!("master={:#b}", MASTER.data.read());
println!("slave ={:#b}", SLAVE.data.read());
println!("master={:#x}", MASTER.data.read());
println!("slave ={:#x}", SLAVE.data.read());
unsafe { ::arch::x86::interrupt::irq::trigger(1); }
MASTER.mask_set(0);
MASTER.mask_clear(1);
println!("master={:#b}", MASTER.data.read());
println!("slave ={:#b}", SLAVE.data.read());
// asm!("sti");
::x86::instructions::interrupts::enable();
}
pub struct Pic {

View file

@ -1,24 +1,59 @@
// https://wiki.osdev.org/Exceptions
macro_rules! exception {
($name:ident, $func:block) => {
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
{
println!("Exception: {}", stringify!($name));
println!("{:#?}", stack_frame);
flush!();
#[allow(unused_variables)]
fn inner(stack: &mut ExceptionStackFrame) {
$func
}
inner(stack_frame);
}
}
}
macro_rules! exception_err {
($name:ident, $func:block) => {
pub extern "x86-interrupt" fn $name(
stack_frame: &mut ExceptionStackFrame, _error_code: u32)
{
println!("Exception: {}", stringify!($name));
println!("{:#?}", stack_frame);
flush!();
#[allow(unused_variables)]
fn inner(stack: &mut ExceptionStackFrame) {
$func
}
inner(stack_frame);
}
}
}
use x86::structures::idt::*;
interrupt!(divide_by_zero, {});
interrupt!(debug, {});
interrupt!(non_maskable, {});
interrupt!(breakpoint, {
exception!(divide_by_zero, {});
exception!(debug, {});
exception!(non_maskable, {});
exception!(breakpoint, {
println!("testing here dont mind me");
flush!();
});
interrupt!(overflow, {});
interrupt!(bound_range, {});
interrupt!(invalid_opcode, {});
interrupt!(device_not_available, {});
interrupt_err!(double_fault, {});
interrupt!(coprocessor_segment_overrun, {});
interrupt_err!(invalid_tss, {});
interrupt_err!(segment_not_present, {});
interrupt_err!(stack_segment, {});
interrupt_err!(general_protection, {});
exception!(overflow, {});
exception!(bound_range, {});
exception!(invalid_opcode, {});
exception!(device_not_available, {});
exception_err!(double_fault, {});
exception!(coprocessor_segment_overrun, {});
exception_err!(invalid_tss, {});
exception_err!(segment_not_present, {});
exception_err!(stack_segment, {});
exception_err!(general_protection, {});
pub extern "x86-interrupt" fn page_fault(
stack_frame: &mut ExceptionStackFrame, code: PageFaultErrorCode)
@ -29,9 +64,9 @@ pub extern "x86-interrupt" fn page_fault(
flush!();
}
interrupt!(x87_fpu, {});
interrupt_err!(alignment_check, {});
interrupt!(machine_check, {});
interrupt!(simd, {});
interrupt!(virtualization, {});
interrupt_err!(security, {});
exception!(x87_fpu, {});
exception_err!(alignment_check, {});
exception!(machine_check, {});
exception!(simd, {});
exception!(virtualization, {});
exception_err!(security, {});

View file

@ -1,6 +1,22 @@
use x86::structures::idt::*;
use arch::x86::device::pic;
#[macro_export]
macro_rules! interrupt {
($i:expr, $name:ident, $func:block) => {
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
{
unsafe { trigger(1); }
#[allow(unused_variables)]
fn inner(stack: &mut ExceptionStackFrame) {
$func
}
inner(stack_frame);
unsafe { acknowledge(1); }
}
}
}
pub unsafe fn trigger(irq: u8) {
if irq < 16 {
if irq >= 8 {
@ -18,34 +34,31 @@ pub unsafe fn acknowledge(irq: usize) {
if irq < 16 {
if irq >= 8 {
pic::SLAVE.mask_clear(irq as u8 - 8);
pic::SLAVE.ack();
} else {
pic::MASTER.mask_clear(irq as u8);
pic::MASTER.ack();
}
}
}
interrupt!(pit, {});
interrupt!(0, pit, {});
interrupt!(keyboard, {
unsafe { trigger(1); }
println!("IT WOOOOOOOOOORKS WOUHOU!!!!!!");
flush!();
unsafe { acknowledge(1); }
interrupt!(1, keyboard, {
::keyboard::kbd_callback();
});
interrupt!(cascade, {});
interrupt!(com2, {});
interrupt!(com1, {});
interrupt!(lpt2, {});
interrupt!(floppy, {});
interrupt!(lpt1, {});
interrupt!(rtc, {});
interrupt!(pci1, {});
interrupt!(pci2, {});
interrupt!(pci3, {});
interrupt!(mouse, {});
interrupt!(fpu, {});
interrupt!(ata1, {});
interrupt!(ata2, {});
interrupt!(2, cascade, {});
interrupt!(3, com2, {});
interrupt!(4, com1, {});
interrupt!(5, lpt2, {});
interrupt!(6, floppy, {});
interrupt!(7, lpt1, {});
interrupt!(8, rtc, {});
interrupt!(9, pci1, {});
interrupt!(10, pci2, {});
interrupt!(11, pci3, {});
interrupt!(12, mouse, {});
interrupt!(13, fpu, {});
interrupt!(14, ata1, {});
interrupt!(15, ata2, {});

View file

@ -1,36 +0,0 @@
#[macro_export]
macro_rules! interrupt {
($name:ident, $func:block) => {
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
{
println!("Exception: {}", stringify!($name));
println!("{:#?}", stack_frame);
flush!();
#[allow(unused_variables)]
fn inner(stack: &mut ExceptionStackFrame) {
$func
}
inner(stack_frame);
}
}
}
#[macro_export]
macro_rules! interrupt_err {
($name:ident, $func:block) => {
pub extern "x86-interrupt" fn $name(
stack_frame: &mut ExceptionStackFrame, _error_code: u32)
{
println!("Exception: {}", stringify!($name));
println!("{:#?}", stack_frame);
flush!();
#[allow(unused_variables)]
fn inner(stack: &mut ExceptionStackFrame) {
$func
}
inner(stack_frame);
}
}
}

View file

@ -1,15 +1,14 @@
extern crate x86;
#[macro_use]
pub mod macros;
pub mod paging;
pub mod interrupt;
pub mod device;
pub mod idt;
use multiboot2;
use acpi;
use raw_cpuid::CpuId;
#[no_mangle]
pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {

View file

@ -14,7 +14,8 @@
#![feature(abi_x86_interrupt)]
extern crate rlibc;
#[macro_use] extern crate alloc;
// #[macro_use]
extern crate alloc;
#[macro_use] extern crate lazy_static;
extern crate spin;
extern crate multiboot2;
@ -45,9 +46,7 @@ pub mod arch;
/// kernel entry point. arch module is responsible for calling this
pub fn kmain() -> ! {
// x86::instructions::interrupts::disable();
x86::instructions::interrupts::int3();
// x86::instructions::interrupts::enable();
// x86::instructions::interrupts::int3();
// fn stack_overflow() { stack_overflow(); }
// stack_overflow();