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.
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?
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.
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.
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.
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!