Table of Contents

PS/2 and the 8042 controller

PS/2 is the keyboard and mouse interface of IBM-compatible PCs. Each device talks over a serial line to a controller on the motherboard, the 8042, named after the Intel microcontroller of the PC/AT; many PCs still provide one, sometimes emulated by the firmware. Its first port serves the keyboard and its second, the auxiliary port, a mouse; the CPU reaches it through two I/O ports: 0x60 carries data bytes both ways, and 0x64 is the status register when read and takes controller commands when written. The keyboard port raises IRQ 1, the mouse port IRQ 12.

Commands come at two levels. The controller's own, written to 0x64, read and write its configuration byte, run its self test and test or enable each port. A device's commands are written as data to 0x60, to the second port after a 0xD4 written to 0x64: reset, identify, set the keyboard's lights, enable scanning. The device acknowledges each command byte with 0xFA, or asks for it again with 0xFE, then sends any reply; a reset is answered 0xAA once the device passes its self test.

Once scanning is enabled, the keyboard sends a code for each key press and another for each release, in one of three scan code sets, and the controller can translate set 2 into the older set 1. A mouse, once reporting, sends three-byte movement packets, four bytes for a wheel mouse. The trap is the shared data port: a command's acknowledgements and replies arrive untagged among the stream, so a driver that sends a command while the user types must sort the bytes it reads.

In the driver kit, I8042Driver owns the controller: it tests it and both ports, turns translation on so the keyboard port delivers set 1 codes, connects IRQ 1 and IRQ 12 or polls instead, and publishes one node per working port. A class driver talks through Ps2Access, whose TryCommand waits for each Acknowledge, resends on Resend up to MaxResends times and collects the reply; every other byte joins the stream the handler drains with TryReceive. See PS/2 devices and The PS/2 access object.