Need help with PS/2 mouse

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
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Need help with PS/2 mouse

Post 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.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Need help with PS/2 mouse

Post by Nessphoro »

kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: Need help with PS/2 mouse

Post 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.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: Need help with PS/2 mouse

Post 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?
User avatar
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Need help with PS/2 mouse

Post 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.....
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Need help with PS/2 mouse

Post 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.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: Need help with PS/2 mouse

Post by kendfrey »

Yes, I have the PIC working fine, and getting keyboard interrupts. How do I initialize the mouse through the keyboard controller?
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Need help with PS/2 mouse

Post 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.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: Need help with PS/2 mouse

Post 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.
Post Reply