c - How to get keyboard input with x86 bare metal assembly? -


i'm in process of trying hack first bits of kernel. have entire kernel compiled down c code, , i've managed displaying text in console window , of fine goodness. now, want start accepting keyboard input can make use of thing , going on process management.

i'm using djgpp compile, , loading grub. i'm using small bit of assembly jumps directly compiled c code , i'm happy there.

all research i've done seems point isr @ $0x16 read in next character keyboard buffer. can tell, supposed store ascii value in ah, , keycode in al, or effect. i'm attempting code using following routine in inline assembly:

char getc(void)  {     int output = 0;      //crazy voodoo code     asm("xor %%ah, %%ah\n\t"         "int $0x16"         : "=a" (output)         : "a" (output)         :           );      return (char)output; } 

when code called, core crashes. (i'm running on virtualbox, didn't feel need try basic on real hardware.)

now have couple of questions. no 1 has been able tell me if (since code launched grub) i'm running in real mode or protected mode @ moment. haven't made jump 1 way or another, planning on running in real mode until got process handler set up.

so, assuming i'm running in real mode, doing wrong, , how fix it? need basic getc routine, preferably non-blocking, i'll darned if google helping on 1 @ all. once can that, can rest there.

i guess i'm asking here is, anywhere near right track? how 1 go getting keyboard input on level?

edit: oohh... i'm running in protected mode. explains crash trying access real mode functions then.

so guess i'm looking how access keyboard io protected mode. might able find on own, if happens know feel free. again.

if compiling gcc, unless using crazy ".code16gcc" trick linux kernel uses (which doubt), cannot in real mode. if using grub multiboot specification, grub switching protected mode you. so, others pointed out, have talk 8042-compatible keyboard/mouse controller directly. unless it's usb keyboard/mouse , 8042 emulation disabled, need usb stack (but can use "boot" protocol keyboard/mouse, simpler).

nobody said writing os kernel simple.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -