Page 1 of 1

Adding keyboard input to James Molloy's tutorial kernel

Posted: Sun Aug 03, 2008 8:22 am
by RevivalDBM
Hello,
I recently decided to try and write my own kernel. Having done well in the past following tutorials then eventually going on to do things on my own I decided to follow James Molloy's kernel tutorial. I managed to complete and compile it, and, using some information in Bran's kernel tutorial, tried to add keyboard input, by creating a function called keyboard_handler and tryed to attach (excuse my wording, I'm not an experianced kernel devver as you can guess) it to IRQ 1 with this code:

Code: Select all

register_interrupt_handler(1,keyboard_handler);
When I compiled the kernel and created my floppy image, running it done nothing when the keys were pressed. The function works perfecly well - I tested it in a continuous for loop which printed the characters, albeit a few hundred times.

Thanks in advance to anyone who can help.

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Sun Aug 03, 2008 8:47 am
by AJ
Hi,

Have you declared your scancode variable as volatile? Important if you keep rechecking an externally modified variable in a tight loop as it stops GCC caching the variable in a register.

Cheers,
Adam

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Sun Aug 03, 2008 8:57 am
by RevivalDBM
AJ wrote:Hi,

Have you declared your scancode variable as volatile? Important if you keep rechecking an externally modified variable in a tight loop as it stops GCC caching the variable in a register.

Cheers,
Adam
Just tried that - same result.

Thanks.

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Sun Aug 03, 2008 12:21 pm
by RevivalDBM
Just wanted to say I modified the keyboard handler function to print some text to the screen even if a key was not pressed - the result was zilch, ergo the IRQ's aren't being received (again, my wording is poor, but I'm not experianced).


EDIT:
I managed to fix it, simple problem which I overlooked.

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Sun Aug 03, 2008 10:05 pm
by Adek336
I think you have to read a byte from port 0x64 to acknowledge a keypress.

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Mon Aug 04, 2008 2:31 am
by AJ
RevivalDBM wrote:EDIT:
I managed to fix it, simple problem which I overlooked.
What was the problem? It may help someone else in the same situation.

Cheers,
Adam

Re: Adding keyboard input to James Molloy's tutorial kernel

Posted: Mon Aug 04, 2008 7:59 pm
by piranha
Change it to

Code: Select all

register_interrupt_handler(IRQ1, keyboard_handler)
IIRC, IRQ1 is defined in common.h

EDIT: Oops, I didn't see your post. Though I'm guessing that was the problem?

-JL