Page 1 of 1

Why my keyboard handler works only once ?

Posted: Thu Apr 09, 2009 11:27 am
by stanko51
I'm trying to handle my interrupt and so far I'm only trying to set basis up but my keyboard interrupt works only once (or sometimes doesn't work at all...).
Timer interrupt keeps on working well and I print every second "clock"

Here's my code... I wrote this according to what i found in the wiki about interrupt..

How i initiate IDT

Code: Select all

	for (i = 0; i < IDTSIZE; i++) 
		create_idt_seg_desc(0x08, (u32) _asm_default_int, INTGATE, &IDT[i]);

	create_idt_seg_desc(0x08, (u32) _asm_irq_0, INTGATE, &IDT[32]);	/* timer*/
	create_idt_seg_desc(0x08, (u32) _asm_irq_1, INTGATE, &IDT[33]);	/* keyboard*/



How it's handle in asm

extern isr_default_int, isr_clock_int, isr_kbd_int
global _asm_default_int, _asm_irq_0, _asm_irq_1

Code: Select all

 
_asm_default_int:
	call isr_default_int
	mov al,0x20
	out 0x20,al
	iret

_asm_irq_0:
	call isr_clock_int
	mov al,0x20
	out 0x20,al
	iret

_asm_irq_1:
	call isr_kbd_int
	mov al,0x20
	out 0x20,al
	iret

and in C

Code: Select all

void isr_default_int(void)
{ print ("unknown interupt"); }

void isr_clock_int(void)
{ static int tic = 0;
  tic++;
  if (tic % 100 == 0) {
    tic = 0;
     rint("clock ");
  }
}

void isr_kbd_int(void)
{ print("keyboard"); }

When i execute, i can print "keyboard" only once, "clock" keeps on working.


Could someone explain to me why the keyboard handler works only once ?

Thank you.

Re: Why my keyboard handler works only once ?

Posted: Thu Apr 09, 2009 11:30 am
by JamesM
Hi,

You must clear the keyboard's key buffer - It won't port IRQs while its buffer is still full.

To do this, poll port 0x64, and while the least significant bit is set, read port 0x60 (this will get you a scancode, which you should then convert via a keymap into ASCII or whatever encoding you use).

After the buffer is empty (read port 0x64, bit 0x01 is clear), you will receive IRQs again.

Cheers,

James

Re: Why my keyboard handler works only once ?

Posted: Thu Apr 09, 2009 11:41 am
by stanko51
It works. thank you! :P

Re: Why my keyboard handler works only once ?

Posted: Thu Apr 09, 2009 12:18 pm
by Combuster
You should also preserve your registers upon interrupt. It may not be causing trouble now, but it will later

Re: Why my keyboard handler works only once ?

Posted: Thu Apr 09, 2009 12:19 pm
by ehenkes