PS/2 Mouse IRQ Problem
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
PS/2 Mouse IRQ Problem
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?
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?
Re: PS/2 Mouse IRQ Problem
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 ?
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 Mouse IRQ Problem
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...
I am just unsure on the port to write and read from for the config byte...
Re: PS/2 Mouse IRQ Problem
To read the config byte you write 0x20 to port 0x64 then read from port 0x60.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 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 ?
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 Mouse IRQ Problem
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 */
Re: PS/2 Mouse IRQ Problem
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 ?
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
PS/2 IRQ Not Firing
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:
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!
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);
just fine. Is there something I am missing?
Thanks!
Re: PS/2 IRQ Not Firing
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).
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 IRQ Not Firing
OK. So I put the irq_install_handler before any of the mouse init code and it still doesn't work...
Re: PS/2 IRQ Not Firing
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 ?
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 IRQ Not Firing
Sorry. Forgot to say I am using QEMU, which I believe does emulate a PS/2 Mouse
Re: PS/2 IRQ Not Firing
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 ?
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 IRQ Not Firing
Thanks! Yes, it now works (I get the text "Fired!")
-
- Member
- Posts: 32
- Joined: Fri Jan 31, 2014 8:21 am
Re: PS/2 IRQ Not Firing
Oh yes. Now, whenever I type something I get a (Mouse) "Fired!" event... Is there something that I need to do to change this?
Re: PS/2 IRQ Not Firing
The PS/2 bus delivers both keyboard and mouse events.