Remembering old CPU bugs.

I was browsing through the Bonus Chapters for Raymond's book and I remembered an old CPU bug we encountered with the early 286 processors.

Back in those days, it was common to manipulate the processor directly, especially from inside the operating system.

Whenever we needed to have a period of time when we didn't want the OS interrupted by the hardware, we used the handy CLI instruction to turn them off.

The CLI instruction (and it's partner STI) clears (and sets) the "interrupt" flag that's part of the processor state.  There are two other instructions of interest - pushf and popf which push all the processor flags onto the stack and pop them off.

As a result, periodically inside the system ROMs and OS, you'd find the following sequence:

 

pushf                              ; Push flags on the stack
cli                                   ; Disable interrupts, we're doing something

:

:

popf                               ; Restore interrupts to their previous state.

 

The problem was that this version of the 286 had a bug in the popf instruction. If you executed a popf instruction when interrupts were off and the flags value on the stack also had interrupts disabled (in other words you were transitioning from "interrupt disabled" to "interrupt disabled"), the processor would enable interrupts (and then turn them off again).

 

Unfortunately that had the side effect of potentially allowing an interrupt to occur when the system didn't expect it.

I'd forgotten how we fixed the problem, but amazingly enough, the first hit I searched for was from a Mike Abrash article in Byte magazine which (in part) discusses the issue and describes a workaround.