PS/2 Mouse IRQ Problem

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.
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

PS/2 Mouse IRQ Problem

Post by inixsoftware »

I started writing an driver for the PS/2 mouse. I know that QEMU does emulate it, so I wanted to make the driver. However, I can't get IRQs for it to work. (My other IRQS - like keyboard and PIT work fine). First, I send the mouse: 0xF4 and I get an ACK, so all should be well.

Next, I add an IRQ handler for it, but, it never gets called, so, the mouse isn't generating interrupts. Am I missing something after sending the mouse 0xF4 to tell it to send interrupts?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: PS/2 Mouse IRQ Problem

Post by gerryg400 »

You also need to enable mouse interrupts by setting b1 in the config byte.
If a trainstation is where trains stop, what is a workstation ?
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 Mouse IRQ Problem

Post by inixsoftware »

OK. Thanks! So, basically, I read a byte from port 0x64 (right?) and then set bit 1 and then write it back to port 0x64 (right?)
I am just unsure on the port to write and read from for the config byte...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: PS/2 Mouse IRQ Problem

Post by gerryg400 »

inixsoftware wrote:OK. Thanks! So, basically, I read a byte from port 0x64 (right?) and then set bit 1 and then write it back to port 0x64 (right?)
I am just unsure on the port to write and read from for the config byte...
To read the config byte you write 0x20 to port 0x64 then read from port 0x60.

To write the config byte back you write 0x60 to port 0x64 then write the new config byte to 0x60.

In all cases don't forget to wait for the buffer to empty before writing a byte and wait until it's ready to read.

http://wiki.osdev.org/%228042%22_PS/2_Controller is an excellent article.
If a trainstation is where trains stop, what is a workstation ?
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 Mouse IRQ Problem

Post by inixsoftware »

OK. So, the code would look something like this:

Code: Select all

outb(0x64, 0x20); /* Write 0x20 to port 0x64 */
	
unsigned char config = inb(0x60); /* Read byte from port 0x60 */
config |= 1 << 1; /* Set bit 1*/
	
outb(0x64, 0x60); /* Write 0x60 to port 0x64 */
outb(0x60, config); /* Write config byte to port 0x60 */

gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: PS/2 Mouse IRQ Problem

Post by gerryg400 »

That looks correct, however, to make it work on real hardware you must look at bits 0 and 1 of the status register to see when it's okay to read and write.
If a trainstation is where trains stop, what is a workstation ?
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

PS/2 IRQ Not Firing

Post by inixsoftware »

Hello. I am struggling still with the PS/2 Mouse (i got the PS/2 keyboard working fine). So, the code I am using is:

Code: Select all

outb(0x60, 0xF4);
while (inb(0x60) != 0xFA); /* Wait for ACK from mouse... */
	
/* Tell mouse to enable interrupts (IRQ12) */
outb(0x64, 0x20);
	
unsigned char res = inb(0x60);
res |= 1 << 1;
	
outb(0x64, 0x60);
outb(0x60, res);
	
/* Install a handler (which prints "Fired!") */
irq_install_handler(12, mouse_handler);
However, I am never getting the text "Fired!". I know my IDT and IRQs are working properly since the PIT and keyboard are working
just fine. Is there something I am missing?

Thanks!
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: PS/2 IRQ Not Firing

Post by sortie »

This is likely not the problem, but you should install the interrupt handler before enabling interrupt delivery from the device, or you might miss the interrupt (and the lack of a EOI might mean no futher interrupts arive).
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 IRQ Not Firing

Post by inixsoftware »

OK. So I put the irq_install_handler before any of the mouse init code and it still doesn't work...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: PS/2 IRQ Not Firing

Post by gerryg400 »

I wonder if you are using a real ps/2 mouse ? Or a usb mouse and hoping for ps/2 emulation ?
If a trainstation is where trains stop, what is a workstation ?
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 IRQ Not Firing

Post by inixsoftware »

Sorry. Forgot to say I am using QEMU, which I believe does emulate a PS/2 Mouse
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: PS/2 IRQ Not Firing

Post by gerryg400 »

Oh I just noticed. You need to write 0xd4 to the 0x64 register to address the mouse before writing commands to it. Like this ...

Code: Select all

// Address the 2nd device
outb(0x64, 0xd4);
// Write it
outb(0x60, 0xF4);
// Read back
while (inb(0x60) != 0xFA); /* Wait for ACK from mouse... */
If a trainstation is where trains stop, what is a workstation ?
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 IRQ Not Firing

Post by inixsoftware »

Thanks! Yes, it now works (I get the text "Fired!")
inixsoftware
Member
Member
Posts: 32
Joined: Fri Jan 31, 2014 8:21 am

Re: PS/2 IRQ Not Firing

Post by inixsoftware »

Oh yes. Now, whenever I type something I get a (Mouse) "Fired!" event... Is there something that I need to do to change this?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: PS/2 IRQ Not Firing

Post by sortie »

The PS/2 bus delivers both keyboard and mouse events.
Post Reply