# The 8088 and what the board needs from its core The CPU core is `i8086-python` (`../i8086-python`, Phase 0 only, commits `560ee80`..`6dd7152`). Read its `docs/start-here.md`, `docs/timing.md` and `docs/validation.md` first. This page says what an IBM PC board needs from that core that its brief does not yet promise. Source names: **A81** IBM PC Technical Reference, Aug 1981 (6025008); **A83** the Apr 1983 revision (1502234); **XT** the PC XT Technical Reference, Apr 1983 (1502237); **I83** Intel *Microprocessors and Peripherals Handbook* 1983; page = PDF page / printed label. The 5150 netlist is reenigne's `8088/circuit_5150.txt` (Unlicense; a transcription of IBM's schematics, `reference/src/reenigne`). ## The clocks and the bus (DOC) - 14.31818 MHz crystal, "divided by three for the processor clock and by four to obtain the 3.58 Mhz color burst" (A81 p.19 / 2-3). CPU clock 4.772727 MHz, period 210 ns, 33 % duty (A81 p.26 / 2-10). The PIT gets 1.19318 MHz (A81 p.38 / 2-22): one PIT tick = 4 CPU clocks. - "8088 bus cycles are four clocks of 210 ns or 840 ns. I/O cycles take five 210 ns clocks or 1.05 microsec" (A81 p.19 / 2-3; A81 p.24 / 2-8; A83 p.25 / 1-17). The fifth clock on I/O is one wait state the system board inserts (the "WAIT STATE GENERATOR" schematic sheet, A81 p.309 / D-3; no prose). - I/O CH RDY lengthens cycles "by an integral number of CLK cycles (210 ns)" and must not be held low over 10 clocks (A81 p.27 / 2-11). The MDA inserts "at least one wait state ... on all memory and I/O accesses from the CPU ... synchronized with the character clock" (A81 p.55 / 2-39); the CGA's buffer is dual-ported the same way (video.md). - The 5150 runs the 8088 in **maximum mode** with an 8288 bus controller (ALE "from the 8288", A81 p.26 / 2-10); the PCjr runs it in **minimum mode** (PCjr TR p.32 / 2-6). ## The 8088's bus interface (DOC, I83) - Queue: "The queue length is 4 bytes in the 8088, whereas the 8086 queue contains 6 bytes"; "The 8088 BIU will fetch a new instruction to load into the queue each time there is a 1 byte hole (space available) in the queue. The 8086 waits until a 2-byte space is available" (I83 PDF p.272). - Queue status QS1/QS0: 00 no operation, 01 first byte of opcode from queue, 10 empty the queue, 11 subsequent byte; valid in the clock after the queue operation (I83 PDF p.263). - READY is synchronised by the 8284A; "The 8088 READY input is not synchronized" (I83 PDF p.260). - **How DMA gets the bus on the 5150 (DOC, netlist):** not through RQ/GT. `-RQ/-GT0` goes to the 8087 socket; the DMA hold request is gated with "`-S0 AND -S1 AND -S2 AND -LOCK AND +HRQ DMA`" (the CPU's bus passive and not locked) into a flip-flop that drives `-DMA WAIT` into the 8284A's RDY1 (circuit_5150.txt sheet 2, lines 182-257). So a DMA cycle (including every refresh) **holds the CPU's next bus cycle in wait states** while the 8237 runs; the CPU's execution unit keeps running from its queue until it needs the bus. This is the mechanism the timing-corner demos live with. ## What the board needs, beyond the i8086-python brief The i8086-python brief (its milestones 1-5) is an *instruction* core: `step()` returns Intel table clocks, and its "Scope boundaries" exclude "bus-cycle timing, no prefetch queue model". That is enough for BIOS boot, DOS and most games, and is the right first core. It is **not** enough for the PC's well-known corners: 1. **Cycle-exact execution (rung "BIU" on the core).** Every observable that 8088 MPH, Area 5150, the CGA snow pattern, PC speaker PWM sample players and copy-protection timing loops depend on comes from *when* each bus cycle happens: the 4-byte queue filled a byte at a time, fetches that start two clocks after a byte leaves a full queue (SingleStepTests README, "Prefetched Tests": "It takes two cycles to begin a fetch after reading from a full queue"), the execution unit's microcode timing between bus requests, and the T1-T4/Tw states. Intel's table figures assume a full queue and no waits (i8086-python `docs/timing.md`); on a PC almost no instruction runs that way. 2. **A bus-cycle host interface.** The board, not the core, decides how long each bus cycle lasts: +1 wait state on every I/O cycle, CGA/MDA wait states locked to the card's character clock, DMA holding the bus. So the core must expose its bus cycles to the host one at a time (start a cycle, ask the host for READY each Tw, deliver the data at T3/T4) rather than call `read_byte` and add a fixed count. A clock-by-clock `tick()` or a "run until the next bus cycle" call both satisfy this; open decision 1 recommends the second (it lets the core run the execution unit's internal clocks in bulk between bus cycles). 3. **8088 mode.** The core's 8086 is a 6-byte, 2-byte-hole, 16-bit bus BIU; the 8088 is a 4-byte, 1-byte-hole, 8-bit bus BIU with every word access split into two bus cycles (I83 PDF p.272). The 8088 is a constructor parameter of the same core. 4. **Interrupt acknowledge as bus cycles.** In maximum mode the 8259A is read by two INTA bus cycles, the vector on the second (I83 8259A sheet, PDF p.148-149). The core's `set_intr` with a vector callback is right; the board also needs the two INTA cycles timed as bus cycles (they steal the bus like any other). 5. **The undocumented and the interrupt corners**: the MOV/POP SS shadow, the STI delay, a REP string instruction interrupted with a prefix (the 8088 "forgets" all but the last prefix on resume: i8086-python `docs/undocumented-behavior.md`), POP CS (0F) executing as an instruction on the 8088. All are in the core's brief already. **The oracle for item 1 exists and is hardware-captured:** SingleStepTests/8088 v2 records every clock (bus status, T-state, queue status, data) of 3,007,000 cases on an AMD D8088 (validation.md). The i8086-python brief tells its runner *not* to compare cycles; the board needs a later core rung that does. reenigne's XTCE (`8088/xtce/`, Unlicense) is a cycle-exact 8088+XT emulator whose test generator ran its cases on a real 5160 with DRAM refresh at chosen periods and phases (`xtce/gentests.h`: `_refreshPeriod`, `_refreshPhase`, periods 0, 18, 19, 17 ... in `refreshPeriods[19]`); its microcode-level model (`xtce_microcode.h`) comes from reenigne's own 8086 microcode disassembly (`8088/8086_microcode/`). It is code OK (public domain), and the best *detector* for the board's bus timing with refresh, since SingleStepTests runs with no wait states, no refresh and no interrupts. ## A cost note for the speed section A bus-cycle core costs more than an instruction core: a typical PC instruction is 2-4 bus cycles plus prefetch, and the board must run the BIU's state machine per bus cycle. The domains-and-speed page budgets for one host interaction per bus cycle (~1.19 M bus cycles a second at most: 4.77 MHz / 4).