Page 2 of 2
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Mon Oct 24, 2011 2:17 pm
by megatron23
turdus wrote:That could take a while to set. Read and check it in a loop (timeout). For example I try it 1000 times before saying it was a false IRQ.
So it does matter if I do not read the 3 bytes mouse packet if i handle a IRQ12?
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Mon Oct 24, 2011 3:26 pm
by megatron23
well I did wait. even for 1m cycles and more. the byte at 0x64 is always 0 although a IRQ12 fired. that may come from the emu as does the one and only IRQ 1 that signals the release of the enter key when starting the emulation.
the ISR for the keyboard does enable the keyboard and signal eoi when returning. after that IRQ1 does not fire anymore. all other IRQs like 0,8 or 12 do work without problems.
I did not enable IRQ2, and if I do, it changes nothing.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Mon Oct 24, 2011 8:01 pm
by Chandra
What initialization commands did you send for enabling the Mouse Packets? You may want to post that snippet too.
Run your code under BOCHS and see how it reports the key strokes. It is possible that the debug window acknowledges "Scan code turned off" which is the obvious cause of incorrect initialization commands. Or may be, "Keyboard: Internal Buffer Full" when the handler is not called in the first place. This helps to catch up most of the issues at an instant.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 4:27 am
by megatron23
at first a used the initialization sequence from SANiK'S code. then I tried this:
Code: Select all
mouse_wait(1);
outportb(0x64, 0xA8);
mouse_wait(1);
outportb(0x64, 0x20);
mouse_wait(0);
_status=(inportb(0x60) | 2);
_status= (_status & 0xDF);
mouse_wait(1);
outportb(0x64, 0x60);
mouse_wait(1);
outportb(0x60, _status);
mouse_write(0xFF);
mouse_read_ack(0xAA); //wait for 0xAA on reset
mouse_write(0xEA);
mouse_read_ack();
mouse_write(0xF4);
mouse_read_ack();
outportb(0x64, 0xAE);
mouse_wait(arg) waits for bit 0 set or bit 1 unset on port 0x64 if argument is 0 or 1 respectively.
mouse_wait_ack(arg) waits for 0xFA or given argument on port 0x60.
In Qemu it works perfectly except that IRQ1 does not fire after IRQ12 fires for the first time.
BOCHS does send another ACK somewhere which kinda messes up the data packets, but it does not report any errors from the keyboard and IRQ1 does not work either.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 5:44 am
by Chandra
Send 0xF4 to the command port, this time to enable keyboard. See how that goes.
Edit: Do not issue command 0xD4 before 0xF4 as that would validate the command for mouse.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 6:17 am
by megatron23
Chandra wrote:Send 0xF4 to the command port, this time to enable keyboard. See how that goes.
If I send 0xF4 instead of 0xAE it locks everything up.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 6:46 am
by Chandra
megatron23 wrote:Chandra wrote:Send 0xF4 to the command port, this time to enable keyboard. See how that goes.
If I send 0xF4 instead of 0xAE it locks everything up.
Probably because you didn't read the ACK byte from the keyboard controller.
Besides, I tried your initialization code. No problem there, other than the reset command which causes mouse to behave really weird, no problem with the keyboard though. The only change I made was replace
mouse_read_ack(0xAA); with
mouse_read(); since I don't have your version.
With that, it's really hard to find the source of problem. Can you attach your binary and the source files? This problem really got me interested.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 1:20 pm
by megatron23
After a lot of search I found out that I am not the only one with that problem:
http://forum.osdev.org/viewtopic.php?f= ... 3&start=15
Besides, I tried your initialization code. No problem there, other than the reset command which causes mouse to behave really weird, no problem with the keyboard though.
What emulator did you use? Does it work everytime w/out problems?
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Tue Oct 25, 2011 10:25 pm
by Chandra
megatron23 wrote:What emulator did you use? Does it work everytime w/out problems?
It does, at least with QEMU and BOCHS. The reset routine dis-aligns the mouse packets so I dropped it and it worked fine.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Wed Oct 26, 2011 4:04 am
by megatron23
Chandra wrote:It does, at least with QEMU and BOCHS. The reset routine dis-aligns the mouse packets so I dropped it and it worked fine.
Can you show me your (now modified) mouse and keyboard initalization code. And the ISR of IRQ1.
What version of qemu did you use?
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Wed Oct 26, 2011 6:23 am
by megatron23
Finally it worked. I did not send anything to set or reset. Just enabling the interrupts an 0xF4 to enable the mouse. That's it. At least for qemu.
Re: ps/2 mouse initalization / keyboard interrupt
Posted: Wed Oct 26, 2011 7:12 am
by turdus
megatron23 wrote:Finally it worked. I did not send anything to set or reset. Just enabling the interrupts an 0xF4 to enable the mouse. That's it. At least for qemu.
Maybe you should check my initalization code. It's written is asm, but you can read what bytes send and read quite easily.
http://forum.osdev.org/viewtopic.php?f=1&t=24277
The sequance to use is not straightforward, there are funny things like optional ack and values read instead of ack, and others. The init seq I use is a known good one, and it also enables wheel and 4th, 5th buttons for you, and autodetects the packet size (whether 3 or 4 bytes). And it does not interfere with keyboard.