maxtherabbit wrote on 2023-10-16, 00:21:
That's not really accurate. Every KBC I've come across with ps/2 mouse support would still function in AT mode when installed in an AT motherboard
Thanks for correcting me: This means, internally the KBC has to detect whether it is inserted into an AT or an PS/2 mainboard, because to keyboard data is wired to a different pin on AT and PS/2 controllers. I can conceive ways how to auto-detect the type of keyboard interface. The KBC then has to use different keyboard interface routines depending on the detection result. I knew that some generic 3rd-party controllers (like the Holtek ones) support both modes, but assumed they need a configuration strap. And I didn't expect the original KBCs on a PS/2 equipped mainboard to be dual-mode at all.
On the other hand, I wouldn't worry that much about the A20/Reset stuff. That one didn't change between AT-type and PS/2-type keybaord controlleres (Note: I'm not talking about actual IBM PS/2 computers, but generic AT-compatible computers with a PS/2 mouse port; original PS/2 hardware might differ). P20 (pin 21) is causing a CPU reset and P21 (pin 22) controls the A20 gate. The command to write custom data to the "output port" (the P2x pins) is D1 since the original AT. On the AT, the complete bit pattern for A20 gate open is "DD", and the complete bit pattern for A20 gate closed is "DF". So you send D1/DD to close the A20 gate and D1/DF to open it. This works on all AT compatible systems. If the actual use of higher bits of the output port don't mix well with the patterns DD and DF, the keyboard controller is going to mask them. The only deviation I know of is that some keyboard controllers implemented the commands DD and DF as shortcuts, making the use of the generic D1 command unnecessessary. This shortcut is not going to work on all KBCs.
Resetting the CPU to leave protected mode is performed by momentarily pulsing P20 low. There is a specific command that can cause pulses on P0..P2, which is Fx. The low 4 bits indicate which pins should be pulsed (0 = pulse low, 1 = don't pulse). To cause a CPU reset, you send the command FE to the keyboard controller. Again, this is universal across all AT-compatible systems.
As both the software interface (commands D1 and FE) and the hardware interface (pins P20 / P21) is identical across all AT compatible machines, I wouldn't expect any A20 trouble when changing the keyboard controller in a standard OEM system (IBM, HP, Compaq or other big brands with custom boards may differ). The only exception could be a BIOS that tries to use the DD/DF shortcuts. I somehow expect that the availability of these shortcuts might be a configurable option in some AMI or Award BIOSes that can be adjusted with the suitable BIOS setup tool like modbin.