Email or username:

Password:

Forgot your password?
Ken Shirriff

What's inside the famous 8086 processor from 1978? I opened up a chip, took microscope photos, and I'm reverse-engineering it. One of the 8086's instructions is HLT, which halts the processohttps://pbs.twimg.com/media/FnalrlNXEBoU1I_?format=jpg&name=4096x4096r. Seems simple, but there's a lot of circuitry to make the halt instruction work... 🧵

10 comments
Ken Shirriff

This diagram shows the main parts of the 8086 chip; dark labels are affected by HALT. The 8086 is partitioned into an Execution Unit which executes instructions, and a Bus Interface Unit which performs memory operations and preloads instructions into the prefetch queue.

Ken Shirriff

Most 8086 instructions are implemented in microcode, but some are implemented in logic. The Group Decode ROM starts by categorizing instructions. The red rectangle detects 1-byte-logic instructions that don't use microcode. The yellow rectangle detects the HLT instruction.

Ken Shirriff

The Bus Interface Unit has a lot of flip-flops to manage memory accesses. When a HALT comes in, it finishes any current memory access but new ones are stopped. In particular, the prefetch circuitry is blocked. A special mini-memory-cycle indicates the CPU is in the halt state.

Ken Shirriff

The CPU sits in the HALT state until an interrupt or reset signal comes in. This starts a microcode routine to handle the interrupt. The interrupt also blocks the Group Decode ROM from decoding the HLT instruction, ending the HALT state.

Ken Shirriff

On the 8086, even something that seems simple like halting the processor has a bunch of complexity and tricky circuitry. For more information, see my latest blog post: righto.com/2023/01/reverse-eng

penguin42

@kenshirriff Oh the references to the datapoint and the origin of parity/little endian in the 8086 are fascinating!

Craig P

@kenshirriff well, here it is. The most heiroglyphical circuit diagram.

Henry H

@kenshirriff

Amazing. I can only imagine what programming in assembler with this level of understanding would be like.

Григорий Клюшников

Henry, some people optimize their code to take advantage of caches and pipelining in modern CPUs. I have a fairly good understanding of how old, "straightforward" CPUs work, but this stuff is just witchcraft to me.

Joe Wein

@kenshirriff

The CP/M 2.2 command processor for the 8080 checked the Digital Research copyright notice and executed a HLT instruction to lock up the machine if it had been tampered with (e.g. pirated copy of the OS).

The 8086 version of CP/M used the same machine translated code, but typical 8086/88 machines were interrupt driven, waking the machine again at the next keystroke and thus rendering the anti-piracy check toothless.

Go Up