Why my keyboard handler works only once ?

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
stanko51
Member
Member
Posts: 32
Joined: Fri Mar 27, 2009 6:58 pm

Why my keyboard handler works only once ?

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

Re: Why my keyboard handler works only once ?

Post 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
stanko51
Member
Member
Posts: 32
Joined: Fri Mar 27, 2009 6:58 pm

Re: Why my keyboard handler works only once ?

Post by stanko51 »

It works. thank you! :P
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Why my keyboard handler works only once ?

Post by Combuster »

You should also preserve your registers upon interrupt. It may not be causing trouble now, but it will later
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply