# Validation: every oracle, what ran here, and the plan ## Tiers | Tier | Meaning | May judge? | | --- | --- | --- | | hardware-captured | values read from a real GBA (a test ROM whose expected results its author checked on hardware, or a fuzz run on hardware) | yes, for exactly what it covers | | manufacturer documentation | ARM's TRM and data sheet | yes where no hardware result contradicts it; it loses to hardware | | hardware-corrected | an emulator or model whose disputed cases were settled on hardware | yes where it has been corrected; a detector elsewhere | | emulator-derived | produced by running an emulator | a detector only | No die-traced or netlist-level model of the ARM7TDMI exists in public (searched 2026-10-21: a die-photo listing, no netlist; the open ARMv4T HDL cores are reimplementations). So unlike sm83-python there is no die model to settle what hardware tests do not cover. ## The oracles | Oracle | Pin | Tier | Judges | Ran here | | --- | --- | --- | --- | --- | | TRM ARM DDI 0029G, DS ARM DDI 0029E | SHA-256 in `pinned_files.json` | manufacturer | cycle types, addresses, widths (timing.md); documented semantics | converted to timing.md | | SingleStepTests ARM7TDMI | `e3097d8` | emulator-derived (NBA fork) | rung 1 gate with overrides | census, referee, multiply model | | NanoBoyAdvance ARM core (GPL-3.0) | Codeberg `master` `e8482c1` | emulator, run closed box (OBSERVED) | detector; the only source of I-cycle sequences | built and run, 2.25 M cases; source never read since the 2026-11-19 rewrite | | zayd's multiplication model | `29cef09` | hardware-corrected (fuzzed on a GBA) | MUL C flag, `m` | built, 53,446 cases | | mGBA suite (`carry`, `multiply-long`, `shifter`) | `e694203` | hardware-captured | ALU carry, long multiply, shifter | not run (needs devkitARM and a board) | | jsmolka `arm.gba`, `thumb.gba` | `a7113b6` | hardware-checked test ROM | instruction semantics | not run (rung 2) | | alyosha-tas tests (`thumb/blx`, `cpy`, `Push/Pop_no_regs`, `arm/Coprocessor_14`, `psr`, `LDM/*`) | `66f5f1d` | hardware-captured (author ran them on a GBA Player) | U4, U7, U14–U17, U19, C6 | 12 run in the minimal harness (rung 3, all pass); `psr` and `Pop_no_regs` need a board's timer or IRQs (rung 5) | | ARMWrestler (destoer's fix) | `802e55a` | hardware-checked test ROM | semantics | not run (interactive: rung 5) | | FuzzARM | `a675329` | emulator-derived (its Python generator computes the expected values) | detector | not run (rung 5) | | mGBA (MPL-2.0) | `fd9dc5c` | emulator, run closed box (OBSERVED) | disassembler detector; C7/C8 runs | built and run; source not read | | ares (ISC), SkyEmu (MIT) ARM cores | `9408cb4`, `9b6bbb6` | emulator (permissive: readable with notice) | detectors for disputes | read only | | MAME 0.285 arm7 core | `f379cd0` (installed 0.285) | emulator; not cycle-exact | detector for real code | not run (needs a GBA BIOS) | | GBATEK | live, fetched 2026-10-21 | community documentation | GBA-side behaviour | cited | ## SingleStepTests ARM7TDMI: what it is From its README (repository `SingleStepTests/ARM7TDMI`, labelled "EXPERIMENTAL"): generated from a fork of NanoBoyAdvance; "any errors in the test are likely errors in my code, not in NBA". Each case loads a state, preloads the pipeline, runs one instruction and records the final state and the bus transactions. The fork and its NBA revision are not published, so the tier is emulator-derived, and its README's known issue (write-back with R15) is C2. Measured here (`scripts/sst_census.py`): - **45 files × 50,000 cases = 2,250,000** (the README says 20,000 per file; every file holds 50,000): 20 ARM files (1,000,000 cases), 25 Thumb (1,250,000), named by instruction class. - **Transactions are reads and writes only.** Kinds: code read, data read, write; sizes 1, 2, 4; access bits from NBA (N/S, code, lock). **No internal cycles are recorded.** The `cycle` field is unreliable (its README says "experimental"): a store's write carries the same cycle number as the fetch before it, and gaps appear only before a refill (1,138 cases in `arm_data_proc_register_shift`, exactly its refills), so I cycles cannot be recovered from it. - **The `access` value in the state is the next fetch's type**, and it encodes the generating emulator's GBA view: N after any I cycle (C1). - **The corpus's state layout** (not documented; found by making the referee agree): `R` holds R0–R15 with **R8–R14 always the User bank**, and `R_fiq`, `R_svc`, ... always hold their own mode's registers, whatever the current mode. Read the other way (R as the current mode's view), 7,103 of 50,000 `arm_data_proc_register_shift` cases disagree with NBA; read this way, none do outside the classes below. - Coverage: unaligned data addresses in the hundreds of thousands (140,198 in `arm_ldm_stm`, 169,064 in `thumb_push_pop`); mode changes in data processing with S and Rd = R15 (~2,000 per file), MSR (4,143 and 4,411); T changes through BX (11,627 ARM, 26,651 Thumb) and MSR (2,386); exception entries through SWI (all executed cases) and undefined coprocessor instructions (25,156 CDP, 25,094 MCR/MRC, 25,266 LDC/STC). - No case uses ARM condition `1111`, IRQ or FIQ entry, or spans two instructions. ## The NBA referee against the corpus `scripts/build_referees.py` builds NBA's ARM core from the pinned Codeberg tree (the GitHub repository closed on 2026-06-21) with stand-in Bus and Scheduler headers (`nba/shim`, GPL-3.0-or-later, kept outside the repository and found at `$EMU_TOOLS_GPL/tools/arm7tdmi-python/nba/`; referees/README.md). It is a closed box: its results are OBSERVED and its source is not read. `scripts/referee_sst.py` loads each case into it, runs one instruction and compares state and bus (with I cycles removed). **Read the agreement as drift, not confirmation.** The corpus was generated from an NBA fork, so this is today's NBA against an older NBA: 97.54% says how far two revisions of one emulator have moved apart, not that a second source agrees. The independent checks in this rung are ARM's cycle tables (timing.md) and zayd's multiply model (below). | Result | Cases | | --- | --- | | state and bus agree | **2,194,656 of 2,250,000 (97.54%)** | | C3: refill fetch address bits 1:0 (only fetch addresses and the pipeline differ) | 33,087 | | C4: LDRSH from an odd address read with width 8 (NBA) or 16 (corpus); same value | 17,145 | | C2: write-back to R15 refills (corpus) or not (NBA): loads | 2,926 | | C2: the same for stores | 2,186 | | unclassified | 0 | `--classify` reproduces the table. 29 of 45 files agree completely, including every branch, MSR/MRS, SWI, undefined-coprocessor and Thumb ALU file. The CP14 cases (C6) agree because both take the trap; the hardware says otherwise. The I cycles NBA makes are in timing.md "Measured"; they match the TRM's tables except the undefined trap (C5). ## zayd's multiply model against the corpus `scripts/multiply_model.py`: of 53,446 executed multiplies (ARM MUL, MLA, UMULL, UMLAL, SMULL, SMLAL, Thumb MUL), results agree in all 47,382 with a comparable destination, the C flag in all 28,508 S forms, and the model's iteration count equals the TRM's `m` in all 53,446. Cases with R15 as an operand compare only when R15 reads address + 12 (U12), which only the emulator-derived corpus shows: not evidence. Since the model was fuzzed against a GBA, this lifts the corpus's multiply files to hardware-corrected for results and C, except for R15-operand cases. ## What was not run, and why - **The test ROMs.** All need either a core (rungs 2–3) or a board (rung 5). jsmolka's `arm.gba`/`thumb.gba` need only RAM, ROM and a DISPSTAT that toggles (handoff-brief.md "The minimal harness"); everything from alyosha-tas uses a timer, interrupts or WAITCNT. - **mGBA suite**: no prebuilt ROM is published; building needs devkitARM (`docker-build.sh`). The board brief should build it once and pin the ROM's hash. - **MAME**: its `gba` driver needs `gba.bin` (BYOR; the retail dump is in the No-Intro tree, see gba-python's validation.md; gba-python found MAME 0.285 fails most CPU and memory tests with it) or a free replacement BIOS; it is an instruction-level detector, and the corpus plus NBA already cover what it would. - **mGBA, ares, SkyEmu** as second instruction-level referees: not built; worth doing only for a dispute the corpus and NBA cannot settle (mGBA closed box only). ## The plan | Rung | What | Acceptance | | --- | --- | --- | | 0 | Generated decode tables; schedule test from timing.md; readability test | every class's (type, address, width) sequence equals the converted TRM table | | 1 | SingleStepTests ARM7TDMI, all 2.25 M cases | state, banks, pipeline, `next_fetch_seq`, transactions (kind, width, address, write data, N/S, code, lock) equal after the override file, excluded classes skipped; I-cycle counts equal NBA's except C5; S-after-I mapped to N per C1 by the shared `gba_access` helper | | 2 | jsmolka `arm.gba`, `thumb.gba` in the harness | r12 = 0 at the result screen | | 3 | alyosha-tas `arm/arm.gba` and the `thumb/` additions that need no timer (`blx`, `cpy`) in the harness | pass | | 4 | Multiply model on random and edge operands (the model, not the corpus, as judge); needs no harness, so it gates alongside rung 1 | results, C and `m` equal for 10^6 random cases per form | | 5 | Through gba-python: ARMWrestler, FuzzARM, mGBA suite `carry`/`multiply-long`/`shifter`/`timing`, alyosha-tas `psr`, `LDM/*`, `Coprocessor_14`, `Push/Pop_no_regs` | pass; failures that are the core's come back here | **The override file** (`tests/sst_overrides.json`, written in rung 1): one entry per class, with the rule the core follows and the evidence, applied to the corpus's expected values before comparing. A class marked *excluded* is skipped by the gate and reported as a count, never as a pass: | Class | Cases | Core follows | Override | | --- | --- | --- | --- | | C1 S after I | all loads, multiplies, register shifts, swaps, MRC | TRM (S) | map the core's S-after-I to N | | C2 write-back to R15 | 5,112 | neither (core refills; corpus author lists it as a known issue) | excluded as unverified | | C3 refill address bits | 33,087 | corpus | none | | C4 LDRSH odd width | 17,145 | corpus (16) | none | | C5 undefined trap I | 74,016 (75,516 traps less C6's 1,500) | TRM | compare I cycles to NBA + 1 | | C6 CP14 MRC/MCR, the four encodings alyosha-tas tests | those of the 1,500 that match | hardware | expected = what `Coprocessor_14` observed (U17) | | C6 CP14 MRC/MCR, every other encoding | the rest of the 1,500 | untested | excluded as unverified | | C7 Thumb `0xDExx` | 50,000 (`thumb_undefined_bcc`) | undefined trap, provisional (user decision 4) | excluded until a hardware test ROM decides; emulators split 2–2 | | C10 LOCK on SWP read | 24,910 executed swaps | TRM | ignore LOCK on the read | So against the corpus the core needs overrides only where it deliberately follows the TRM or hardware (C1, C5, the tested part of C6, C10). Where the corpus and NBA disagree on an unverified case, the core follows the corpus only when nothing argues against it (C3, C4); C2, where the corpus's own author doubts it, and the untested parts of C6 and C7 are excluded rather than given expected values the core would have to invent. The S-after-I rule (C1) is written once, as `arm7tdmi_python.gba_access`, and both the rung-1 comparison and gba-python call it, so the conversion the gate checks is the one the board uses. ## Results (2026-10-22, the first build) Measured on this machine (32 threads); tiers as above. **Rung 0** (`tests/test_tables.py`, `test_bus_schedule.py`, `test_readability.py`): the decode tables are generated by `scripts/gen_tables.py` and checked current; 48 bus schedules (every class and path of timing.md's tables, plus the m = 1–4 multiply rows and IRQ entry in both states) equal the converted TRM tables cycle for cycle (type, address, width) and in the next fetch's type. Manufacturer documentation as judge. **Rung 1** (`scripts/sst_gate.py`; a detector, the corpus is NBA-derived): | | Cases | | --- | --- | | gated, all pass | **2,192,923 of 2,192,923** | | excluded C2 (by encoding: Rn = R15 with write-back, executed) | 5,578 | | excluded C6 (CP14 encodings no hardware test covers) | 1,499 | | excluded C7 (`thumb_undefined_bcc`) | 50,000 | | overridden C6 (the tested encodings; 1 corpus case matches) | 1 (passes) | C2's 5,578 is every executed case with that encoding; the referee's 5,112 are the subset where the corpus and NBA differ. Faults injected into the core (a flipped subtraction bit, a dropped I cycle) fail thousands of cases, so the gate is not vacuous. **Rung 1, I cycles** (`scripts/referee_icycles.py`, against NBA's core): 2,118,750 cases have the same sequence of cycle kinds; 74,016 differ by the TRM's I cycle in the undefined trap (C5) and 156 by the TRM's I cycle in Thumb POP/LDMIA with an empty list (C11, found here); none unexplained. **Rung 4** (`scripts/multiply_judge.py`; zayd's model, hardware-corrected, as judge): MUL, MLA, UMULL, UMLAL, SMULL, SMLAL (all with S) and Thumb MUL, 10^6 cases each (every pair of 32 edge operands, then random operands spread over 1–4 significant bytes and both signs): result, C and `m` agree in **7,000,000 of 7,000,000**. Faults injected into the carry or the cycle count fail. **Speed** (CPU time per corpus case, harness included, summed over the 45 files): CPython 3.14 49 µs, PyPy 7.3.20 86 µs (each process runs 50,000 one-instruction cases, too short for PyPy's JIT to pay). Wall time with 16 processes: 8 s and 14 s. Rung 4 with 28 processes: 11 s and 24 s. **Rungs 2 and 3** (`tests/test_roms.py`, the minimal harness `arm7tdmi_python.harness`): jsmolka `arm.gba` and `thumb.gba`, alyosha-tas `arm/arm.gba`, `thumb/blx.gba` and `thumb/cpy.gba` all reach their result loop with R12 = 0 (hardware-checked test ROMs; blx and cpy are hardware tests of U19). Since the 2026-11-19 rewrite also alyosha-tas `arm/Coprocessor_14`, `thumb/Push_no_regs` and the eight `LDM/*` tests of the LDM^ glitch (U7): 15 ROMs, all pass (the pre-rewrite core passed 4 of the 8 `LDM/*` ROMs). A failing jsmolka test draws its number with BIOS division (SWI 6), so in the harness a failure ends at the BIOS vector with R12 set; faults injected into the core end there with the failing test's number (for example 151 and 52 for logical operations that clear C, 355 and 204 for loads that do not rotate). Throughput in the harness: about 0.3 to 0.5 M bus cycles per second on either interpreter. **Corrected here:** U9's "Rs = R15 reads plus 12" is plus 8 (1,591 corpus cases). **Found here:** C11 and U21. ### After the 2026-11-19 provenance rewrite The pieces written with NanoBoyAdvance's source open were removed unread and rewritten (docs/provenance.md "Wave 2"). Measured at the rewrite's commits on 2026-11-19, PyPy 7.3.20, against the pre-rewrite core (`51bb589`) run the same way: | Gate | Before (`51bb589`) | After | | --- | --- | --- | | Rung 1, corpus | 2,192,923 of 2,192,923; excluded C2 5,578, C6 1,499, C7 50,000 | the same | | Rung 1, I cycles vs NBA | agree 2,118,750; C5 74,016; C11 156 | the same | | Rung 4, multiply judge | 7,000,000 of 7,000,000 (recorded 2026-10-22) | 7,000,000 of 7,000,000 | | Rungs 2–3, ROMs | 5 of 5 (the 10 added ROMs: 6 pass) | 15 of 15 | | `pytest` (slow included) | 492 passed | 502 passed (10 added ROMs) | | Disassembler judge | no unexplained differences | no unexplained differences (147 more encodings classed "should-be bits differ": post-indexed halfword transfers with W = 1 are now marked nonstandard) |