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
Problem with key presses when interrupts are disabled
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Problem with key presses when interrupts are disabled
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
@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
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
That is the correct fix. Not just "for now" - it's the way to handle that particular condition. My code does the same.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.
Re: Problem with key presses when interrupts are disabled
Ummmm ... that works for the keyboard, yes ... but you will need to make some decisions about supporting USB mice, later.