OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Dec 11, 2018 11:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Can't set PS/2 scancode set in Virtualbox
PostPosted: Fri May 11, 2018 8:45 am 
Offline
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 20
Location: Poland
Hi. I'm working on my OS and I ran into a problem. When trying to set the scancode set to 1 using the following code:
Code:
outb(0x60, 0xF0);
outb(0x60, 0x01);
VirtualBox seems to ignore it completly and keeps using the scancode set 2. The code works correctly in QEMU and on real hardware and I can correctly set the scancode set. I also checked the current keyboard scancode set and it remains at 2 on VirtualBox. Does anyone know how to fix that issue? Or is it something to do with VirtualBox?

Thanks for help in advance.
qookie

_________________
quack, my small operating system project


Top
 Profile  
 
 Post subject: Re: Can't set PS/2 scancode set in Virtualbox
PostPosted: Fri May 11, 2018 9:57 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1359
Why are you trying to use scan code set 1? Every real OS uses scan code set 2, so it's possible VirtualBox simply can't handle set 1.

qookie wrote:
The code works correctly [...] on real hardware

I'm surprised it works on real hardware, since you're not waiting for the keyboard controller to be ready before you send each byte. Actually, the hardware you're using probably doesn't have a "real" keyboard controller, since it should take hundreds of microseconds to send a single byte to the keyboard, and a "real" keyboard controller can't accept another byte while it sends the first one.

Since you're able to get the scan code set but not set it, the lack of appropriate delays is probably not why VirtualBox doesn't work - but emulators are known to be inaccurate, so it's still a possibility.


Top
 Profile  
 
 Post subject: Re: Can't set PS/2 scancode set in Virtualbox
PostPosted: Fri May 11, 2018 11:10 am 
Offline
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 20
Location: Poland
I have ommited the calls to wait function in the code snippet. I wait for the input buffer to be empty before sending each byte and waiting for the output buffer to be full to read bytes from the keyboard. Probably should have put the calls to wait functions in the code to make it clearer.

_________________
quack, my small operating system project


Top
 Profile  
 
 Post subject: Re: Can't set PS/2 scancode set in Virtualbox
PostPosted: Sat May 12, 2018 3:28 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

qookie wrote:
VirtualBox seems to ignore it completly and keeps using the scancode set 2. The code works correctly in QEMU and on real hardware and I can correctly set the scancode set. I also checked the current keyboard scancode set and it remains at 2 on VirtualBox. Does anyone know how to fix that issue? Or is it something to do with VirtualBox?


All real keyboards (since "IBM Personal System/2" was released in the 1980s) support scancode set 2, but there's no guarantee that a keyboard will support any other scan code set. If a keyboard doesn't support a scancode set then it may pretend that the command worked but do nothing. VirtualBox is correctly emulating a real keyboard that doesn't support scancode set 1 - there's no bug in VirtualBox.

To fix the issue, you can:
  • Forget about scancode set 1 and only bother with scancode set 2, and disable translation in the PS/2 controller. This should have no issues, even when the keyboard happens to be plugged into the second PS/2 port.
  • Try to set the keyboard to scancode set 1 and detect if it is/isn't supported (by asking keyboard which scancode set is currently being used). If it is supported make sure translation is disabled in the PS/2 controller (and end up with scancode set 1). If scancode set 1 is not supported by the keyboard but is plugged into the first PS/2 port then set scancode set 2 and enable translation in the PS/2 controller (and end up with scancode set 1), and if the keyboard is in the second PS/2 port then you have no choice and will have to use scancode set 2 (or not support the keyboard).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Can't set PS/2 scancode set in Virtualbox
PostPosted: Sat May 12, 2018 5:25 am 
Offline
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 20
Location: Poland
Thank you for your answers Brendan and Octocontrabass. I think I'll start using the scancode set 2 to fix the problem. I also had no idea keyboards don't need to support the scancode set 1, so thanks for letting me know!

_________________
quack, my small operating system project


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group