Adding keyboard input to James Molloy's tutorial kernel

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
RevivalDBM
Member
Member
Posts: 34
Joined: Sun Aug 03, 2008 5:38 am

Adding keyboard input to James Molloy's tutorial kernel

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

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

Post 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
RevivalDBM
Member
Member
Posts: 34
Joined: Sun Aug 03, 2008 5:38 am

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

Post 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.
RevivalDBM
Member
Member
Posts: 34
Joined: Sun Aug 03, 2008 5:38 am

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

Post 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.
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

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

Post by Adek336 »

I think you have to read a byte from port 0x64 to acknowledge a keypress.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

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

Post 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
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

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

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Post Reply