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.
help getting user input from keyboard, and reading writing..
This will get a key press
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 ?.
Code: Select all
xor eax,eax
in al,0x60
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
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.
For simply reading from the keyboard, It can be done sorta like this..
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.
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;
}
Code: Select all
unsigned char scancode;
scancode = inportb(0x60);
if (scancode & 0x80)
{
....
}
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.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Just noticed you posted you don't know what IDT/IRQ is.. Your beyond all help..
Read here - http://www.osdev.org/phpBB2/viewtopic.php?p=85475#85475
Read here - http://www.osdev.org/phpBB2/viewtopic.php?p=85475#85475
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 ?
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 ?
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...
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