Hello all!
Please help me to understand the ps2 mouse interrupt better.
In alot of other os source code I've read, the ps2 mouse is assigned irq 12 (0x2c). What is the rationale for this when both are accessed through the i8042 keyboard controller? I don't understand why the keyboard interrupt handler isn't used to process mouse movement.
After I initialize the mouse, moving the mouse seems to generates characters via IRQ 1. I assume my keyboard interrupt handler is picking up both hardware interrupts.
Would it be sensible to handle mouse movement in the keyboard interrupt handler?
i.e.
if the AUXB flag of the status register 0x64 == 0
// process keyboard data
else if AUXB == 1
// process mouse data
Any responses will be greatly appreciated
Thanks!
PS2 mouse interrupt handler
-
srg_13
Re:PS2 mouse interrupt handler
AFAIK, the mouse sends an IRQ 12, but it is read at port 0x60, like the keyboard handler. If your keyboard handler only reads port 0x60 when an IRQ 1 is called, you should not pick up mouse movements.
-Stephen
-Stephen
-
tom1000000
Re:PS2 mouse interrupt handler
Hello,
You may ask why the PS/2 mouse IRQ is always 12?
Why is the floppy IRQ always 6?
Why is the first hard drive IRQ always 15? I can't remember the port addresses, which are also fixed.
Basically the original 286 PC design was crap (the 8086 was equally bad). Hardware had fixed addresses / settings purely to make it cheaper to produce.
The legacy is still with us.....
You may ask why the PS/2 mouse IRQ is always 12?
Why is the floppy IRQ always 6?
Why is the first hard drive IRQ always 15? I can't remember the port addresses, which are also fixed.
Basically the original 286 PC design was crap (the 8086 was equally bad). Hardware had fixed addresses / settings purely to make it cheaper to produce.
The legacy is still with us.....
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:PS2 mouse interrupt handler
first, numbers of the IRQs also indicate their priority. timer has priority over anything else, then comes keyboard, then all of the "slave" devices (including mouse and hard disk). Floppy and soundblasters are among the less prioritized.
Why keyboard is 1 and mouse 12 ? i guess that's because IRQ12 was still available when the launched the PS/2 serie. remember that initially, PCs had no mouse! if you still wanted one, you needed to connect it to the general-purpose "serial port". When they replaced 8255 by 8042, the new chip emulated the behaviour of 8255-based keyboard driver but it was also capable of handling the "auxiliary" channel over which you'd find a PS/2 mouse.
That being said, yes, that's all a matter of ancient decisions, backward compatibility and the like. It's ugly but it's everywhere and i guess we'll have to deal with that for a while ...
Why keyboard is 1 and mouse 12 ? i guess that's because IRQ12 was still available when the launched the PS/2 serie. remember that initially, PCs had no mouse! if you still wanted one, you needed to connect it to the general-purpose "serial port". When they replaced 8255 by 8042, the new chip emulated the behaviour of 8255-based keyboard driver but it was also capable of handling the "auxiliary" channel over which you'd find a PS/2 mouse.
That being said, yes, that's all a matter of ancient decisions, backward compatibility and the like. It's ugly but it's everywhere and i guess we'll have to deal with that for a while ...
-
distantvoices
- Member

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:PS2 mouse interrupt handler
Ha --- and even if we did it otherwise we'd still need somep?lace where to talk to hardware.
See, hardware io-stuff is connected to data bus (hidden by some buffer). CPU writes some address to the address bus and either sets IORQ to low(high in other cases) and either the Read or Write Line to low(high) - at least on the i386 architecture. In case the IORQ line is set, the IO-addressdecoder is selected instead of the mem address decoder and depending on a given set of bits in the submitted address (maybe the highest four I don't know - so it is limited to ~65000 ??) an IO component is selected for either reading from or writing to the data bus.
That's the purpose of ports. a Port represents a piece of hardware connected to a given line of the responsible address decoder. Even in sparc machines we 'd need a way to find out where we can talk to the mouse/harddisk/floppy/whatsoever ...
That intel architecture also operates with cascaded address decoders to map certain addresses to io devices instead of memory can be seen in the example of the magnificient vesa framebuffer.
@pype: I daresay the von-neumann architecture dictates some of the dealings we have to sort out nowadays. ...
stay safe ...
See, hardware io-stuff is connected to data bus (hidden by some buffer). CPU writes some address to the address bus and either sets IORQ to low(high in other cases) and either the Read or Write Line to low(high) - at least on the i386 architecture. In case the IORQ line is set, the IO-addressdecoder is selected instead of the mem address decoder and depending on a given set of bits in the submitted address (maybe the highest four I don't know - so it is limited to ~65000 ??) an IO component is selected for either reading from or writing to the data bus.
That's the purpose of ports. a Port represents a piece of hardware connected to a given line of the responsible address decoder. Even in sparc machines we 'd need a way to find out where we can talk to the mouse/harddisk/floppy/whatsoever ...
That intel architecture also operates with cascaded address decoders to map certain addresses to io devices instead of memory can be seen in the example of the magnificient vesa framebuffer.
@pype: I daresay the von-neumann architecture dictates some of the dealings we have to sort out nowadays. ...
stay safe ...
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
-
lit
Re:PS2 mouse interrupt handler
Thanks everybody for the insights!
I am left with the question:
Can I use the same interrupt handler function for both the mouse and the keyboard, using the AUXB flag to deternine which data to process?
I am left with the question:
Can I use the same interrupt handler function for both the mouse and the keyboard, using the AUXB flag to deternine which data to process?
-
srg_13
Re:PS2 mouse interrupt handler
You could use something like this psudeocode:
If you made interrupts for both 1 and 12 pointing to that...
-Stephen
Code: Select all
void irq1_handler(struct regs *r)
{
if(r->int_no==1)
{
char kb_byte = inb(0x60);
// etc.
}
else if(r->int_no==12)
{
char mouse_byte = inb(0x60)
// etc.
}
else
{
printf("ERROR");
}
}-Stephen
-
lit
Re:PS2 mouse interrupt handler
Thanks, Steve the Pirate, I appreciate the response.
I am going to implement things this way and will post my results asap.
I am going to implement things this way and will post my results asap.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:PS2 mouse interrupt handler
Honnestly, i fail to see how that could be helpful ... you have two distinct events, regarding two different stuff. What kind of benefit do you expect from using the same handler for both of them (not mentionning that sending EOI following IRQ1 and following IRQ12 isn't the same) ?lit wrote: Can I use the same interrupt handler function for both the mouse and the keyboard, using the AUXB flag to deternine which data to process?