XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsDONE docs/debugger-profiler-plan.md

Symbolic Ivory Disassembler, Live Debugger & Profiler Plan

Status: Implemented (DONE) — All 5 phases implemented in the host shell (SHELL_SRCS) with zero libivory_core ABI changes and verified on Linux (16/16 unit + 6/6 E2E) and Windows/Wine (16/16 unit). See docs/ROADMAP.md and docs/TROUBLESHOOTING.md.

Target Emulator: C11 XL1200 Emulator (emu/) — Host Shell Only (zero libivory_core ABI changes)
Reference Sources (local-only developer assets): genera-original/sys.sct/i-compiler/disassemble.lisp, genera-original/sys.sct/i-sys/{sysdef.lisp,opdef.lisp}, docs/hardware-reference/01-cpu-data-types-and-registers.md, docs/hardware-reference/02-isa-and-execution-semantics.md, docs/instruction-set-lexicon.md


1. Executive Summary & Goals

As ivory-xl1200 opens up to external beta testers on Linux and Windows, raw hexadecimal dumps (PC=0xF8004120, opaque 40-bit stack words, and unnamed trap vectors) slow down root-cause analysis. Today:

  • emu/src/bug_report.c captures raw words around PC, raw stack words, and 16 raw frame links, without decoded Ivory mnemonics or Lisp function names.
  • emu/src/ui_workbench.c (Debug & Snapshots) shows PC/SP/FP/LP/LED/instr_count and numeric breakpoints/watchpoints, but has no disassembly, full register/FPA inspector, or symbolic stack viewer.
  • emu/src/debug_ctl.c has regs, bt, mem, pma, hw, and a ~50-line raw-PC sample [N] command, but no symbolic disassembler or symbol-aware backtrace.
  • .agents/skills/xl1200-live-debug/SKILL.md is tailored to local POSIX /tmp/ivory-xl1200-*.sock workflows rather than external beta testers, Windows Named Pipes/TCP, or other AI coding agents.

This plan delivers five tightly scoped capabilities with zero changes to libivory_core ABI and 0% steady-state execution overhead:

  1. 40-Bit Ivory Instruction Disassembler (emu/src/ivory_disasm.c).
  2. Side-Effect-Free Genera Symbol, Function & Stack Walker (emu/src/ivory_sym_walk.c) feeding debug_ctl, bug_report.c .zip archives, and s7 REPL.
  3. Interactive Disassembly / Register / Stack / Memory Tabs in Debug & Snapshots (ui_workbench.c).
  4. Low-Cost On-Demand Symbolic Sampler (sample-sym, ~120–150 LOC) extending existing debug_ctl.c sample [N] to export standard .folded stacks for flamegraph.pl / speedscope.app (explicitly excluding costly background sampling or in-GUI flamegraph rendering).
  5. Vendor-Neutral Beta-Tester Troubleshooting Guide & Portable Cross-Agent Skill (docs/TROUBLESHOOTING.md + portable SKILL.md) supporting both Unix (AF_UNIX) and Windows (Win32 Named Pipes / TCP) builds across Antigravity, Claude Code, Codex, Cursor, and human testers.
flowchart TD
    PEEK["Read-Only Memory Access<br/>api->ivory_mem_peek_vma / peek_pma<br/>(Zero Side Effects, Zero Traps, Zero ABI Bloat)"]
    DIS["ivory_disasm.c<br/>All 256 Opcodes, Formats 1-4,<br/>Fullwords, CDR-JUMP, ENTRY Headers"]
    SYM["ivory_sym_walk.c<br/>DTP-SYMBOL Names/Packages,<br/>DTP-COMPILED-FUNCTION Debug Info,<br/>Control-Stack Frames &amp; Trap Table"]

    PEEK --> DIS
    PEEK --> SYM

    DIS --> DBG["debug_ctl.c<br/>disasm, bt-sym, inspect, sample-sym"]
    SYM --> DBG
    DIS --> BR["bug_report.c<br/>Symbolic Disasm + Backtrace in report.txt"]
    SYM --> BR
    DIS --> UI["ui_workbench.c<br/>Debug Window: Disasm / Regs / Stack / Mem"]
    SYM --> UI
    DBG --> S7["emu_script.c<br/>(emu/disasm), (emu/bt-sym)"]

