Page 1 of 1

Keyboard I/O programming question

Posted: Sat Apr 24, 2010 3:07 pm
by kslimani
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.

Re: Keyboard I/O programming question

Posted: Sat Apr 24, 2010 4:04 pm
by Believer424
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.

Re: Keyboard I/O programming question

Posted: Sun Apr 25, 2010 2:07 am
by kslimani
ok, i think i understand.

Thank you.

Re: Keyboard I/O programming question

Posted: Wed May 05, 2010 10:01 pm
by XV8
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?

Re: Keyboard I/O programming question

Posted: Thu May 06, 2010 2:17 pm
by Andyhhp
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

Re: Keyboard I/O programming question

Posted: Fri May 07, 2010 5:17 pm
by XV8
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.

Re: Keyboard I/O programming question

Posted: Fri May 07, 2010 5:40 pm
by pathos
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.

Re: Keyboard I/O programming question

Posted: Fri May 07, 2010 8:50 pm
by Andyhhp
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

Re: Keyboard I/O programming question

Posted: Sun May 09, 2010 7:25 pm
by XV8
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.