Page 1 of 1
Need help with PS/2 mouse
Posted: Thu Nov 10, 2011 4:15 pm
by kendfrey
I could use some help understanding how to code for the mouse and make a mouse driver. Please do not send me to the Mouse Input page on the wiki. I have read that too many times, and I do not understand it, and it has a horrible lack of example code.
The first thing I want to know is how to enable the mouse and read packets. I have my IDT/PIC stuff all set up, and I even have a handler for IRQ 12. I have not found any clear and comprehensive information on reading from the mouse. If someone could point me to something like that, I would appreciate it.
Re: Need help with PS/2 mouse
Posted: Thu Nov 10, 2011 4:38 pm
by Nessphoro
Re: Need help with PS/2 mouse
Posted: Thu Nov 10, 2011 5:52 pm
by kendfrey
Actually, I was looking for something that explains what is happening. You know, a healthy balance of English and code. I might be able to understand that code, but it would be tough without some high-level explanation.
Re: Need help with PS/2 mouse
Posted: Thu Nov 10, 2011 6:12 pm
by kendfrey
Right, that goes in my interrupt handler, correct? However, I'm not getting interrupts from the mouse yet. I need to set it up. Where can I find instructions on that?
Re: Need help with PS/2 mouse
Posted: Thu Nov 10, 2011 10:31 pm
by Muneer
kendfrey wrote:Right, that goes in my interrupt handler, correct?
Yes.
kendfrey wrote:However, I'm not getting interrupts from the mouse yet. I need to set it up. Where can I find instructions on that?
You must first setup the PIC (programmable interrupt controller) inorder to properly setup the interrupts in a protected mode(so u have to setup GDT and IDT) or enable interrupts from mouse if you are in real mode.I think that most bios disables the mouse interrupt on startup.
PIC guide.
http://wiki.osdev.org/PIC
http://www.beyondlogic.org/interrupts/interupt.htm
Afterwards initialize the keyboard controller to activate mouse interrupts.....
Re: Need help with PS/2 mouse
Posted: Fri Nov 11, 2011 3:05 am
by turdus
kendfrey wrote:Right, that goes in my interrupt handler, correct? However, I'm not getting interrupts from the mouse yet. I need to set it up. Where can I find instructions on that?
I confirm that the wiki on mouse is more than unusable. To enable irq12 you'll have to do some voodoo magic, see links at the bottom of page. It's covered in linked forum topics.
Re: Need help with PS/2 mouse
Posted: Fri Nov 11, 2011 7:33 am
by kendfrey
Yes, I have the PIC working fine, and getting keyboard interrupts. How do I initialize the mouse through the keyboard controller?
Re: Need help with PS/2 mouse
Posted: Fri Nov 11, 2011 12:14 pm
by turdus
kendfrey wrote:Yes, I have the PIC working fine, and getting keyboard interrupts. How do I initialize the mouse through the keyboard controller?
Did you read the wiki and the linked threads?
Set Compaq Status/Enable IRQ12
On some systems, the PS2 aux port is disabled at boot. Data coming from the aux port will not generate any interrupts. To know that data has arrived, you need to enable the aux port to generate IRQ12. There is only one way to do that, which involves getting/modifying the "compaq status" byte. You need to send the command byte 0x20 ("Get Compaq Status Byte") to the PS2 controller on port 0x64. If you look at RBIL, it says that this command is Compaq specific, but this is no longer true. This command does not generate a 0xFA ACK byte. The very next byte returned should be the Status byte. (Note: on some versions of Bochs, you will get a second byte, with a value of 0xD8, after sending this command, for some reason.) After you get the Status byte, you need to set bit number 1 (value=2, Enable IRQ12), and clear bit number 5 (value=0x20, Disable Mouse Clock). Then send command byte 0x60 ("Set Compaq Status") to port 0x64, followed by the modified Status byte to port 0x60. This might generate a 0xFA ACK byte from the keyboard.
Re: Need help with PS/2 mouse
Posted: Fri Nov 11, 2011 4:01 pm
by kendfrey
I read the linked threads and happened to stumble upon one that linked to
http://houbysoft.com/download/ps2mouse.html. Thanks for reminding me to check links
Sorry for being such a n00b. I got it working now.