2. Core & Host-Shell Invariants

  • 100% Host-Shell (SHELL_SRCS): ivory_disasm.c and ivory_sym_walk.c compile solely into ivory-xl1200 (and unit tests), adding 0 bytes to libivory_core.so/.dll and requiring no IVORY_CORE_ABI_VERSION bump.
  • Strictly Side-Effect-Free Inspection: Every guest read goes exclusively through api->ivory_mem_peek_vma() / api->ivory_mem_peek_pma() — never triggering PHT fault traps, GC transport barriers, modified bit updates, or watchpoints.
  • Cycle-Safe & Bounded Memory Walks: All pointer chases (DTP-ONE-Q-FORWARD, DTP-EXTERNAL-VALUE-CELL-POINTER, package/symbol chains, frame links) enforce strict hop caps (MAX_IND_HOPS = 8, MAX_STR_LEN = 128, MAX_BT_FRAMES = 64) so corrupted or mid-GC guest memory can never hang or crash the debugger or Bug Dump.
  • Reference Provenance: Opcode tables, addressing-mode syntax, and Genera object layouts derive exclusively from emu/include/ivory_hw.h, docs/hardware-reference/, and genera-original/sys.sct/.

3. Phase-by-Phase Technical Design

Phase 1: From-Scratch 40-Bit Ivory Disassembler (emu/include/ivory_disasm.h, emu/src/ivory_disasm.c)

Provides a pure, stateless C11 disassembler decoding any (vma, is_odd, IvoryWord) (plus optional next word for 2-word ENTRY / fullword targets):

typedef struct IvoryDisasmLine {
    uint32_t vma;
    bool     is_odd;
    uint8_t  cdr;
    uint8_t  dtp;
    bool     is_fullword;
    bool     has_branch_target;
    uint32_t branch_target_vma;
    bool     branch_target_odd;
    char     mnemonic[32];
    char     operand[96];
    char     annotation[128]; /* Optional symbol / constant / CDR-JUMP note */
} IvoryDisasmLine;

size_t ivory_disasm_word(uint32_t vma, IvoryWord word,
                         IvoryDisasmLine out_lines[2]);

Decoding coverage:

  • Packed Halfwords (DTP 0o60..0o77):
    • Even (<17:0>) and Odd ({tag<3:0>, data<31:18>}) decoded across all 256 opcodes in emu/include/ivory_hw.h.
    • Exact Format 1 (FP+k, LP+k, SP-pop, SP-k, Immediate), Format 2 (signed 10-bit branch offset resolved to target_vma:E|O), Format 3 (8-bit unsigned immediate / LDB/DPB byte-specifier (byte ss pp)), and Format 4 (ENTRY-REST-ACCEPTED / ENTRY-REST-NOT-ACCEPTED min/max/rest decoding).
    • Annotates CDR-JUMP (cdr == 3, skips Odd slot) and CDR-NIL (cdr == 1, function trailer / fence).
  • Fullword Call Starters (DTP 0o50..0o57): CALL-COMPILED-EVEN/ODD, CALL-INDIRECT, CALL-GENERIC (+ prefetch variants), printing target VMA and (when symbol walker is enabled) resolved callee name.
  • Inline Constants (DTP < 0o50): PUSH-CONSTANT with formatted FIXNUM, CHARACTER, SINGLE-FLOAT, NIL/T, SYMBOL, LIST, or LOCATIVE.

Shared Lisp S-Expression Output Contract (--lisp Mode)

