Problem with key presses when interrupts are disabled

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
DL
Posts: 2
Joined: Mon May 10, 2010 6:53 pm
Location: Lithuania

Problem with key presses when interrupts are disabled

Post 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
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Problem with key presses when interrupts are disabled

Post 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.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Problem with key presses when interrupts are disabled

Post by bewing »

@DL: try doing an sti before sending EOI to the PIC in your interrupt handlers. That may get your more IRQ1s.
DL
Posts: 2
Joined: Mon May 10, 2010 6:53 pm
Location: Lithuania

Re: Problem with key presses when interrupts are disabled

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Problem with key presses when interrupts are disabled

Post 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.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Problem with key presses when interrupts are disabled

Post by bewing »

Ummmm ... that works for the keyboard, yes ... but you will need to make some decisions about supporting USB mice, later.
Post Reply