Keyboard I/O programming question
Moderator:Moderators
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.
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.
-
- Posts:7
- Joined:Sat Apr 24, 2010 4:19 am
Re: Keyboard I/O programming question
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
ok, i think i understand.
Thank you.
Thank you.
Re: Keyboard I/O programming question
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?
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
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
Can you post your interrupt routine please?
~Andrew

Re: Keyboard I/O programming question
i have the ISR on asm and compiling it by nasm
this low level ISR call High level c++ function
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.
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);
}
and write one symbol.
timer ISR works good. But this keyboard ISR don't work.
Re: Keyboard I/O programming question
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
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:
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
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
That should work as you intend
~Andrew

Re: Keyboard I/O programming question
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.
i don't change my ISRs(high level and low level). But i add function which reading output value from the Keyboard controller.
The problem in it. Thank you.pathos wrote: but I think the keyboard status register thinks it's busy, and you have to clear it.