Files
courier-emu/tests/test_machine_map.py
T
Cryan209andClaude Opus 5 dd8f9dd885 Describe the board declaratively, and give each one its own clock
Two strands, joined because machine.py carries both.

`machine_map` is the canonical description of the hardware: address ranges,
service vectors and the DSP reset port, which used to sit as module constants
beside whichever code happened to use them. An exact-digest `FirmwareProfile`
supplies only what moves between ROM revisions, so profile selection is
evidence rather than a revision-string guess.

`timebase` does the same for the clock. Three constants carried it between
them - pit's 5 cycles an instruction, timers' 5.93, and timers'
INSTRUCTIONS_PER_SECOND at 4,348,000 - and each described a different part
while being imported by whatever needed a rate. The 5 is the 386EX I-modem's;
the 5.93 is the 80C186EB's; the 4,348,000 is the 186's rate on main211's
25.8048 MHz crystal, and it was serving the 20.16 MHz 302/403 as well.

Cycles per instruction is a property of the part and the code mix, so both
186 boards share it. The crystal is a property of the board. Keeping them
apart is what lets one model serve all three:

  courier-20.16     20.1600 MHz  5.93  3,399,663 insn/s  dsp/x86 5.93
  courier-25.8048   25.8048 MHz  5.93  4,351,568 insn/s  dsp/x86 4.6328
  imodem-386ex      25.0000 MHz  5.00  5,000,000 insn/s

That separation fixes two things. The DSP ratio is not shared by the two 186
boards: docs/asic-pinout.md traces the C5x's CLKIN to the ASIC, which runs
from the shared 40.320 MHz can either way, so the 2806's faster crystal is
the CPU's alone and the DSP does not speed up with it. And timers.py's note
that the crystal cancels is right about the timers - the ratio is CPI/4 on
both boards - but did not cover what takes INSTRUCTIONS_PER_SECOND as an
absolute rate. FRAME_HZ was measured on the live 403 at 20.16 MHz and then
divided into main211's figure, 28% fast on the board it was measured on.

The board is taken from the timer constant the firmware writes: 25,200 counts
is 5.000 ms only at 20.16 MHz and 32,256 only at 25.8048, and the 7.4.16
board checks its own value back at 0x4a83b. Anything unrecognised leaves the
assumed 302/403 in place rather than guessing from it. All three flash
captures identify themselves in agreement with their own ATI7.

The 2806's 60M-instruction boot is byte-identical and still prints its
profile. Elsewhere only timer counts and event instants shift, by the 0.08%
between the rounded 4,348,000 and an exact 5.93/4. Note that every XMF here
programs 0x7e00 - they are all 25.8048 builds - so the 20.16 correction bites
only on the flash captures, and both stall on unimplemented x87 opcodes
before reaching it. It is argued from the documentation and from the boards'
own ATI7, not yet demonstrated by a run that gets that far.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 22:55:35 +12:00

33 lines
1.2 KiB
Python

from pathlib import Path
from courier_emu.machine_map import FIRMWARE_PROFILES, courier_machine_map
from courier_emu.rom import CourierRom
ROOT = Path(__file__).resolve().parents[1]
def test_canonical_regions_prefer_mapped_device_over_ram():
image = CourierRom.load(ROOT / "IDSDL302.ROM")
memory = courier_machine_map(image)
assert memory.address_space_size == 0x100000
assert memory.region_at(0x02CA).name == "dsp-host-queue"
assert memory.region_at(0xFF56).name == "80186-peripheral-control"
assert memory.region_at(0x80000).device == "flash"
def test_australian_roms_select_exact_firmware_profiles():
cases = (
("courier-board-11430-flash-20260914-02", "061-7.4.16", "3.0.13"),
("courier-board-11430-flash-20260914-unit2-02", "061-7.6.7", "3.1.2"),
)
for directory, supervisor, dsp in cases:
image = CourierRom.load(ROOT / "artifacts" / directory / "courier-board.rom")
profile = courier_machine_map(image).firmware
assert profile is FIRMWARE_PROFILES[image.digest]
assert profile.supervisor == supervisor
assert profile.dsp == dsp
assert profile.product == "Australia External"
assert profile.boot_entry == image.reset.boot_physical