# Provenance Audit of 2026-11-13 (provenance audit wave 1), against the family charter's "Licences and provenance" rules: nothing copied or transcribed from GPL, LGPL or unlicensed code; facts about the chip are not code; other emulators may be run as closed boxes; permissive sources are used with their notice kept. No GPL source was opened for this audit. Evidence is this repository's own records: docstrings, `docs/undocumented-behavior.md`, `docs/validation.md`, `scripts/pinned_repos.json` and `pinned_files.json` (whose notes show that the Phase 0 research read the GPL references it fetched: Mednafen, Ymir, Kronos, Yabause, jgenesis, and the unlicensed srg320 RTL). `provenance_check.py` was run against the permissive references only (below). ## Summary | Verdict | Count (wave 1) | After the wave 2 rewrite (2026-11-19) | | --- | ---: | ---: | | clean | 14 | 22 | | cite | 4 | 0 | | rewrite | 4 | 0 | | unclear | 0 | 0 | Wave 2 (2026-11-19, in place) is recorded in [Wave 2 rewrite](#wave-2-rewrite-2026-11-19) below; the rows of the tables are updated with their new source and verdict. ## The core (`src/sh2_python/`) | Piece | Where its behaviour came from | Source licence | Verdict | | --- | --- | --- | --- | | `_decode.py` | generated by `scripts/gen_decode.py` from PM appendix A table A.50 (`scripts/extract_pm_tables.py` reads the PDF) | Hitachi manual (facts) | clean | | `_arith.py`, `_logic.py`, `_shift.py`, `_transfer.py`, `_branch.py`, `_system.py`, `_multiply.py` | PM/SWM instruction descriptions; ambiguous results ruled by the rung-1 corpus, where MAME 0.285 (BSD-3-Clause SH-2 files) and jgenesis (GPL-3.0) were **run** as closed boxes and agreed, or by the manuals (`validation/rung1/overrides.json`) | manuals; closed box | clean | | `_arith.py` DIV1 ("PM 6.19's code, transcribed") | the manual's own C description of DIV1 (now the shared `div1_step`) | Hitachi manual | clean (wave 2): PM citation kept; the chip maker's own description | | `_multiply.py` MAC.W/MAC.L saturation | PM code annotation and prose (C11); MAME and jgenesis run | manual; closed box | clean | | `pipeline.py` stage scheduler | PM section 7 figures, reproduced state for state (rung 3) | manual | clean | | `cache.py` | HM chapter 8, tables 8.3/8.4 (LRU bits) | manual | clean | | `bsc.py` (incl. write buffer, SDRAM) | HM chapter 7; Dunkley's CPS3 measurements (DN/DP) | manual; CC-BY-4.0 | clean (attribution present in docs and `validation/rung4/dn_p2.json`) | | `intc.py`, `dmac.py`, `frt.py`, `sci.py`, `ubc.py`, `power.py` | HM chapters | manual | clean | | `divu.py` (whole module; was `partial_64`, `_divide_32`, `_divide_64`) | wave 1: Mednafen's code paths. **Wave 2**: removed unread, rewritten from HM 10.2.2, 10.3.1-10.3.3, table 10.2 (DOC); the early state after an overflow from PM 6.19 example 4 run three steps (`early_state`, HYPOTHESIS); the divide-by-zero sign (HYPOTHESIS; jgenesis `d41e2d9` closed box agrees, OBSERVED); round-toward-zero remainder sign (MAME 0.285 `sh7604.cpp` BSD-3 read, jgenesis closed box: OBSERVED) | manuals; BSD-3; closed box | clean (wave 2) | | `_core.py` read of the associative-purge space; H'A0000000 | wave 1: Mednafen. **Wave 2**: a read purges nothing and reads 0; H'A0000000- is reserved (reads 0, writes ignored); HM 8.4.7, tables 7.3 and 8.2; own choice (HYPOTHESIS) | manual | clean (wave 2) | | `wdt.py` H'FFFFFE82 read | wave 1: Mednafen comment, H'FF. **Wave 2**: reads 0, own choice (HM lists no read there), quote dropped | manual | clean (wave 2) | | `divu.py` register map and mirrors | MAME 0.285 `sh7604.cpp` (BSD-3-Clause), HM table 10.2 | BSD-3-Clause; manual | clean | | `disasm.py` | PM mnemonics; number format after MAME's `sh_dasm.cpp` (BSD-3-Clause) | BSD-3-Clause | clean | | `cpu.py`, `bus.py`, `debug.py`, `console.py`, `trace.py`, `state.py`, `harness.py`, `_module.py` | own | — | clean | | SPDX headers | wave 2: `SPDX-License-Identifier: MIT` on every file in `src/` (`_decode.py` through its generator), `tests/test_modules.py` and the jgenesis harness; `NOTICE` lists the permissive notices | — | clean (wave 2) | ## Validation, tests and tools | Piece | Source | Licence / terms | Verdict | | --- | --- | --- | --- | | `validation/rung1/` corpus (`cases`, `expected`), `overrides.json` | cases generated here; expected values from running MAME (`-nodrc`) and jgenesis | closed-box outputs | clean | | `validation/jgenesis_harness/` (until 2026-11-22; History) | own glue against jgenesis' `sh2-emu` public API; built in `reference/build/`, never distributed | jgenesis GPL-3.0 | clean (wave 2): its header and NOTICE say the built binary is a GPL-3.0 tool (there is no `validation/rung1/README.md`; `gate.py`'s docstring describes the referees) | | `tests/data/disasm_mame.txt.gz`, `disasm_jgenesis.txt.gz` | disassembler outputs | closed-box outputs | clean | | `validation/rung4/dn_p2.json`, `scripts/extract_dn_rung4.py` | Dunkley's CPS3 companion data | CC-BY-4.0, attributed in the file | clean | | `validation/rung2/replay.py`, `scripts/mame_trace.py` | MAME 0.285 run as a closed box | — | clean (but `mame_trace.py` hard-codes a machine ROM path: a house-rule item, use `MAME_ROMPATH`) | | `docs/undocumented-behavior.md`, `docs/validation.md`, `docs/timing.md`, `docs/README.md`, `docs/start-here.md`, `docs/handoff-brief.md`, `scripts/pinned_*.json` notes | wave 1: code fragments and source comments from Mednafen, Ymir, srg320's RTL. **Wave 2**: every GPL/unlicensed code fragment, identifier, source comment and description of their internals removed (U2, U7, U8, U10, U12-U16, U18, C2, C4, C8, C9, the divider's timing note); Dunkley's prose findings and ares (ISC, in NOTICE) stay; Ymir's test vectors are no longer planned as data, only closed-box runs | manuals; CC-BY-4.0; ISC | clean (wave 2) | ## provenance_check runs (2026-11-13) - `--repo src --reference reference/src/ares --licences scripts/pinned_repos.json` (ares SH-2, ISC): 0 file pairs with hits. - `--repo src --reference reference/src/mame ...` (MAME 0.285 `src/devices/cpu/sh/`, BSD-3-Clause per file headers): 0 file pairs with hits. - Not run against Mednafen, Ymir, Kronos, Yabause, jgenesis (GPL), PicoDrive (non-commercial) or the MiSTer RTL (no licence). The Mednafen items above are settled by this repository's own docstrings; no comparison was needed. ## History Public repository (alewman/sh2-python); no tags, not on PyPI. | What | Introduced | Where it is | | --- | --- | --- | | Mednafen-derived DIVU paths, purge-space read, WDT H'FF | `deaabee` (2026-10-23, rung 0) | every commit since, `main`, `sdram-bsc`, `table-at-class` (all on origin) | | Mednafen/srg320 code fragments in docs | `6460ced` (2026-10-21) | every commit since | No deleted file. Downstream: sega32x-python pins sh2-python `d4665d5`, which carries all of the above. ## Citation-only fixes made in this audit None. ## Wave 2 rewrite (2026-11-19) Mode: **in place**. The flagged pieces were localised (one module, one read rule, one value, some documents); the rest of the core was clean in wave 1. Removed unread: `src/sh2_python/divu.py` was moved to a git-ignored `trash/` whole (its register map, access path and state methods, which wave 1 marked clean, were read and kept; the division bodies, `partial_64` and the module docstring's description of them were not), and the three DIVU tests that encoded the flagged behaviour were moved out of `tests/test_modules.py` by line range without display. Two flagged lines were seen while locating the code (`grep` output of the comments, and the three-line non-overflow tail of `_divide_64`); nothing of them was reused beyond what HM states. Closed-box route tried: jgenesis `d41e2d9` through the jgenesis harness (a probe of 35 edge cases). It saturates on overflow but models no early state, and panics on H'80000000 ÷ −1, so it cannot measure the partial results. Mednafen would need a Saturn BIOS and a Saturn program from an SH toolchain (none here); srg320's RTL would need its port list read and a Verilog simulator (none installed). So the early state is HYPOTHESIS. Edge cases, old (wave 1 build, run as a closed box) → new: | Case | Old | New | New source | | --- | --- | --- | --- | | 32 ÷ 32, H'80000000 ÷ −1 | no overflow, quotient H'80000000, remainder 0, 39 states | overflow (OVF), DVDNTL = DVDNT = H'7FFFFFFF with OVFIE = 0, 6 states | DOC HM 10.3.3 (+2^31 is out of range) | | 64 ÷ 32, quotient exactly H'80000000, divisor > 0 (e.g. −2^31 ÷ 1) | overflow | no overflow, quotient H'80000000 | DOC HM 10.3.3 (in range) | | 64 ÷ 32, quotient exactly H'80000000, divisor < 0 | no overflow | no overflow (same) | DOC | | both negative, quotient H'7FFFFFFF, remainder ≠ 0 (−H'FFFFFFFF ÷ −2) | no overflow | overflow, DVDNTL = H'7FFFFFFF | DOC HM 10.3.3, read literally | | ÷ 0, OVFIE = 0: DVDNTL | H'7FFFFFFF / H'80000000 by dividend sign | same | HYPOTHESIS (sign); jgenesis OBSERVED agrees | | ÷ 0 and every overflow: DVDNTH (and DVDNTL with OVFIE = 1) | the earlier build's partial (e.g. 32 ÷ 0 of 5: DVDNTL H'2F with OVFIE) | PM example-4 state after 3 steps (5 ÷ 0: H'2B; 2^60 ÷ 2: DVDNTH H'7FFFFFF2 against the old H'7FFFFFE4) | HYPOTHESIS (`early_state`) | | normal results, timing (39/6 states) | — | unchanged | DOC | | purge-space read (H'40000000-) | purges the line, reads all ones | purges nothing, reads 0 | HYPOTHESIS (own choice; HM documents writes only) | | H'A0000000- read / write | as the purge space | reserved: reads 0, writes ignored | HM table 7.3; HYPOTHESIS | | WDT H'FFFFFE82 byte read | H'FF | 0 | HYPOTHESIS (own choice) | The probe is `validation/divu/probe.py`; its outputs for the wave-1 build, jgenesis and this tree are beside it. The new behaviour is pinned by `tests/test_modules.py`. Gates (CPython 3.14, `pytest`, then `pytest -m slow`): | Gate | Before (wave 1 tree, e34f593's content) | After (e5c5af3) | | --- | --- | --- | | fast tests (rung 0, 3, 4 units) | 592 passed | 606 passed (3 flagged DIVU tests out, 15 new in, 2 from PR #2's merge) | | rung 1 corpus (16,600 cases) | pass | pass | | rung 2 MAME replays (4 games, ~129 M instructions) | 4/4 exact | 4/4 exact | | rung 4 DN CPU-resident loops | pass | pass | ## History rewrite (2026-11-22, wave G) The family's history clean-up (wave G) removed `validation/jgenesis_harness/` (our Rust harness, built linked with jgenesis' GPL-3.0 `sh2-emu`) and `scripts/build_jgenesis_harness.py` (which assembles that build and patches a copy of `sh2-emu`'s source with a `registers_mut()` accessor) from every commit with `git filter-repo`, keeping the single commit of the 2026-11-21 reset. By the family's rule of 2026-11-19 both are GPL tools. They are kept with the family's other GPL tools (emu-tools-gpl, `tools/sh2-python`): with `EMU_TOOLS_GPL` naming a checkout of emu-tools-gpl, run `python "$EMU_TOOLS_GPL/tools/sh2-python/build_jgenesis_harness.py"` from this checkout (until 2026-11-24 the folder was named by `SH2_GPL_TOOLS`) and the binary lands where it did, `reference/build/jgenesis-sh2/target/release/sh2-jgenesis-harness`. Commit hashes cited from before that date refer to the old history, which is kept privately. ## Closed-box sources removed (2026-11-24) Aubrey's rule of 2026-11-24: an MIT repository does not download or keep the source of anything the family's `sources.md` marks closed box only, unless a program with no shipped build is built from it. Pins removed from `scripts/pinned_repos.json`, trees moved aside unopened, out of the repository (not deleted), none of them built: PicoDrive (`1008a98e`, non-commercial), Kronos (`d451a552`, GPL-2.0), Yabause (`7e38821d`, GPL-2.0), Ymir (`8cdf0a53`, GPL-3.0), Saturn_MiSTer (`9aa94498`, no licence) and S32X_MiSTer (`3d4209c6`, no licence). URLs are in docs/validation.md. **Kept, with a question for Aubrey:** jgenesis (GPL-3.0), because the harness above builds its `sh2-emu` crate (the build copy under `reference/build/jgenesis-sh2/` holds its source), and the Mednafen 1.32.1 tarball, from which `scripts/build_referees.py` builds the Saturn detector. Neither has a shipped build that would do. Aubrey's answer (decisions page T3, 2026-11-25): both move, one tool at a time. Mednafen moved on 2026-11-25 (below); jgenesis is still here. ### Mednafen's build moved to emu-tools-gpl2 (2026-11-25) Decisions page T3: the Saturn Mednafen is now built by emu-tools-gpl2's `tools/mednafen` (mednafen-build 0.1.0, GPL-2.0-only: `build.py --machine ss`, the same pinned tarball, SHA-256 `de7eb94a...`, the same configure options), at `$EMU_TOOLS_GPL2/tools/mednafen/build/ss/bin/mednafen`; `scripts/build_referees.py` runs that build as a program and checks for that file. The tarball's pin (with its `src/ss` extract) left `scripts/pinned_files.json`. Moved unopened to a backup outside the repository (not deleted): `reference/archives/mednafen-1.32.1.tar.xz`, `reference/src/mednafen-1.32.1` (the extract Phase 0 read, before the rule) and `reference/build/mednafen-1.32.1` (the build tree and its program, sha1 `6b03ca69`). No script here runs the program (no result in these documents came from it), so the identity check is of the program itself, 2026-11-25: run with no game (SDL's dummy drivers, a fresh `MEDNAFEN_HOME`), the old program and the tool's print the same banner and usage ("Emulation modules: ss demo cdplay"), exit with the same status (255), and write the same default `mednafen.cfg` (12,811 lines; paths aside); their ELF sections are the same sizes, and their disassemblies (1,878,074 lines each) are the same once constants and addresses are blanked: the 7,488 lines that differ load addresses in read-only data, which moved with the install paths compiled in (sh2-python's build ran from its tree; the tool's is installed). OBSERVED; not a run of Saturn code, which needs a Saturn BIOS and has not been done here.