To guarantee direct compatibility with the standalone Common Lisp assembler/disassembler specified in docs/assembler-disassembler-plan.md (tools/ivasm/):

  • ivory_disasm.c uses the same canonical lowercase hyphenated mnemonic table and Lisp operand syntax ((fp k), (lp k), (sp-pop), (sp k), (imm v), (byte ss pp), (target :vma #x... :slot :even|:odd)), derived from emu/include/ivory_hw.h.
  • Alongside the compact single-line view for ui_workbench.c and report.txt, ivory_disasm.c exposes an assembler-ready S-expression formatter (debug_ctl disasm --lisp [vma] [count] and (emu/disasm vma count :lisp)) that wraps decoded words in a valid (module :arch :ivory-rev4 ... (section :vma ...)) form with explicit (:word :cdr ...) / (word ...) escapes and ; comment annotations, so debugger disassemblies feed directly into ivasm asm without manual reformatting.

Phase 2: Read-Only Genera Symbol, Object & Stack Walker (emu/include/ivory_sym_walk.h, emu/src/ivory_sym_walk.c)

Decodes authentic Genera 8.3 heap objects strictly via ivory_mem_peek_vma():

  • String Reader (ivory_sym_read_string): Reads DTP-STRING (ART-STRING / ART-FAT-STRING / DTP-ARRAY with DTP-HEADER-I length & 4-char/word 8-bit ASCII packing, forwarding through DTP-ARRAY-FORWARD / DTP-HEADER-FORWARD up to MAX_IND_HOPS).
  • Symbol Formatter (ivory_sym_format_symbol): Reads DTP-SYMBOL print-name (sym + 0, DTP-HEADER-P symbol header) and package cell (sym + 4 → package instance/string; +3 is property list) into "PKG:NAME" or "NAME".
  • Stack-Cache-Aware Peek (ivory_sym_peek_vma): Checks the active 128-word cpu->stack_cache ring (vma & 0x7F) before delegating to api->ivory_mem_peek_vma() so live control-stack frames always unwind accurately without mutating CPU/PHT state.
  • Compiled-Function Name Resolver (ivory_sym_resolve_pc):
    • Scans backward from pc_vma (up to 4096 words, stopping at page faults or prior function headers) to locate the enclosing DTP-HEADER-I / DTP-EVEN-PC / ENTRY compiled-function header (DTP-COMPILED-FUNCTION).
    • Extracts the function's debug-info pointer (info-word / (:method ...) / (:internal ...) / symbol name) and returns (fn_name, fn_entry_vma, word_offset).
  • Trap Vector Resolver (ivory_sym_resolve_trap): Reads the active Rev 4 *TRAP-DISPATCH-TABLE* entry or maps IVORY_REV4_USTATE_* microstate IDs to human-readable names (MEMORY-DATA-ERROR, TRAP-ON-EXIT, STACK-OVERFLOW, etc.).
  • Symbolic Control-Stack Backtrace (ivory_sym_backtrace): Walks FP frame links using the verified Ivory 2-word frame header (continuation, control CR) and resolves each frame's PC via ivory_sym_resolve_pc() + argument count (cr.argument_size).

Immediate Integration Points

  1. emu/src/bug_report.c (report.txt):
    • Replaces raw-only instruction & backtrace hex blocks with symbolic disassembly (PC - 8 .. PC + 8) and 16-frame symbolic backtrace (#0 0x... SI::FUNC+0x14 args=3), drastically accelerating beta-tester bug triage from a single .zip attachment.
  2. emu/src/debug_ctl.c (Live IPC & Puppet):
    • disasm [hex_vma] [count] (default: around current PC, 16 words)
    • bt-sym [max_frames] (symbolic backtrace with frame FP, arg count, callee name + offset)
    • inspect <hex_vma> (prints word CDR/DTP/pointer plus decoded symbol, string, array length, or compiled-function name)
    • trap-info (decodes current trap mode, vma, microstate, and trap handler name)
  3. emu/src/emu_script.c (s7 REPL):
    • (emu/disasm vma count) and (emu/bt-sym max-frames) return formatted strings / lists for interactive scripting.

Phase 3: Interactive Debug & Snapshots Workbench Tabs (emu/src/ui_workbench.c)

Upgrade the existing Debug & Snapshots floating window with compact, readable tabs (staying fully inside our antialiased 15/18 px Inter layout and ui_prepare_window_open() invariants):

  1. Overview & Controls (existing controls: Save Bug Dump (.zip)..., .snap, Video Recording..., Screenshot..., Reload Core, COW checkpoints, Breakpoints/Watchpoints).
  2. Registers & State: Complete live readout of Ivory CPU registers (PC, SP, FP, LP, CR bitfields: trap_mode, call_started, extra_arg, arg_size, caller_frame_size, BAR0..3, VMA, microsecond_clock, preempt_register, zone_oldspace/ephemeral_oldspace), Weitek W3x64 FPA status/registers, and Merlin-II IRQ/LED/SCSI/Ethernet summary.
  3. Disassembly & Stack:
    • Scrollable disassembly window centered on PC (with Follow PC checkbox, address jump box, Step 1 / Step 10 / Continue buttons, and inline [BP] toggle buttons).
    • Scrollable symbolic backtrace list (#0..#15) where clicking a frame jumps the disassembly view to that frame's return PC.
  4. Memory: Address input (VMA or PMA toggle), 16-word scrollable table showing [addr | raw 40-bit | CDR | DTP | pointer | decoded symbol/ASCII].

Phase 4: Low-Cost On-Demand Symbolic Sampler (sample-sym)

Complexity & Cost Analysis

  • What is ALREADY built: debug_ctl.c already includes a ~50-line synchronous sample [N] command that steps N chunks and prints a top-16 histogram of raw hex PCs.
  • What Phase 4 adds (~120–150 LOC total, 0% overhead when idle):
    • sample-sym [samples] [step_stride] [out.folded]: Reuses the existing on-demand sampling loop (runs only while the user explicitly executes the command), resolves each sampled PC (plus optional 8-frame shallow FP walk) through a tiny per-run (entry_vma -> name) cache over ivory_sym_walk.c, and prints a sorted top-20 hot-functions summary on stdout/IPC.
    • When [out.folded] is provided, writes standard Brendan Gregg folded-stack lines (ROOT;CALLER;CALLEE 42) consumable directly by external flamegraph.pl or browser-based speedscope.app.
  • Explicitly OUT OF SCOPE (high complexity / low ROI):
    • Continuous always-on background sampling inside emu_thread (adds lock/atomic contention).
    • Per-instruction instrumentation in cpu.c / cpu_zen4_loop.S (risks hot-loop regression).
    • In-GUI interactive flamegraph canvas inside microui (external tools like speedscope.app are vastly better at zero maintenance cost).

Phase 5: Beta-Tester Troubleshooting Guide & Portable Cross-Agent Skill

Because beta testers and contributors will run on both Unix (Linux/BSD) and Windows and may use any AI coding assistant (Antigravity, Claude Code, Codex, Cursor, etc.) or diagnose issues manually:

  1. docs/TROUBLESHOOTING.md (human- and agent-readable reference):
    • One-click bug reporting: How to trigger Bug Dump in the GUI (or bug-report via IPC) and what privacy guarantees apply (no ROMs or disk images included; paths sanitized).
    • Connecting to live IPC on both Unix & Windows:
      • Unix: ./scripts/xl1200-ctl.sh --list / AF_UNIX /tmp/ivory-xl1200-<pid>.sock / --debug-tcp 127.0.0.1:12345.
      • Windows: Win32 Named Pipe \\.\pipe\ivory-xl1200-<pid> + dual-stack TCP (--debug-tcp 127.0.0.1:12345) with a small zero-dependency PowerShell / Python one-liner client (scripts/xl1200-ctl.py or scripts/xl1200-ctl.ps1).
    • Triage playbook for common beta-tester issues: Boot PROM missing/swapped (115988+115989), SCSI :ro vs :rw (%Merlin-SCSI-data-protect), Y2K RTC clock prompt on unpatched Genera 8.3, Show FEP Directory 9 GB bitmap scan delay, Disk Restore >2047 MiB paging trap, Windows firewall/Npcap/SDL3 video-driver diagnostics, and how to inspect an attached ivory-bug-report-*.zip.
  2. Portable Cross-Agent Debugging Skill (updating .agents/skills/xl1200-live-debug/SKILL.md and documenting agent-agnostic usage in docs/TROUBLESHOOTING.md):
    • Standard YAML frontmatter (name + description — compatible with Antigravity, Claude Code, Codex CLI, and Cursor Agent Skills spec).
    • Zero Antigravity-only tool assumptions: uses standard shell/Python commands that work identically on Linux/macOS and Windows (PowerShell / python3), adding disasm, bt-sym, inspect, sample-sym, and bug-report triage workflows.

4. Verification & Acceptance Criteria

PhaseAutomated TestsEnd-to-End & Hygiene Gates
Phase 1: DisassemblerNew emu/tests/test_disasm.c: tests all 4 packed formats, all 64 DTP tags, CDR-JUMP/CDR-NIL, fullword calls, ENTRY headers, branch offset sign extension, and invalid/spare opcode formatting.Cross-check decoded output of genuine fep330/rom.dump entry block (0xF8007162) against docs/fep330-disassembly.md.
Phase 2: Symbol Walker & Bug DumpExpand emu/tests/test_disasm.c + emu/tests/test_bug_report.c: synthetic heap objects (DTP-SYMBOL, DTP-STRING, forwarding loops verifying cycle cap, compiled-function debug info) and verifying report.txt inside .zip contains disassembled mnemonics.Live Genera 8.3 check: compare bt-sym output over xl1200-ctl.sh against Genera's own :Backtrace inside the Debugger.
Phase 3: UI Workbench TabsExpand emu/tests/test_ui_workbench.c: switch across Debug & Snapshots tabs under SDL_VIDEODRIVER=dummy (Linux + Wine), verify zero crashes when cpu == NULL or powered off.Visual screenshot check of Disassembly / Registers / Stack / Memory tabs in both 15 px and 18 px fonts.
Phase 4: Lean Sampleremu/tests/test_debug_ctl.c: run sample-sym 20 100 <tmp.folded> and verify valid .folded syntax.Confirm 0 diffs in libivory_core.so (readelf -WS, nm -D, sizeof).
Phase 5: Docs & Portable SkillVerify all Linux (AF_UNIX) and Windows (Named Pipe + TCP) commands in docs/TROUBLESHOOTING.md and SKILL.md against live test runs (test_debug_ctl on Linux & Wine).nix develop --command make -C emu -j all test + nix develop .#mingw --command make -C emu TARGET_OS=windows -j all dist-win test-win pass 100%.

5. File Impact Summary

FileActionPurpose
emu/include/ivory_disasm.h, emu/src/ivory_disasm.cNewFrom-scratch 40-bit Ivory instruction disassembler (host shell only)
emu/include/ivory_sym_walk.h, emu/src/ivory_sym_walk.cNewRead-only, cycle-safe Genera symbol/function/stack/trap walker
emu/src/bug_report.cEditInclude symbolic disassembly & symbolic stack backtrace in report.txt
emu/src/debug_ctl.c, emu/src/emu_script.cEditAdd disasm, bt-sym, inspect, trap-info, and lean sample-sym
emu/src/ui_workbench.cEditAdd Registers, Disassembly/Stack, and Memory viewer tabs in Debug & Snapshots
emu/tests/test_disasm.c, test_bug_report.c, test_ui_workbench.c, emu/MakefileNew / EditUnit tests for disassembler, symbol walker, symbolic bug dumps, UI tabs
docs/TROUBLESHOOTING.md, scripts/xl1200-ctl.py (or .ps1), .agents/skills/xl1200-live-debug/SKILL.mdNew / EditBeta-tester troubleshooting guide + cross-agent Unix & Windows live-debug skill
Related Chip Datasheets (3)All Component Datasheets →