Keyboard I/O programming question

For programming questions that do not fit in the other forums.

Moderator: Moderators

Keyboard I/O programming question

Postby kslimani » Sat Apr 24, 2010 3:07 pm

Hello,

i have read the chapter about keyboard programming (http://www.brokenthorn.com/Resources/OSDev19.html). I don't have understand everything as i am not familiar with hardware and asm.

I would like to know, if it is possible to simulate a key pressed on keyboard, by send a command to keyboard controller (0x64), or by directly write into keyboard I/O port (0x60) ?

Regards,

SK.
kslimani
 
Posts: 2
Joined: Sat Apr 24, 2010 2:18 pm

Re: Keyboard I/O programming question

Postby Believer424 » Sat Apr 24, 2010 4:04 pm

As far as I know you will just use the IRQ to handle the keyboard. Writing to 0x64 will send a command and reading 0x64 will get you the status reigister. Writing/reading to 0x60 will get you the output/input buffers.
Believer424
 
Posts: 7
Joined: Sat Apr 24, 2010 4:19 am

Re: Keyboard I/O programming question

Postby kslimani » Sun Apr 25, 2010 2:07 am

ok, i think i understand.

Thank you.
kslimani
 
Posts: 2
Joined: Sat Apr 24, 2010 2:18 pm

Re: Keyboard I/O programming question

Postby XV8 » Wed May 05, 2010 10:01 pm

Hi. need help.
when i read keyboard controller status register(from 0x64) i have value= 17 (00010001).
but when i install ISR for keyboard interrupt (which write any char to screen), the ISR code execute automatically and write char to screen 1 times . If i press to keyboard key nothing don't occur.
Leds command for set CapsLock or NumLock,ScrollLock works ok.
Self Test command return 0xFA value

What wrong?
May be this error because i use USB keyboard?
User avatar
XV8
 
Posts: 9
Joined: Tue Apr 06, 2010 10:47 am

Re: Keyboard I/O programming question

Postby Andyhhp » Thu May 06, 2010 2:17 pm

Until you initalise the USB subsystem all USB keyboards act as PS2 one so that wont be the problem

Can you post your interrupt routine please?

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Keyboard I/O programming question

Postby XV8 » Fri May 07, 2010 5:17 pm

i have the ISR on asm and compiling it by nasm
this low level ISR call High level c++ function

Code: Select all
IRQ_33:
cli
pushad
; call ir2 function (in C++ _Z3ir2v)
call _Z3ir2v
popad
sti
iretd



Code: Select all
static int q=49;

void ir2()
{
unsigned char * u= (unsigned char*) 0xb8000;
unsigned short cur=0;
u[cur*2]=q;
u[(cur++*2)+1]=VC_White;
q++;
// send End Of Interrupt to Slave PIC
IntFinish(0);
}


but this code was called automaticlly one times aftrer enable interrupts. (Why? i don't know)
and write one symbol.
timer ISR works good. But this keyboard ISR don't work.
User avatar
XV8
 
Posts: 9
Joined: Tue Apr 06, 2010 10:47 am

Re: Keyboard I/O programming question

Postby pathos » Fri May 07, 2010 5:40 pm

Andyhhp will know better than me, but I think the keyboard status register thinks it's busy, and you have to clear it. But I could be completely wrong.
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Re: Keyboard I/O programming question

Postby Andyhhp » Fri May 07, 2010 8:50 pm

Your problem is that calling the function doesnt store the value of EAX.

You need to explicitly save EAX by pushing and poping it. Conversly, the pushad and popad are not needed as the function call is guarenteed to restore all other registers.

Finally, the cli and sti are not needed. The hardware which controls interupts in the CPU will do this automatically for you.

The reason it only does a single character is that it works the first time, but hits a GPF when EAX isnt properly restored.

As a result, you code should be more like:

Code: Select all
IRQ_33:

push eax
; call ir2 function (in C++ _Z3ir2v)
call _Z3ir2v
pop eax

iretd


Also, you have a logical error in your printing routine - cur is set to 0 each time you enter the function. It should be declared outside like q is.

That should work as you intend

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Keyboard I/O programming question

Postby XV8 » Sun May 09, 2010 7:25 pm

Thank you for all. Problem was solved.
i don't change my ISRs(high level and low level). But i add function which reading output value from the Keyboard controller.

pathos wrote: but I think the keyboard status register thinks it's busy, and you have to clear it.

The problem in it. Thank you.
User avatar
XV8
 
Posts: 9
Joined: Tue Apr 06, 2010 10:47 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron