Silicon reverse-engineering: the Intel 8086 processor's flag circuitry
righto.com
righto.com
https://bytecellar.com/2022/11/16/a-secret-apple-silicon-ext...
But do those uses actually exist? What are those use cases for the flags that isn’t just some straight line code or maybe using some simple branches? Is there code that relies on even weirder cases like creating a fault, with the fault handler depending on correctly set A/P flags? Or did Apple just not want to deal with having flow analyses in their JIT emulator and decided going the hardware route was easier?
For Apple, I'm guessing that failing to emulate even an oddball program would be an unacceptable risk.
Famous last words, "simple". What about sequences like:
pushfd
pop eax
and eax, ebx
Now you need to know what ebx is to know for certain that PF and AF are irrelevant. Which is very likely, but not guaranteed, and the halting problem rears its ugly head.I don't know whether there are good heuristics there or even how common that really is, but my gut feeling is that it may still be easy to "accidentally" drop into the slow AF/PF-preserving case, which can hurt in performance-critical code.
On the other hand, calculating AF/PF in hardware in the first place seems, from my outside view at least, much simpler, and appears to prevent a great deal of potential headache.
As in, memory address $3f8 is just a RAM location and not the same thing as the base register of the COM1 serial port.
This is unlike 1980's home computers that use a 6502, where things like the keyboard interface appear to be just another memory location from software.
Is there anything interesting related to how that is handled in hardware?
As far as the implementation of I/O in the 8086 chip, I haven't come across anything particularly interesting yet. It's essentially the same bus state machine as memory, except it signals an I/O access rather than a memory access.
At the software level, it's accessed by different instructions. Instead of MOV with a memory location, you use IN or OUT. And notably those instructions take only a 16 bit address and no segment selector, so IO space is limited to 64kb.
Also note that to the IBM PC, IO space was routinely truncated to just 10 bits. I honestly don't know if that was ever standardized or not, but that's the way production devices and chipsets have always worked. The extra address lines never worked, and generally aliased with devices in the bottom of the space that were ignoring the top bits.
[1] Actually it's multiplexed in a group of 8 bus states addressed by three lines, because Intel was stingy about pins. But logically it's an extra address line. [This is the spot where I repeat my request to Ken to please do a blog post on the insane bus management on this device, which I'd dearly love to see.]
I'm working on it, but it's a difficult topic. The bus management circuitry is both very complicated (a bunch of flip flops making a complex state machine full of special cases) and lacking in general concepts. So it's hard to figure out how to make it comprehensible and interesting.
Relevant? I'm not a cpu expert.
I guess that many people here will feel similar, given the 8086's role.
I'm not sure if there is a cutoff for what you're able to / interested in exploring.
Also, does LOOP use a different ALU operation to decrement CX, since it doesn't update the flags at all?
For LOOP, the microcode doesn't have the F bit set, so the flags aren't updated from the ALU. Same with NOT.