Page 1 of 1

Cant get PS2 Mouse interrupt to work

Posted: Tue May 09, 2023 12:57 pm
by VirtualException
Hi,
I tried implementing an interrupt handler for the mouse in my x64 OS.
The code is the same as SANiK's one, but the interrupt handler is already "installed".
All the IDT stuff is working fine (both the keyboard and PIT work fine even in real hardware).
The only thing i do with the PIC is remapping it, as the wiki says
Maybe I am missing something with the init code:

Code: Select all

void ps2mouse_setup() {

    // Unmask the pic
    uint8_t oldpic = inb(PIC2_DATA);
    outb(PIC2_DATA, oldpic & (~PIC_PS2MOUSE_IRQ)); // PIC_PS2MOUSE_IRQ = 0b00010000

    uint8_t status;

    //Enable the auxiliary mouse device
    ps2mouse_wait(1);
    outportb(0x64, 0xA8);

    //Enable the interrupts
    ps2mouse_wait(1);
    outportb(0x64, 0x20);
    ps2mouse_wait(0);
    status = (inportb(0x60) | 2);
    ps2mouse_wait(1);
    outportb(0x64, 0x60);
    ps2mouse_wait(1);
    outportb(0x60, status);

    //Tell the mouse to use default settings
    ps2mouse_write(0xF6);
    ps2mouse_read();  //Acknowledge

    //Enable the mouse
    ps2mouse_write(0xF4);
    ps2mouse_read();  //Acknowledge

    return;
}
The handler never [-X fires. I tried with different tutorials, but i get no interrupt: the only thing that changes is that the keyboard stops working.

Re: Cant get PS2 Mouse interrupt to work

Posted: Tue May 09, 2023 6:21 pm
by Octocontrabass
Without seeing more of your code it's hard to say for sure, but it sounds like you didn't unmask IRQ2 in the interrupt controller. You can't receive IRQ12 if IRQ2 is masked.

It's a good idea to separate your mouse driver from your PS/2 controller driver. Right now, your mouse driver is directly manipulating the PS/2 controller, which can interfere with the keyboard.

Re: Cant get PS2 Mouse interrupt to work

Posted: Wed May 10, 2023 5:13 am
by VirtualException
That was it! I needed to unmask IRQ2:

Code: Select all

uint8_t oldpic1 = inb(PIC1_DATA);
outb(PIC1_DATA, oldpic1 & (~0b00000100)); // IRQ2
Right now the mouse and keyboard drivers are a mess, so I will take ur advice, thx!