#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Rung 0's reference side: every table the core decodes with, one line per entry. tables_reference.py SH2_PYTHON OUT For each of the 65,536 encodings: its handler, its pipeline plan, the load-use registers (``_load_use``), the slot-illegal and interrupt-blocking flags (cpu.py ``_build_tables``), and its disassembly at two addresses (a 4n and a 4n + 2, for the PC-relative forms); then every pipeline class's row (PM table 7.2) and plan, and the on-chip register map (which module answers each address of H'FFFFFE00-H'FFFFFFFF). ``sh2-trace --tables OUT`` writes the same file from this crate. """ from __future__ import annotations import sys from pathlib import Path def main() -> int: root, out = Path(sys.argv[1]), Path(sys.argv[2]) sys.path.insert(0, str(root / "src")) from sh2_python import cpu from sh2_python.disasm import disassemble_word from sh2_python.pipeline import CLASSES, EXCEPTIONS, PLANS with out.open("w") as stream: for op in range(0x10000): a = disassemble_word(op, 0x06001000) b = disassemble_word(op, 0x06001002) target = lambda i: -1 if i.target is None else i.target # noqa: E731 stream.write( f"{op:04x} {cpu._NAMES[op]} {cpu._PLANS[op].name} {cpu._LOAD_DEST[op]} {cpu._USES[op]} " f"{cpu._SLOT_ILLEGAL[op]} {cpu._BLOCKS[op]} [{a.text}] {target(a)} [{b.text}] {target(b)}\n" ) for c in (*CLASSES.values(), *EXCEPTIONS.values()): p = PLANS[c.name] mas = ",".join(map(str, p.mas)) stream.write( f"class {c.name} [{c.category}] [{' '.join(c.stages)}] {c.states} {c.next_id_stall} {c.mm} " f"[{c.figure}] plan [{mas}] {p.stall} {p.mul} {p.mm} {p.kind} {p.tail}\n" ) chip = cpu.SH7604(lambda a, w, k: 0, lambda a, w, v, k: None) for i, module in enumerate(chip._onchip): stream.write(f"onchip {0xFFFFFE00 + i:08x} {module.NAME if module is not None else '-'}\n") return 0 if __name__ == "__main__": sys.exit(main())