Page 1 of 1
Keyboard
Posted: Tue Jun 09, 2009 4:17 am
by Andr3w
Hello!
I'm making a small kernel for my OS (working in PMode).
I'm trying to make a keyboard driver.
Could you help me and answer why this code isn't working?
Code: Select all
mov word[ds:(9*4) ], keyboard_handler
mov word[ds:(9*4)+2], 0
jmp $
keyboard_handler:
pusha
in al, 0x60
call write_byte_as_hex
mov bl, '|'
call Putch32
mov al, 0x20
out 0x20, al
popa
iret
hex_chars: db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
write_byte_as_hex:
pusha
and ax, 0xFF
push ax
mov bx, ax
shr bx, 4
mov bl, [hex_chars+bx]
call Putch32
pop bx
and bx, 0xF
mov bl, [hex_chars+bx]
call Putch32
popa
ret
P.S Putch32 function puts a char from BL register on the screen.
Thanks!
Re: Keyboard
Posted: Tue Jun 09, 2009 4:40 am
by Combuster
You are running real mode code in protected mode.
Re: Keyboard
Posted: Tue Jun 09, 2009 4:42 am
by kop99
when your key pressed, keyboard handler is called?
Re: Keyboard
Posted: Wed Jun 10, 2009 2:52 am
by CmpXchg
That's not gonna work, mate
How about setting up IVT?
Re: Keyboard
Posted: Wed Jun 10, 2009 8:43 am
by Troy Martin
CmpXchg wrote:How about setting up IVT?
In protected mode? Haha, more like remapping the PIC and setting up the ever-tricky (for noobs) IDT. Th' Interrupt Vector Table is for real mode, the Interrupt Descriptor Table is for protected mode.
The answer is on the wiki. RTFM.
Re: Keyboard
Posted: Wed Jun 10, 2009 9:42 am
by cyr1x
Troy Martin wrote: Th' Interrupt Vector Table is for real mode, the Interrupt Descriptor Table is for protected mode.
It's the same thing in both RM and PM. These are only different names, while IVT is the more general term, IDT is the x86-specific term.
Re: Keyboard
Posted: Wed Jun 10, 2009 10:04 am
by yemista
cyr1x wrote:Troy Martin wrote: Th' Interrupt Vector Table is for real mode, the Interrupt Descriptor Table is for protected mode.
It's the same thing in both RM and PM. These are only different names, while IVT is the more general term, IDT is the x86-specific term.
Well the idea is the same, but IVT exists in memory by the BIOS setting it up. IDT needs to be setup differently because of the larger address space available, but they basically work the same. Try this link for more information:
http://osdever.net/tutorials/interrupts.3.php
Re: Keyboard
Posted: Wed Jun 10, 2009 11:07 am
by mathematician
qandrew wrote:Hello!
I'm making a small kernel for my OS (working in PMode).
I'm trying to make a keyboard driver.
Could you help me and answer why this code isn't working?
Code: Select all
mov word[ds:(9*4) ], keyboard_handler
mov word[ds:(9*4)+2], 0
jmp $
keyboard_handler:
pusha
in al, 0x60
call write_byte_as_hex
mov bl, '|'
call Putch32
mov al, 0x20
out 0x20, al
popa
iret
hex_chars: db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
write_byte_as_hex:
pusha
and ax, 0xFF
push ax
mov bx, ax
shr bx, 4
mov bl, [hex_chars+bx]
call Putch32
pop bx
and bx, 0xF
mov bl, [hex_chars+bx]
call Putch32
popa
ret
P.S Putch32 function puts a char from BL register on the screen.
Thanks!
You need to go to Intel or AMD's site and download their system programming manuals. There you will find out all about protected mode interrupt descriptor tables. Also, if you are writing a full blown kernel, you might want to reprogram the PIC to something other than int 9 for the keyboard controller. The first 32 interrupts are reserved by Intel - something IBM thought they could ignore when they developed the first PC - but in these days of protected mode operating systems, it can be ignored no longer.
Re: Keyboard
Posted: Thu Jun 11, 2009 8:07 am
by jal
mathematician wrote:The first 32 interrupts are reserved by Intel - something IBM thought they could ignore when they developed the first PC - but in these days of protected mode operating systems, it can be ignored no longer.
They didn't entirely ignore that: IRQ0 is mapped to INT8. The 8086 used only a few interrupts (NMI, BRK, INTO). Not until the 80186 and later the 80286, 386 more processor interrupts / acceptions became available. By then, it was too late to change anything or about all software would break (keyboard and timer hooks, anyone?).
JAL