# Pipeline, hazards, the delay slot, and Atari's bug lists What a program can see of the pipeline, and every hardware bug Atari documented for the two processors, with what is known of the games that meet each one. Tick counts are in [timing.md](timing.md); interrupts in [interrupts.md](interrupts.md). Sources: TRM = *Technical Reference Manual* rev. 8 (manufacturer): pipeline p.33-35, flow control p.39-40, "Writing Fast GPU Programs" p.61-63, the Tom & Jerry bugs list p.133-141. **HWB** = *Hardware Bugs & Warnings*, Atari, 26 April 1995 (manufacturer; scanned, OCR in `reference/text/hwbugs/`), items "GPU/DSP" 1-11. Netlist files under `NET/` = `reference/src/JagNetlists/netlists_org/`. ## The pipeline as a programmer sees it - **Stages** (TRM p.33-34): decode, read operands, compute, write back. An instruction is "executing" in the tick it reads its registers (cycle 1 in the manual's per-instruction "Register Usage"); ALU results are written at cycle 3, MOVE/MOVEQ/MOVE PC/MOVETA/MOVEFA at cycle 2, MOVEI at 3, internal loads at 3-4 (indexed 5-6), DIV at 18, external loads when the bus delivers. - **Prefetch**: instructions are fetched as long words from a long boundary (`PREFETCH.NET` header, 7/2/91). The header still says "a 32-bit prefetch queue holding a total of two instructions", but the logic as it stands has **two 32-bit stages** (`Pfbuf1` and `Insdata`) and a queue-size state machine counting 0-4 words (`PREFETCH.NET` l.132-240: "valid data in the first stage, given by a queue size of 3 or 4"), which is what Tom bug 14 says: "The pre-fetch queue is two long-words ... it always contains three or four instruction words if no instructions are being used". A fetch is requested "whenever there is room for two more instructions" and "is always cleared by jump". BIG_INSTR swaps which half of the long executes first (`Ins_swap`). - **Local bus priority** (TRM p.36): CPU (slave) access > operand transfer > instruction fetch. Program fetch from local RAM uses less than half its bandwidth (TRM p.35). ## The delay slot and jumps - "The instruction after a jump is always executed" (TRM p.39), taken or not, and the jump and its slot are **atomic** (TRM p.39; `PREFETCH.NET` 10/12/91: "Jumps must be atomic with the subsequent instruction or all hell breaks loose"). No interrupt is taken between them. - **JR's target is computed one tick later than JUMP's** (`PREFETCH.NET` 10/9/91: computed from the pipelined source `srcdp`, "which means computing the relative jump one tick later"); JR's offset is relative to the instruction after the JR (TRM p.48). - **Illegal sequences** (TRM p.40): MOVEI in a delay slot ("the jump will take effect before the data is fetched"), two jumps in a row ("results are not predictable"), MOVE PC in a delay slot ("the value read can not be relied upon"), anything but IMACN/RESMAC after IMULTN/IMACN, LOAD/STORE immediately before MMULT. The rev. 8 appendix also says the restrictions of the *previous* (prototype) bugs list "are lifted ... illegal instruction sequences given in that bugs list can all now be disregarded" (TRM p.131), while keeping this list in the GPU chapter (C8). What the hardware actually does for each is U5. - **"Lies and Damned Lies"** (TRM p.140), allegations Atari reports without endorsing: a jump then an indexed load/store crashes with interrupts on (Paul Foster & ATD); no jump directly to an MMULT; two instructions needed between MMULTs; no MMULT in a delay slot; and **IMASK cannot be cleared in the delay slot of the return jump "because the instruction that was interrupted may not get the correct register bank" (TWI, Brian McKee)**, although the manual's own example service routine (TRM p.38-39) does exactly that with `store r29,(r30)` in the slot. MAME's `m_branch_hack` (taken jump reads the *other* bank's register when it executes in the tick a bank swap happened) is a workaround for CoJag DSP handlers that hit this region (`jump_cc_rn` comment). U13. ## The scoreboard TRM p.34-35 and p.61-62, `SBOARD.NET` header (18/4/91): - Protected: **reads** of a register still being computed by the ALU, of a divide's destination, of an internal load's destination, of an external load's destination; a flags-dependent instruction (conditional jump, ADDC, SUBC) while flags are pending. The instruction waits. - **Not protected: writes.** "If two instructions both write to the same register and the first one completes after the second, the data will be written out of sequence" (TRM p.35). Bug 13 below. - **Register file ports**: the file is dual-ported. A pending write-back is concealed if the next instruction reads that register or reads fewer than two registers; otherwise the pipeline holds one tick to write. Two write-backs due at once cost a tick (TRM p.35, p.61). The libretro project reports from a Verilator run that in practice this makes back-to-back register-writing ALU instructions with disjoint registers cost two ticks each (C5). - **Memory interface**: one internal load/store, or two external ones, may be pending without holding the stream; a further load/store waits (TRM p.62). - "Load and store operations ... it is quite safe to use the same register as both operands" (TRM p.37). ## The bug lists, item by item Tom bugs are numbered as in TRM p.133-140 ("revision code 2 silicon"); Jerry bugs p.141; HWB items as numbered on its pages 1-3. Only items that touch the processors are listed; the Blitter, OP and video ones belong to the board. | # | Source | Bug | Where it lives | Core or board | Games known to meet it | | --- | --- | --- | --- | --- | --- | | B1 | Tom 2, HWB 1 | indexed stores (49, 50, 60, 61) do not scoreboard their **data** register: storing a DIV or external-load result writes the old value | `SBOARD.NET` 30/10/92 note: `STORE (r14+r3),r2` needs three registers protected, "just not possible" | core (follows from a scoreboard model that checks only address registers for these four) | none named | | B2 | Tom 13, HWB 2 | a later "destination write-only" instruction (MOVE, MOVEQ, MOVEI, MOVETA/FA, MOVE PC, all LOADs, MTOI, NORMI, RESMAC) can be overwritten by an earlier slower write to the same register with no read between (`load (r3),r2; moveq 3,r2` leaves the load data; `div r2,r4; moveq #4,r4`; even `add r10,r12; moveq #1,r12`) | write-back ordering, no write protection | core (falls out of modelling write-back time per source) | none named; HWB shows it at loop exits | | B3 | Tom 14 | single-step with MOVEI as the first instruction of an external program: MOVEI executes as soon as the first long arrives and empties the queue | prefetch | core (only matters for a debugger that single-steps via the control register) | none | | B4 | Tom 15, HWB 3 | JUMP/JR executed from **external** memory can leave invalid data in the prefetch queue ("rules out almost all programs") | prefetch vs gateway timing | core, needs the gateway timing to reproduce | later software runs GPU code from DRAM anyway (board's `bus-arbitration.md`, unverified per title); U14 | | B5 | Tom 16, HWB 8 | HIDATA (`F02118`) has no scoreboard and is changed by **any** external load, so an interrupt that loads externally corrupts an underlying LOADP | gateway | core | none named | | B6 | Tom 23, HWB 6 | GO may only be cleared by the processor itself; an external clear "is intermittent" | `GPU_CTRL` | core: model a clean stop; log external GO clears | none named | | B7 | Tom 25, HWB 9 | two divides less than 16 ticks apart where the second uses the first quotient and nothing reads it in between: **second result wrong** ("divide length counter is not reset") | `DIVIDE.NET` | core | none named; what the wrong value is: U4 | | B8 | Tom 12, Jerry 3, HWB 7 | Jerry can latch wrong write data from a one-tick bus grant; an external DSP write must follow a **completed** external read | Tom arbiter vs Jerry gateway | board (arbiter) with a core flag; AtariAge thread 326379 (2021) discusses it, no measurement | none named | | B9 | Jerry 6, HWB 10 | DSP MMULT matrix only in the low 4 KB (`F1Bxxx` hard-wired) | `SYSTOLIC` address | core (variant data) | none | | B10 | Jerry 2 | slave reads of DSP space only work at IOSPEED = 3 | Jerry slave port | board | none | | B11 | HWB 4 | **DSP with DMAEN set hangs** on an external load or store, "needing a reset to recover" | Jerry gateway | core flag + board; recommended: log and halt the DSP | none | | B12 | Tom 24, HWB 5 | GPU DMAEN (or Blitter BUSHI) above the OP corrupts line-buffer addresses (black stripes) | arbiter | board | none named | | B13 | HWB 11, TRM p.59 | a value stored to FLAGS (flags, REGPAGE) is not seen by the next instruction(s): TRM "at least one other instruction", HWB "two NOP instructions" | flag write vs pipeline | core | the CoJag trace shows `store r22,(r21)` to FLAGS followed by two NOPs (fishfren, [mame-oracle.md](mame-oracle.md)); C1 | | B14 | HWB p.6 item 2 | the 68000's `clr.l` and `move.l ,-(an)` write the two halves of a long in reverse order, which breaks writes to GPU/DSP registers and RAM | 68000 bus order + the slave port's pairing | board (it owns the 16-bit pairing), core only if it owns the pairing latch | none named | Not core: Tom 1, 3-5, 7-11, 17-22, 26-29, Jerry 1, 4, 5 (Blitter, OP, video, pins, 32-bit hosts). ## What emulators do with these (detectors) - **MAME 0.285**: no pipeline, no scoreboard, so B1, B2, B5, B7, B13 cannot happen; delay slot executed inside the jump handler (no interrupt between); `ABS` of `80000000` keeps the value and sets N ("towers2 and chekflag will hit this"); interrupt latch set only while enabled (comment names barkley, breakout, clubdriv, ironsol2, skyhamm, ultravor); the `m_branch_hack` above; R30 set to the vector at entry "(kasumi)"; "feverpit doesn't want" the bank swap gated on GO. - **Virtual Jaguar** (https://github.com/mirror/virtualjaguar @ `8d86cf72`, GPL-3, not fetched since 2026-11-24): its source comments, read in Phase 0, tie *Flip Out* (GPU timing instead of semaphores) and *Rayman*, *FACTS* and *Tripper Getem* (DSP sound starved without a timing cheat) to processor timing (HYPOTHESIS, source-read; for review). Those are the only titles any source ties to processor timing. - **libretro Virtual Jaguar** (`8543bbff`, GPL-3): `docs/gpu-timing-spec.md` is a careful netlist reading with evidence tags; its ยง14 reports Verilator results (second-hand: the rig is not published). No game is documented anywhere as *relying on* a bug's wrong result; the leads above are games that meet a corner (U7). A core that models the pipeline faithfully reproduces B1, B2, B5, B7 and B13 without special cases, which is the argument for modelling write-back times rather than retiring each instruction at once ([handoff-brief.md](handoff-brief.md), decision 4).