# A new core, or an architecture-version axis on arm7tdmi-python? The question this Phase 0 was asked first. arm7tdmi-python (`../arm7tdmi-python`, ARMv4T, built, rungs 0-4 pass, 2.19 M SingleStepTests cases gated) already specifies the DS's second CPU. Could the ARM946E-S be the same core with an `arch="v5TE"` switch that adds CLZ, the saturating ops, BLX, LDRD/STRD and the DSP multiplies? **Recommendation: a new core repository, `arm946es-python`, sharing shape and tooling with arm7tdmi-python but no code.** The reasons, with their evidence, and what was weighed. ## What an "axis" would have to change The instruction set is the small part. Listing everything the ARM946E-S does differently from the ARM7TDMI, by where it lives in arm7tdmi-python: | Area | ARM7TDMI (arm7tdmi-python) | ARM946E-S | Source | | --- | --- | --- | --- | | New instructions | absent (undefined, or what the ARM7 does with the encoding) | CLZ; QADD, QSUB, QDADD, QDSUB and CPSR.Q; SMULxy, SMLAxy, SMULWy, SMLAWy, SMLALxy; LDRD, STRD; PLD; MCRR, MRRC; BLX (immediate and register), BKPT; CDP2, LDC2, MCR2, MRC2, STC2 in the cond=1111 space; Thumb BLX and BKPT | ARM ARM DDI 0100E; GBATEK "ARM CPU Versions" (DOC) | | Changed rules for existing instructions | LDR/LDM/POP to R15 keep T; MUL leaves C "meaningless"; LDM with the base in the list never writes back; STM stores the old base only when it is first; an empty list loads R15 | LDR/LDM/POP to R15 set T from bit 0 (unless CP15 control bit 15, "pre-ARMv5 mode"); MUL leaves C unchanged; LDM writes back when the base is the only register or not the last; STM always stores the old base; an empty list transfers nothing, base +/- 40h | GBATEK "ARM Opcodes: Memory: Block Data Transfer", "ARM CPU Versions"; ARM ARM (DOC); rockwrestler tests the R15 cases (TEST ROM, verdicts on hardware per its README's credit to StrikerX3) | | Data abort model | base updated | **base restored** | DDI 0165B 2.9.7, DDI 0201D 2.2.1 (DOC) | | Pipeline | 3 stages; R15 = address + 2L; one bus, cycle types N/S/I/C | 5 stages (Fetch, Decode, Execute, Memory, Writeback); R15 still reads address + 8 / + 4, but timing comes from **interlocks** (load-use, multiply result, Q-op result) | DDI 0165B 1.1.1, chapter 8 (DOC) | | Bus model | **one** bus; one callback per cycle in chip order, N/S/I/C | **two** buses (Harvard): every cycle has an instruction-side and a data-side activity, both shown in DDI 0165B's tables (e.g. LDR, 1 cycle: I-bus 1S, D-bus 1N) | DDI 0165B table 8-2 (DOC) | | Instruction timings | TRM tables (LDR 1S+1N+1I, STR 2N, MUL 1S+mI with early termination) | different counts (LDR 1 cycle plus 1-2 interlock cycles; STR 1; MUL 2-3, MULS 4; no early termination: "the ARM9 has lost the fast-multiply feature for small numbers") | DDI 0165B table 8-2; GBATEK "DS Memory Timings" (DOC, and GBATEK's own measurements on a DS) | | Memory system in front of the bus | none (the GBA's bus is the core's) | CP15, protection unit, 8 KB I-cache, 4 KB D-cache, ITCM, DTCM, 16-entry write buffer, the BIU that turns core cycles into AHB transfers at half the clock | DDI 0201D chapters 2-6 (DOC) | | Coprocessor 15 | absent (MRC p15 is undefined) | present; also the wait-for-interrupt halt (C7,C0,4 / C7,C8,2) | DDI 0201D 2.3; GBATEK "ARM CP15 Cache Control" | So an axis would put a version test into most handlers (every load, store, multiply, branch and block transfer changes either semantics or timing), and it would replace the heart of arm7tdmi-python, its bus schedule. That schedule is what arm7tdmi-python *is*: "one bus callback per CPU cycle, internal cycles included" (its README), checked cycle by cycle against its corpus and against hardware-calibrated GBA timing ROMs. The ARM9E-S has no such single stream; its per-cycle picture is two buses and an interlock model, and on the DS what the board sees is not even the core's bus but the BIU's AHB transfers behind the caches and TCMs. ## The options weighed **A. An `arch` axis in arm7tdmi-python.** One repository for both ARM CPUs of the DS. Against: the reference for one chip grows branches for another on nearly every line; the ARM7's certified gates have to be re-run for every ARMv5 change; the readability contract (one mnemonic per handler, the hardware reason on the line) breaks where one handler serves two chips with different timings; and the charter's rule that a CPU gets its own core (chip rule) is about chips, not instruction sets: the ARM946E-S is a different chip with a different pipeline, made by the same company. **Not recommended.** **B. A new core, written from ARMv5TE's documents, in arm7tdmi-python's shape.** Same tooling bar (state, disassembler, debugger, console, trace), same docs layout, same evidence tags; decode tables generated from the ARM ARM's encoding tables, handlers written from its pseudo-code, timing from DDI 0165B chapter 8, the memory system from DDI 0201D. The ARMv4T subset is written again (about 1,500 lines of arm7tdmi-python's 4,500 are instruction semantics; the rest is the bus schedule, tools and tables, which differ anyway). **Recommended.** The duplication is real but small, and it buys a core whose every line describes one chip. **C. A new core that imports pure helpers from a pinned arm7tdmi-python** (the barrel shifter, condition codes, PSR bank switching). Less code, but it couples two chips' specifications through private modules (`_alu`, `_modes`, `_psr` are underscore names), so an ARM7 fix would silently change the ARM9 and an ARM9 need would bend the ARM7. The charter's "never copy code between repos; depend on the pinned sibling" is about sharing a *chip*; here the shared part is the architecture, and the architectures differ in the corners (MUL's C flag, abort model, interworking). **Not recommended**, but listed in Open decisions because it is the cheapest. ## What B keeps from arm7tdmi-python - Its **shape**: mixins by instruction family, one handler per decode row, generated decode tables with a `--check` mode, `state.py` / `disasm.py` / `debug.py` / `console.py` / `trace.py`, the readability test. - Its **corners as hypotheses to re-check, never as facts**: where arm7tdmi-python records an ARM7TDMI behaviour (unaligned LDR rotation, LDRSH on odd addresses, the LDM^ glitch, MSR to T), the ARM9 answer is looked up afresh (ARM ARM, GBATEK, test ROMs); several are known to differ (an odd-address LDRH or LDRSH: GBATEK "ARM CPU Memory Alignments" says the ARM9 forces the address even, where the ARM7 rotates LDRH and turns LDRSH into a sign-extended byte load; isa-v5te.md). - A **differential detector**: the two cores run the same ARMv4T instruction streams (no timing compared) and every disagreement must be on the list of known ARMv4/v5 differences. Tier 5 (two of our own specifications), but it catches transcription slips in the shared subset cheaply. ## What the DS board gains nds-python composes two cores with two different bus contracts: `arm7tdmi_python.ARM7TDMI` (per-cycle callbacks, the GBA's contract) for the ARM7, and `arm946es_python.ARM946ES` (transactions from the BIU, behind the core-owned caches and TCMs) for the ARM9. The DS's GBA mode is arm7tdmi-python unchanged, at 16.78 MHz, which is gba-python's board.