Page 1 of 1

Problem with key presses when interrupts are disabled

Posted: Mon May 10, 2010 7:11 pm
by DL
Hi,

I've got a basic protected mode kernel running using information found on the wiki and I can get key scancodes most of the time by reading from port 0x60 when IRQ 1 fires.

However, if a key is pressed before interrupts are enabled (e.g. after the kernel has been loaded by GRUB and is setting up GDT, IDT, ...) or between cli and sti (e.g. while handling other IRQs or software interrupts), IRQ 1 never fires, even for subsequent key presses.

I've googled, but didn't find much. Could someone point me in the right direction? Pressing a key at the wrong time basically disables the keyboard...

DL

Re: Problem with key presses when interrupts are disabled

Posted: Mon May 10, 2010 7:59 pm
by NickJohnson
What is happening is that the keyboard controller is trying to send an interrupt, but since interrupts are off, it never gets through. Until you read the scancode from 0x60, it will not try to send any more interrupts. So, simply flush the buffer by reading in all of the scancodes until they cease changing (I think there's some flag elsewhere that might be a more reliable way of doing this), and your keyboard controller will start firing interrupts again.

Re: Problem with key presses when interrupts are disabled

Posted: Tue May 11, 2010 8:15 am
by bewing
@DL: try doing an sti before sending EOI to the PIC in your interrupt handlers. That may get your more IRQ1s.

Re: Problem with key presses when interrupts are disabled

Posted: Thu May 13, 2010 9:32 am
by DL
I've fixed it for now by checking if there are new scancodes available (bit 0 in status byte read from port 0x64) and reading them before iret - I then get IRQ 1s for new key presses. Thank you for your answers.

Re: Problem with key presses when interrupts are disabled

Posted: Thu May 13, 2010 9:43 am
by JamesM
DL wrote:I've fixed it for now by checking if there are new scancodes available (bit 0 in status byte read from port 0x64) and reading them before iret - I then get IRQ 1s for new key presses. Thank you for your answers.
That is the correct fix. Not just "for now" - it's the way to handle that particular condition. My code does the same.

Re: Problem with key presses when interrupts are disabled

Posted: Thu May 13, 2010 5:16 pm
by bewing
Ummmm ... that works for the keyboard, yes ... but you will need to make some decisions about supporting USB mice, later.