I cant get PIC8259 to work properly!

I recently started working on a operating system using the limine bootloader.

i wanted to be able to get keyboard input through PIC8259 and i found a example in the phill opp blog,
i made the following code below but it doesnt seem to ever call the handlers for some reason,
i have been working on this problem for a while and i also implemented serial ports just so i can be sure that it never calls.

use core::fmt::Write;

static PICS: Mutex<ChainedPics> = Mutex::new(unsafe { ChainedPics::new(32, 40) });

lazy_static! {
    static ref IDT: InterruptDescriptorTable = {
        let mut idt = InterruptDescriptorTable::new();

        idt.breakpoint.set_handler_fn(breakpoint);
        idt.double_fault.set_handler_fn(double_fault);
        idt[32].set_handler_fn(timer_interrupt);
        idt[33].set_handler_fn(keyboard_interrupt);

        return idt;
    };
}

pub fn init() {
    IDT.load();

    unsafe {
        PICS.lock().initialize();
    }

    x86_64::instructions::interrupts::enable();
}


extern "x86-interrupt" fn keyboard_interrupt(_stack_frame: InterruptStackFrame) {
    DEBUG.lock().write("[debug] keyboard interrupt\n");

    unsafe {
        PICS.lock().notify_end_of_interrupt(33);
    }
}

extern "x86-interrupt" fn timer_interrupt(_stack_frame: InterruptStackFrame) {
    DEBUG.lock().write("[debug] timer interrupt\n");

    if let Some(tty) = unsafe { KERNEL_TTY.lock().as_mut() } {
        tty.write(".");

        tty.render();
    }

    unsafe {
        PICS.lock().notify_end_of_interrupt(32);
    }
}

if anyone has a clue it would help allot if yall give me some help!

did you use this:

[dependencies.lazy_static]
version = "1.0"
features = ["spin_no_std"]

I guess it won't even compile without it, hmm.. forget I said anything.

I guess for some reason you don't need the gdt ?
that

pub fn init() {
    gdt::init();

part in your link

thanks for the reply, i figured it out later the problem was that all the masks where disabled by default for some reason the problem got fixed simply by doing

    unsafe {
        PICS.lock().initialize();

        PICS.lock().write_masks(0, 0);
    }

in order to enable all masks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.