Keyboard

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Keyboard

Post 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!
User avatar
Combuster
Member
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:

Re: Keyboard

Post by Combuster »

You are running real mode code in protected mode.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Keyboard

Post by kop99 »

when your key pressed, keyboard handler is called?
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Re: Keyboard

Post by CmpXchg »

That's not gonna work, mate :(
How about setting up IVT?
Every Man Must Learn David DeAngelo's Stuff, Period.
http://www.doubleyourdating.com/Catalog
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Keyboard

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Keyboard

Post 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.
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Keyboard

Post 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
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Re: Keyboard

Post 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.
The continuous image of a connected set is connected.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Keyboard

Post 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
Post Reply