Page 1 of 3

detecting Keyboard in P mode: how do I do it

Posted: Thu Feb 14, 2008 1:09 am
by naiksidd_85
:cry: I am trying to detect keyboard in the protected mode.
I am able to print values that are typed using scan codes but i want to halt the system after grub if the keyboard is not present can any one help.

the error is not thrown if keyboard is unavailable.

I know this is really stupid thing to ask but am missing some thing and cant figure out what .

Posted: Thu Feb 14, 2008 1:28 am
by HeliOS
You want to "detect keyboard"? Well as you said, you can print characters(i assume you are accessing the video memory directly), you must have made a keyboard driver?
Do post what exactly you have done, so other can be benifited too.

HeliOS.

Posted: Thu Feb 14, 2008 1:39 am
by xyzzy
He means he wants to check if the keyboard is plugged in or not.

Posted: Thu Feb 14, 2008 1:51 am
by pcmattman
You can probably safely assume that the keyboard is plugged in. If it isn't then you simply won't get any data from the keyboard when you send such things as the reset command and the like.

Posted: Thu Feb 14, 2008 2:31 am
by naiksidd_85
what AlexExtreme said is true.
i want to check if keyboard is plugged in or not in simillar way that the bios does but in pmode.

i have not written the driver as such for key board it just uses scan codes that I have defined to get the key pressed will post it after some changes

Posted: Thu Feb 14, 2008 2:56 am
by pcmattman
I'd suggest attempting to talk to the keyboard (the PS/2 protocol is heavily documented) and then if you don't get an acknowledge from the keyboard controller (or an error) then you assume that no keyboard is plugged in.

Posted: Mon Feb 18, 2008 5:35 am
by naiksidd_85
i tried a lot using the following code

Code: Select all

[GLOBAL keybdpre]
	 [bits 32]
         xor eax,eax;
         in al,0x60;   // read from key board ctrl staus register 
   kbdpre:
                 xor eax,eax;    
                 in al,0x64; // get port status  
                 bt ax,1;    // test bit 1 of command register to check if it is set  
                                // and will set carry flag
                 jc print; 
                 jnc areho;
                print: mov ah,0x01
                ret
                areho: mov ah,0x00
                 ret
I am trying to get the value in c code and then display if the key board is present or not...
but every time its returning garbage value....

pls help

Posted: Mon Feb 18, 2008 5:38 am
by JamesM
Try adding (a) code blocks and (b) COMMENTS, dammit!

Posted: Mon Feb 18, 2008 5:47 am
by naiksidd_85
have done the changes .
:oops:

Posted: Mon Feb 18, 2008 5:51 am
by JamesM
Wouldn't "al" still have garbage data in? You clear eax, then set ax = in(0x60), test bit one, then set ah, but al will still have some garbage.

Try:

Code: Select all

print:
  mov ax,0x01
  ret
areho: 
  mov ax,0x00
  ret 

Posted: Mon Feb 18, 2008 6:00 am
by HeliOS
Yup, this is the solution.. I was thinking on the same lines :)

Posted: Mon Feb 18, 2008 6:01 am
by naiksidd_85
yes thats the problem i get it ......

the code was returning garbage value ........

thanks will try the same .........

Posted: Wed Feb 20, 2008 9:57 pm
by naiksidd_85
HI all,
the tips that you guys gave was quite helpful but i think i messed up some where the key board is detected...
but i still need to give a input in the buffer to validate .....
I want to know how can i do that without even giving any input....

we used to send a interrupt in real mode but in Pmode am not able to figure it out as I am new to coding and not from Computers Background.

Posted: Thu Feb 21, 2008 2:27 am
by JamesM
As said before - *read the PS/2 protocol documentation*. There are commands there that you can send and expect replies to (like, for example, switching the caps-lock LEDs on and off).

Posted: Thu Feb 21, 2008 11:32 pm
by naiksidd_85
Thanks I think I was trying to jump without basics.
I am going through your tutorials.
hopefully it will help.