Files
courier-emu/tools/x86_disasm.py
T
Cryan209andClaude Opus 5 4772fbe1a9 AT&T1 reaches the datapump through the test flag, not the call gate
Tools first: tools/x86_disasm.py wraps capstone over CourierRom.at so an
80186 routine can be read at the same physical addresses the traces
print, and tools/executed_addresses.py dumps the whole track_executed set
and diffs two runs as contiguous spans. hot_addresses is a top-20 profile
and cannot say whether a branch ran at all; the diff can, and it is what
found everything below. AT&T0 executed 2,885 addresses, AT&T1 3,745, and
&T1 against &T8 differs by 10.

The &T dispatch is a table of far-call thunks at 875d8, four bytes apart.
Slot 0 -> 875f8 and slot 1 -> 876b1 are confirmed executed by AT&T0 and
AT&T1, slot 7 -> 87738 by AT&T8. The middle slots are not named here
because nothing ran them.

[0x685] is the test-mode flag byte. Every access to it in the image - 51
sites - agrees on the bits:

  0x01  analogue loopback     876c5 (&T1), 87752 (&T8)
  0x02  a second loopback     876eb
  0x04  a third               8770e, 8825c
  0x08  self test             87752 as |9, 8772c as |0c
  0x40  already-online form   876bd, 8774b
  0x80  test armed            87764
  0x07  any loopback, a gate  833bb, 88236, a4fea, a6abd

So the modes differ by bit, and the test pattern is bit 3, not bit 0.
[0x686] is the self-test error counter: &T8 zeroes it, and &T0's handler
does `test [0x685],8 / jz / call 8776f`, which reads [0x686] and prints
it. &T1 sets bit 0 alone - no internal pattern and no counter.

The part that corrects earlier work here: the gate at 8b863 that
datapump-dispatch-gate.md documents returns carry *clear* under &T1.
8bbc2, the carry-clear target, is in the &T1-only set and 8bbaa's carry
branch is not taken. The datapump comes in through 8b84f instead:

  8bbc2  call 8b84f
  8bbc5  jne  8bbca          taken
  8b84f  test [0xa96],2      jnz ret
  8b856  test [0x5a5],1      jnz ret
  8b85d  test [0x685],1      the loopback bit leaves ZF clear

8b85d is in the &T1-only set. The test flag is what routes to 8bbca and
the 344-address block at 8bbe9..8bd40 that selects the datapump, loads
overlay 6 and publishes 0010:5001. &T0 confirms the shape by absence: it
runs slot 0 and 875fb and never reaches 87438, 8b85d or 8bbc2.

Two sites ran under &T1 that gate against the test rather than for it,
and are where to look next for why the DTE data path never opens:

  a4d4c  test [0x685],0x80 / and [0x685],0x7f / stc / ret
         the armed bit is consumed and cleared on first pass, one shot
  a6abd  test [0x685],7 / jnz -> stc; ret
         refuses the jump through cs:[bx+0x1dbe] while any loopback is up

No behaviour changes in this commit; both tools are smoke-tested against
the runs above and reproduce them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 12:07:18 +12:00

55 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Disassemble 16-bit 80186 code out of a Courier ROM by physical address.
The repository has a C5x disassembler but nothing for the supervisor side, so
reading an 80186 routine meant decoding bytes by hand. This wraps capstone.
Addresses are physical, the same ones `--trace-pc`, `hot_addresses` and
`executed_addresses.py` print, so a site found in a trace can be pasted
straight in:
PYTHONPATH=. python3 tools/x86_disasm.py IDSDL302.ROM 876b1 --count 20
Needs the `disasm` extra, which pyproject already declares for capstone.
Linear disassembly from an arbitrary offset is a guess: starting mid
instruction produces plausible-looking nonsense for a few lines before it
resynchronises. Start from an address something actually branched to.
"""
from __future__ import annotations
import argparse
import capstone
from courier_emu.rom import CourierRom
def disassemble(rom: CourierRom, start: int, count: int):
"""Yield `count` instructions from the physical address `start`."""
engine = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_16)
# The longest 8086 encoding is six bytes, so this cannot run short.
data = rom.at(start, min(count * 6, len(rom.data) - (start - rom.base)))
for index, instruction in enumerate(engine.disasm(data, start)):
if index >= count:
return
yield instruction
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("image")
parser.add_argument("address", help="physical start address, hex")
parser.add_argument("--count", type=int, default=24,
help="instructions to print (default 24)")
args = parser.parse_args()
rom = CourierRom.load(args.image)
for instruction in disassemble(rom, int(args.address, 16), args.count):
print("%05x %-18s %s %s" % (
instruction.address, instruction.bytes.hex(),
instruction.mnemonic, instruction.op_str))
if __name__ == "__main__":
main()