help getting user input from keyboard, and reading writing..

Programming, for all ages and all languages.
Post Reply
R2_
Member
Member
Posts: 50
Joined: Sat Dec 02, 2006 3:27 pm

help getting user input from keyboard, and reading writing..

Post by R2_ »

Hi, Im currently developing a small kernel. So far I got printf() function but I do not know how to get keyboard input, nor get my kernel to install into the hard drive. I have written small kernels for PDA devices before never for x86 so any help would be greatly appreciated.

I seen in a lot of tutorials the use of outb() or something like that functions which they say can be used to access the keyboard but they never explain it nor show how they work so this leads to another question... is it a gcc built in function header that gets added when compiled (I doubt it) or how do you code it ?

Im good at C and assembler, but I do not want to use BIOS for keyboard input.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

This will get a key press

Code: Select all

        xor   eax,eax
      	in    al,0x60
But you need to have your keyboard irq, link in to your keyboard code, for a proper OS setup, have you got your idt setup yet ?.
R2_
Member
Member
Posts: 50
Joined: Sat Dec 02, 2006 3:27 pm

Post by R2_ »

sorry I posted this in wrong section..


how would I implement this into C ?

asm( xor eax,eax );
asm( in al,0x60 );

?

sorry as I said Im a newbie
thnx for response.
Last edited by R2_ on Sat Dec 02, 2006 5:28 pm, edited 1 time in total.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

1) You have to install a IRQ handler for the keyboard...
2) And you need a Scancode table..
3) Handle every event like the shift key.. caps lock, keyboard lights, etc.

To simplify reading from I/O ports, A function like this can be used with GCC.

Code: Select all

/*
This is used for reading I/O ports to get data from devices such as the
keyboard.
*/
inline unsigned char inportb(unsigned short p)
{
	unsigned char rv;
	__asm__ __volatile__("inb %%dx, %%al" : "=a" (rv) : "d" (p));
	return rv;
}
For simply reading from the keyboard, It can be done sorta like this..

Code: Select all

unsigned char scancode;
scancode = inportb(0x60);
if (scancode & 0x80)
{
	....
}
You should read a few tutorials...

In any senses it does take time, learning about the languages and the architecture your writing for is usually something you should do first.
Last edited by Brynet-Inc on Sat Dec 02, 2006 5:03 pm, edited 2 times in total.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
R2_
Member
Member
Posts: 50
Joined: Sat Dec 02, 2006 3:27 pm

Post by R2_ »

thanks a lot that really helped, about this tutorials can you post any ? I haven't been able to find any on OS dev or I/O on the Intel architecture.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Just noticed you posted you don't know what IDT/IRQ is.. Your beyond all help.. :lol:

Read here - http://www.osdev.org/phpBB2/viewtopic.php?p=85475#85475
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
R2_
Member
Member
Posts: 50
Joined: Sat Dec 02, 2006 3:27 pm

Post by R2_ »

I read the
http://www.osdev.org/osfaq2/index.php/S ... eFunctions
website but I can't figure out how to enable the IRQ

static __inline__
void irqUnlock(int no)
{
/* Val, Port */
if (no>7) outb(0x20,0xa0);
outb(0x20,0x20);
}

^^ I was thinking that was the way to do it but my IRQ check function still says it's disabled... I passed number 8 to it.. don't know if thats right..

Can anyone recommend any books that cover all this ?
TheQuux
Member
Member
Posts: 73
Joined: Sun Oct 22, 2006 6:49 pm

Post by TheQuux »

This took me forever as well...

To enable IRQ's, you need to write an 8-bit mask to port 0x21 (for the lower 8 IRQs) and another to 0xA1 (for the upper 8 IRQs).

For each mask, if a bit is clear (0), the IRQ is enabled

Then, to enable interrupts, use "sti"

Now, if your computer reboots, or bochs complains about a "third chance exception without resolution", you forgot your IDT...

About documentation; google is your friend.

For intel processors (and AMD, for that matter), go to http://www.intel.com/products/processor ... /index.htm

Download all of them; they are all useful.

For other hardware, good luck; I STILL haven't found anything on my NVidia graphics card...
My project: Xenon
Post Reply