Keyboard handling with BIOS

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
cutebomb

Keyboard handling with BIOS

Post by cutebomb »

I write my os keyboard handling using BIOS interrupt 0x16 subfunction
0x0.But when I call the get_keystroke function,the machine reboot
immediately,and in VMware this procedure cause a triple fault.This
function post below.
   How can I handle my keyboard with BIOS?
   And is there any interrupt I should use befor I call interrupt 0x16
subfunction 0x0 to initialize the keyboard?
   Can I find some tutorial on Web?
   Any idea?
   Thanks!
/////////////////////////////////////////////
typedef unsigned short word;

word get_keystroke()
{
word _ax;
__asm__ __volatile__ ("movb $0x0,%%ah;
int $0x16;"
:"=a"(_ax));
return _ax;
}
/////////////////////////////////////////////
carbonBased

RE:Keyboard handling with BIOS

Post by carbonBased »

Don't know how many times it can be said, but... you _cannot_ use the BIOS in protected mode!

Possible solutions are to run the BIOS through a vm86 task, or write a real pmode driver for it (ie, the "normal" way).

A keyboard driver is one of the easiest you'll ever write.  Check out some programming docs on the 'net.  Basically, it involves writting an ISR, and reading ports (0x60, I think... but I don't remember exactly).

Jeff
cutebomb

RE:Keyboard handling with BIOS

Post by cutebomb »

I forgot to say that I still in Real Mode :)
carbonBased

RE:Keyboard handling with BIOS

Post by carbonBased »

> I forgot to say that I still in Real Mode :)

Ahh, yes... that'd be a useful tidbit to know :)  I read "triple fault" and assumed pmode (imagine that! ;)

Anyway, if your code is, indeed, read mode, then you shouldn't be using GCC (which cannot produce real mode code).  And how are you booting this OS?

Jeff
Post Reply