[RESOLVED] ps/2 mouse initalization / keyboard interrupt

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.

Moderators: JAAman, klange, Octocontrabass, sortie, kmcguire, chase, thepowersgang, Owen, Combuster, AJ, 01000101, carbonBased, Candy, pcmattman

megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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?
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ps/2 mouse initalization / keyboard interrupt

Post by Chandra »

Code: Select all

outportb(0x64, 0xAE);
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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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=1&t=19873&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?
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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?
megatron23
Posts: 19
Joined: Sat Oct 22, 2011 3:03 pm

Re: ps/2 mouse initalization / keyboard interrupt

Post 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.
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: ps/2 mouse initalization / keyboard interrupt

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