Hi,
ARISTOS wrote:A PS\2 keyboard will use 1 of the 3 scancode sets and the USB keyboard?
For BIOS, if there's a PS/2 keyboard in the first PS/2 port the firmware configures the keyboard to use scancode set 2, and enables translation in the PS/2 controller (for backward compatibility purposes with extremely old computers from before PS/2 existed) so that it converts scancode set 2 into scancode set 1. If there's a PS/2 keyboard in the second PS/2 port then firmware will probably ignore it.
For USB keyboards, the keyboards typically support 2 different protocols - one called "Report Protocol" and one called "Boot Protocol". Report Protocol gives you a packet of data, and the format of that data is described by a convoluted (but extremely flexible) description language (that's shared by other "Human Interface Devices", like mouse, joystick, etc). Boot Protocol is designed to emulate legacy PS/2 (without any support for any extra features that a keyboard might have); and in both cases the codes used for keys have nothing to do with PS/2 scan codes (e.g. "A" = 0x04, "B" = 0x05, "C" = 0x06, ..). In general; I'd expect that if "PS/2 emulation" is used then (at most) one USB keyboard will use Boot Protocol; and any other USB keyboards could be left configured for either protocol or not configured at all.
For UEFI the firmware can configure PS/2 hardware and USB hardware however it likes (there is no requirements or guarantees). The only thing that matters is that it implements the EFI_SIMPLE_TEXT_INPUT_PROTOCOL. This protocol supports internationalisation and gives you Unicode characters; and defines its own "scan codes" (that are completely different to anything any keyboard uses) where these scan codes are only used for special keys that have no Unicode character (e.g. cursor keys, home, end, insert, function keys, etc) and there are no scan codes for most keys.
Note: I'd assume that (to make it easier to for "hybrid firmware" to support both UEFI and BIOS) a lot of computers probably set things up the same as BIOS would have when using UEFI.
ARISTOS wrote:If I receive a 0x42 will be 'F8' (PS\2 scancode set 1), 'K' (PS\2 scancode set 2) or a backspace
(USB scancode set) ?
If you receive 0x42 from the BIOS, then it'll be F8 (PS\2 scancode set 1), even though the keyboard itself will use PS\2 scancode set 2 (and would've sent the byte 0x0A, and the PS/2 controller would've translated it into 0x42).
ARISTOS wrote:Also will the BIOS convert USB scancode set ?
What happens when the PS\2 device is emulated by USB devices - BIOS? (how can I ask the "PS\2" keyboard what scancode set it uses)
For "PS/2 emulation" the BIOS has to convert USB codes into PS\2 scancode set 1. In theory, for the "PS/2 emulation" case the firmware should emulate all of the possible commands a PS/2 controller and a PS/2 keyboard would accept (including the "get scancode set" command); but in practice the emulation itself is typically extremely bad (barely able to support simple key presses reliably) and will probably do everything wrong. Because of this; an good OS should always disable "PS/2 emulation" in any/all USB controllers before attempting to touch the PS/2 controller and shouldn't assume things like the "get scancode set" command actually work.
Cheers,
Brendan