How do i write a keyboard driver?
How do i write a keyboard driver?
Hi, i've a question (perhaps no only one). How do i can write a driver for my keyboard? I've heard about the PCI and the IRQ but i haven't understand how do i use them...
P.S As you may have noticed, i'm not english and i cant tell it well...
If I will write some mistakes please forgive me
P.S As you may have noticed, i'm not english and i cant tell it well...
If I will write some mistakes please forgive me
- gzaloprgm
- Member
- Posts: 141
- Joined: Sun Sep 23, 2007 4:53 pm
- Location: Buenos Aires, Argentina
- Contact:
Hello Karlosoft, it's very easy to write it.
First you'll have to register a dummy handler in IRQ1 (keyboard irq), in my kernel I do the following:
But in yours it may different.
Then I have a keyboard_handler function which is like the following
Keyboard_map_us is an array of unsigned char, US key map is here, for making italian map you'll need to search for it or write yourself the table manually
http://www.osdever.net/bkerndev/Sources/kb.c
Cheers,
Gonzalo
ps. you'll need pci for loading list of devices in pci bus, not for this.
First you'll have to register a dummy handler in IRQ1 (keyboard irq), in my kernel I do the following:
Code: Select all
register_interrupt_handler(IRQ1, &keyboard_handler);
Then I have a keyboard_handler function which is like the following
Code: Select all
void keyboard_handler(registers_t regs){
unsigned char key = inportb(0x60);
if(key < 0x80){
putch(keyboard_map_us[key]);
}
}
http://www.osdever.net/bkerndev/Sources/kb.c
Cheers,
Gonzalo
ps. you'll need pci for loading list of devices in pci bus, not for this.
- gzaloprgm
- Member
- Posts: 141
- Joined: Sun Sep 23, 2007 4:53 pm
- Location: Buenos Aires, Argentina
- Contact:
I assume you have Idt, isrs and irq correctly loaded.
I don't think that works but I hope you understand the idea.
Cheers,
Gonzalo
Code: Select all
irq1:
cli
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
outb 0x20, 0x20 ;send signal to pic
inb 0x60, ax ;read code to ax (?)
;do what you want here with ax
pop ebx ; reload the original data segment descriptor
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
popa ; Pops edi,esi,ebp...
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
Cheers,
Gonzalo
same principles to follow.
read the scancode from the keyboard port, then run the scancode value through an array of keyboard characters (unique to each region).
then you can print the returned array value to the screen.
read the scancode from the keyboard port, then run the scancode value through an array of keyboard characters (unique to each region).
then you can print the returned array value to the screen.
Website: https://joscor.com
I must write something to use this code? I mean, i don't have understand if i must set the irq lines or noI assume you have Idt, isrs and irq correctly loaded.
P.S
Excuse my ignorance, but it's difficult to find italian books about assembly, so I must search them in english web-sites, and i don't always understand all...
Last edited by Karlosoft on Thu Feb 14, 2008 11:52 am, edited 1 time in total.
And all is ok, but the problem ist that an italian tutorial about "How to write a simle OS" sayd that I musst set the irq lines, the pci with many commands. Now i don't understand what do...same principles to follow.
read the scancode from the keyboard port, then run the scancode value through an array of keyboard characters (unique to each region).
then you can print the returned array value to the screen.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
look harderbut i don't have find any tutorial that say how do...