detecting Keyboard in P mode: how do I do it

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.
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

detecting Keyboard in P mode: how do I do it

Post 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 .
Learning a lot these days THANKS to OSdev users
User avatar
HeliOS
Posts: 2
Joined: Thu Feb 14, 2008 1:23 am

Post 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.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post by xyzzy »

He means he wants to check if the keyboard is plugged in or not.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post 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
Learning a lot these days THANKS to OSdev users
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post 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
Last edited by naiksidd_85 on Mon Feb 18, 2008 5:46 am, edited 2 times in total.
Learning a lot these days THANKS to OSdev users
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Try adding (a) code blocks and (b) COMMENTS, dammit!
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

have done the changes .
:oops:
Learning a lot these days THANKS to OSdev users
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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 
User avatar
HeliOS
Posts: 2
Joined: Thu Feb 14, 2008 1:23 am

Post by HeliOS »

Yup, this is the solution.. I was thinking on the same lines :)
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

yes thats the problem i get it ......

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

thanks will try the same .........
Learning a lot these days THANKS to OSdev users
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post 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.
Learning a lot these days THANKS to OSdev users
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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).
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

Thanks I think I was trying to jump without basics.
I am going through your tutorials.
hopefully it will help.
Learning a lot these days THANKS to OSdev users
Post Reply