PS2 mouse/keyboard conflict

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Paul

PS2 mouse/keyboard conflict

Post by Paul »

I am writing an operating system. I have enabled IRQ1 (keyboard interrupt) and it accepted keystrokes just fine. Then when I enabled IRQ12 (mouse interrupt), the keyboard interrupt stopped responding. In case you have read my other post about a similar problem, please note that this is totally different. I am resetting the interrupt controllers just as I should after each ISR so I know that isn't the problem. I did notice that some garbage was received on both interrupts right at the beginning. Then the mouse interrupt continued to work but the keyboard interrupt stopped firing. There were a few occasions when I booted the computer and the keyboard interrupt worked just fine, but is not consistant. Does anyone know what the problem could be?
Friend

Re:PS2 mouse/keyboard conflict

Post by Friend »

Hi,

I dont know if this is your problem, but it is something that is a possibility and could happen.

If an exception fires during the execution of your IRQ and the exception pushes an error code and you do not pop that off in your exception handler, then the return address of you IRQ would be the error code pushed by the excpetion. Probably not your problem, but just a thought for you and anyone else who reads this post.

Might be able to help more if I see your mouse\keyboard IRQ code.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:PS2 mouse/keyboard conflict

Post by Pype.Clicker »

a.f.a.i.k., both keyboard (legacy or PS/2) and PS/2 mouse use the 8042 chip to communicate with the CPU. what could happen is

1. the ps/2 mouse moves, which makes the 8042 decode its signal internally.
2. the 8042 emits IRQ12 for the mouse
3. your handler for IRQ12 gets the execution, displays "mouse movement" but don't read on the 8042 (for instance because you haven't read about PS/2 mice communications and dunno what to do: you're just testing the interrupt)
4. your handler returns, freeing the 8259a

BUT the 8042 is still waiting the CPU to read its datas

5. when a keystroke occurs, the 8042 can't deliver it because its output buffer is still busy with the mouse datas, no IRQ1 is generated ...

i have the same problem with Clicker and came to the conclusion "don't enable mouse IRQs until you're able to process mouse datas on the PS/2"
Paul

Re:PS2 mouse/keyboard conflict

Post by Paul »

Hi,

Actually, I am processing the mouse data. Whenever
IRQ12 fires, my handler is reading 3-bytes from port
0x60 and these bytes seem to be correct cause my
mouse pointer works fine.... I'm getting the button
state and the MSB of the X and Y movement in byte
1, and i'm getting the X movement in byte 2 and y
movement in byte 3.

Then, for the keyboard interrupt, I'm reading just one
byte from 0x60.

AND, I'm enabling the PS/2 mouse interrupt before I turn
interrupts back on. (STI)

So, what could be the problem?
Tim

Re:PS2 mouse/keyboard conflict

Post by Tim »

You might be better off reading one byte per interrupt and doing processing every on every third interrupt, since the aux port gives you one IRQ12 per byte it sends.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:PS2 mouse/keyboard conflict

Post by Pype.Clicker »

isn't there something to do that will notify the 8042 the bytes have been read ?
Tim

Re:PS2 mouse/keyboard conflict

Post by Tim »

isn't there something to do that will notify the 8042 the bytes have been read ?
[me=Tim Robinson]looks up his PS/2 mouse driver[/me]

Apparently not.

Code: Select all

bool ps2Isr(device_t *dev, uint8_t irq)
{
    if ((in(KEYB_CTRL) & 0x01) != 0)
    {
   Ps2Mouse *mouse;
   mouse = (Ps2Mouse*) dev;
   mouse->data[mouse->bytes++] = in(KEYB_PORT);
   if (mouse->bytes >= 3 + mouse->has_wheel)
   {
       ps2StartIo(mouse);
       mouse->bytes = 0;
   }
   
   return true;
    }

    return false;
}
Here I'm just reading from port 0x60 as normal.

BTW, if anyone wants to look at this source: http://cvs.sourceforge.net/cgi-bin/view ... cvs-markup
Post Reply