Hacker News new | past | comments | ask | show | jobs | submit login
The keyboard controller (computer.rip)
115 points by robin_reala on Dec 19, 2022 | hide | past | favorite | 18 comments



> It's tragic how the modern PC has put us into this situation, where we no longer have control or even visibility into the working of core, privileged components of our computers

It's worrying. These days hardware isn't even managed by the operating system anymore. Hardware makers look at the operating system the same way operating systems look at programs. It's the "user OS" to be isolated from everything else.

https://youtu.be/36myc8wQhLo


Well except Apple, like most things.


But that’s anti-consumer!

Who do you trust? You can’t trust anyone. They drop the ball, “whoops!”, and it’s back in business.

Remember, RSA not only compromised the root keys for their products, they responded by wanting their customers to pay for replacements.


Ever since the KBC was integrated into the chipset, it's not been an 8042 or even any sort of microcontroller anymore but a specialised ASIC core that just handles the interface between the PS/2 ports and the bus.

Chipsets also started including "fast gate A20" via port 92h when the KBC hadn't been integrated into them yet, although I think the newer ones that have both fast A20 and regular KBC A20 control will basically be the same speed for both. (I'll leave it as an exercise for the reader to wonder why A20 control needs to be fast.)

Of course today, we use keyboards and mice primarily via a polling strategy over USB.

You can still get motherboards with a pair of PS/2 ports --- and they're often the high-end gaming/enthusiast-oriented ones too.


> You can still get motherboards with a pair of PS/2 ports --- and they're often the high-end gaming/enthusiast-oriented ones too.

Part of the reason is because USB HID supports 6-key rollover only (whereas PS/2 enables proper NKRO), as cheap keyboards wouldn't include a diode with each switch to properly prevent ghosting. Apparently it does get in the way of some games, but the only case that comes to mind is local multiplayer with the same keyboard, which isn't exactly a common or high-end thing - I imagine most people enjoying local multiplayer on a big screen from a PC would get at least one controller anyway.

So most likely, something to do with latency.


Actually, you can start to see rollover issues with fewer than 6 keys down.

Consider if the keys are (from the perspective of the controller) wired in a 3x3 grid:

A B C

D E F

G H I

Most controllers work by running a signal down the "rows" and reading back on the "columns" (or vice versa) to determine which switches are closed.

If you hold down A and D, and then press either "B" or "E", without diodes, it looks like both B and E are pressed.

Controllers try to mitigate this problem by locking out troublesome combinations, so you end up with worst-case of 2-key rollover. The logical key matrix may end up designed in a way very different from the physical layout, to avoid putting commonly-used-together keys in the same row or column.

This does have non-gaming implications: commands like shift-control-alt-S (IIRC, Photoshop's "save as non-PSD" command) are blocked on some keyboards.


Yep, most "consumer grade" peripherals are a race to the bottom. Diodes are cheap, but manufacturers are cheaper. Unfortunately the protocols follow.


> USB HID supports 6-key rollover only

I don't understand why. In USB HID the report size is practically unlimited. Is there a limit on popular OSes that would be the reason for this ?


Yeah, I'm really leaving out a lot of steps on the evolution to modern machines which I probably could have made more clear. In practice an "8042" keyboard controller was never really that common, as a lot of machines used the 8048 instead. That said there were plenty of laptops especially that used the 8048 for everything we'd expect in a modern EC like the LEDs, screen backlight, etc. The general ACPI architecture still reflects this history in some ways.

NKRO is an interesting issue and I'll probably write a post on it one day, it's not actually a limitation of USB HID as many people think but there is a set of factors that mean that USB HID keyboards usually do not support NKRO (has to do with the BIOS and EFI specs). It's less of an issue these days and there are more NKRO keyboards on the market that don't require device-specific drivers.

That said one of the original motivations for GAMERS to stick to PS/2 is the fact that the PS/2 controller was capable of interrupts, while the USB controller was not, and there were plenty of people who felt that this added up to noticeable latency (perhaps possible under high load conditions but I tend to doubt it). This situation has changed these days with USB 3.0 but I don't see a lot of USB 3.0 keyboards. In practice I think processors got fast enough and the polling loop short enough that people stopped caring. Things like USB interrupt (a different thing than processor interrupts) mitigate the issue by ensuring reliable polling.


> I learned about computer architecture in the days in which the "northbridge" and "southbridge" were the major active components of the system bus... but few computers today have discrete north and south bridges (or front-side and back-side buses for that matter), the functions of the two having been integrated into various combinations of the processor die and a large, monolithic motherboard chipset like the platform controller hub (PCH), with the functions of essentially all motherboard components put into one IC.

Seems somewhat in flux again though, albeit slightly different form!

AMD's been doing chiplets for a while now, with a io die that quite strongly resembles a Northridge in many ways. It sits between cpu, ram, and the rest of the system. Conceptually it seems very similar to a Northridge. But it so happens to be a dedicated die on the multi-chip-module, rather than be on the motherboard.

The southbridge never really left, and I'm not sure if there's any roles it really gave up either... i've thought of it as the platform control hub or io expander for a long time.

But agreed that many embedded chips tend to eskew this pch & just combine all functionally on the main chip, albeit that might be comprised of chiplets.

We've gone to finer levels of integration! But things are much the same.


His recent posts about over the horizon radar are a super good read: https://computer.rip/2022-12-04-over-the-horizon-radar-pt-II...


I love computer.rip, everything is super good read, but I just wish it had some ascii diagrams

I also dislike images, but some phrack style ascii is so beautiful, like the famous issue 49 article 14. I think the information density per symbol (or area) even beats images.


I love ASCII diagrams, and fixed width everything... Until I want to read it on mobile.

If a picture is worth a thousand words, I'll take a thousand words of computer.rip over any picture ;)


This is what's prevented me putting in ASCII-art - the header already explodes on mobile. I force mobile to 40char display width to mitigate it but it's still not a great experience. I probably need to totally rethink how the mobile version works but I'm not much of a web frontend person and I appreciate the simplicity of what I have right now.


Should change the width to max-width and let text flow. Art is different, try to keep it narrow I suppose.


yea its a shame how hard it is to read 79 columns on mobile..


In a shitton of computers the 8042 is not even a separate entity, being emulated by the main CPU through SMM, so that the BIOS can play fancy tricks like allowing a USB keyboard to be read through the 8042 primary PS/2 port.


There's typically a "real[1]" 8042, but with an optional chipset configuration register that diverts accesses to it to SMM instead, even on modern chipsets

[1] Obviously not actually an 8042, but some hardware that would decode those addresses if they weren't trapped beforehand




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: