Skip to content

Improvement: DSP register-contract report for Octatrack DSP package entries, from the assembled words - #1608

Merged
repeat98 merged 2 commits into
mainfrom
improvement/dsp-register-contract
Nov 16, 2026
Merged

repeat98 merged 2 commits into
mainfrom
improvement/dsp-register-contract

Conversation

@repeat98

Copy link
Copy Markdown
Owner
  • What was wrong or hard: dsp-sites.json declares a clobbers list per DSP hook site, and docs/OCTATRACK_PACKAGE_DSP_HOOKS.md said build.py --dsp-hook refuses "a register outside the site's contract (checked on the disassembly)". Neither held: no code read clobbers, and build.py has no --dsp-hook. The only register rule checked anywhere was r1 in an effect's init, by a regex over source (the trap-init-r1 class: an init that moved r1 hung every core at project load). A reviewer of a hook package (an engine for site 5, or the chain site in Octatrack base: DSP hook chains, so several packaged DSP machines share a hook site #1418) had to read its registers by hand.
  • What this changes:
    • scripts/dsp-register-contract.py reads every shipped Octatrack DSP package from its words: the .mwrm files octatrack-module-packages.json lists (effect init/proc, ABI 10 engine hook entries) and the base's own hooked engines in dsp-packages.json. Each entry is placed with its relocations and walked from its offset over what it can reach: falls, both sides of a branch, local jsr/bsr callees, with each rts going back to its own caller. Only reached instructions are decoded, so a P table or data beside the code is never read as code. Decoding uses the DSP56300 disassembler built beside ELEKLOADER_DSP_ASM (dsp56kDisassemble -nops).
    • The write set is judged on two path kinds. Paths that return to the caller must stay inside the contract. Paths that leave (the site's exit, or a jump out of the package) are reported apart. The contract has three parts: a hook entry writes only its site's clobbers, and a site with an exit also lets it drop the return it was called with. An effect init keeps r1, n1 and m1. No entry writes omr, mr, sr, sp, ssh, ssl, vba, ep, sz or sc.
    • It fails closed. A word it cannot decode is reported as "undecodable at P:$xxxx". An instruction it does not model, an indirect jsr (rN), a call outside the package or running past the end each makes the entry "incomplete", and that counts as a finding.
    • It reports now and refuses later, the way dsp-source-gates.py does with REP_REFUSED_FROM. REFUSED_FROM = None means report only. You set the date. From that date, a module first listed on or after it gets a red doctor line and exit 1.
    • module:doctor has a dsp registers line (✓, or · with the first finding). Without the disassembler it says "not checked", so CI, which has no toolchain, is unaffected. pr-ready.mjs lists the script and its test as gate files, next to dsp-source-gates.
    • The doc paragraph now says what exists: hook_engines.py and abi9.engine() build and package an engine, dsp_sites.py --check checks addresses and guards, dsp-source-gates.py checks rep, and this script checks registers. Stack depth is not checked. The doc gets 31 bytes shorter.
  • What it reports on every current DSP package today (13 packages, 29 entries, 5 with findings, 0 refused):
    • Clean: E-Verb, Mini Verb, TapeHead, LOFI2, SC Ringmod, Tape Echo, Euclid, BBD Delay, and Air Chorus init. No effect init writes r1, n1 or m1, which agrees with the source regex.
    • Air Chorus 0.1.2 proc: incomplete, jsr (r2) at +$2a1 (an indirect call through its table). It writes nothing outside the contract up to that point.
    • Analog BD 0.1.7 engine, site 5: the return path stays inside [b, r4, x0]. The path out through the exit writes a, m0, m1, m4-m6, n1, n5, n7, r0, r1, r5, r6, x1, y0, y1. The site records no exit-path contract, and the stock source it skips may free those registers. n5 is a known false positive: the voice saves and restores it, which the check does not recognise yet.
    • Sidechain Compressor (base engine, cores A and B):
      • Site 0 writes r6, outside [a, b, r0, r1, n1, x0]. It reloads r6 from X:$208 before returning.
      • Sites 1, 2 and 6 have clobbers: [] but write a lot: site 1 a, b, n1, n6, r0, r1, r4, r5, x0, x1, y0, y1; site 2 a, b, n1, r0, r1, r3, x0, x1, y1; site 6 only x0, by replaying stock's displaced move #>$20c5,x0.
    • Output Matrix (base engine, core A):
      • Site 3 writes b and r6 on its return path, and leaves to stock P:$0292 and P:$02d5.
      • Site 4 writes b and r0 on its return path, and leaves to stock P:$035a.
      • Both pop the site's return (move ssh,x0) at sites that have no exit.
    • My reading: most of the base-engine findings mean the clobbers: [] lists were never filled in, plus the "reloaded from a stock word" and "replays the displaced instruction" patterns the checker does not model. They are not faults seen on a unit. Before setting the date: fill in the base sites' clobbers (a base pull request), or teach the checker save/restore.
  • What remains (not in this PR): recognising save/restore, the stack-depth allowance, a declared exit-path contract per site, and a never-write list from the stock interrupt and host-command code (not yet known). Octatrack base: DSP hook chains, so several packaged DSP machines share a hook site #1418 makes site 5 a chain. The script reads clobbers per site whether the site has feature or features, so it also covers a second chain member, but I did not run it against that branch.
  • How I checked it:
    • python3 -B -m unittest on sdk/tests/test_dsp_register_contract.py: 10 tests pass with the toolchain. Without it, 5 skip with the toolchain reason.
      • The decoding rules and the reader for the committed packages run everywhere. The reader is cross-checked against dsp-packages.json: the same words, relocations and entries for every effect whose versions match. Every engine's exit word follows a long BRA.
      • Synthetic routines are assembled with dsp_asm: an init that moves r1 is reported; a write of n1 two bsr levels down counts; proc may move r1; data words after rts are never decoded; a branch into one gives "undecodable at P:$4004"; jsr $292 is incomplete; jmp $292 leaves; and a hook is judged per path against a test site.
    • The full report (above) runs in under a second.
    • npm run module:doctor -- analog-bassdrum and -- everb both end "Every integration point is green". The new line shows · for Analog BD and ✓ for E-Verb.
    • eslint on the changed .mjs files passes, and so does vitest run scripts/pr-ready.test.mjs (12 tests).
    • Not run: npm run pr:ready and the full sdk:check, because the machine I share with other jobs cannot take the load. CI runs them.
  • What the guides lacked or got wrong, and where I fixed it: docs/OCTATRACK_PACKAGE_DSP_HOOKS.md described a build.py --dsp-hook register refusal that does not exist. That paragraph, and the stale tools line under "What it costs", now say what exists. Changelog: changelog/2026-11-16-dsp-register-contract.md.

🤖 Generated with Claude Code

repeat98 and others added 2 commits November 16, 2026 12:06
…tes against its contract, read from the assembled words

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the enhancement New feature or request label Nov 16, 2026
@repeat98
repeat98 merged commit 31a4a1a into main Nov 16, 2026
13 checks passed
@repeat98
repeat98 deleted the improvement/dsp-register-contract branch November 25, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant