Symbolic Ivory Disassembler, Live Debugger & Profiler Plan
Status: Implemented (DONE) — All 5 phases implemented in the host shell (
SHELL_SRCS) with zerolibivory_coreABI changes and verified on Linux (16/16 unit + 6/6 E2E) and Windows/Wine (16/16 unit). Seedocs/ROADMAP.mdanddocs/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.ccaptures raw words aroundPC, raw stack words, and 16 raw frame links, without decoded Ivory mnemonics or Lisp function names.emu/src/ui_workbench.c(Debug & Snapshots) showsPC/SP/FP/LP/LED/instr_countand numeric breakpoints/watchpoints, but has no disassembly, full register/FPA inspector, or symbolic stack viewer.emu/src/debug_ctl.chasregs,bt,mem,pma,hw, and a ~50-line raw-PCsample [N]command, but no symbolic disassembler or symbol-aware backtrace..agents/skills/xl1200-live-debug/SKILL.mdis tailored to local POSIX/tmp/ivory-xl1200-*.sockworkflows 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:
- 40-Bit Ivory Instruction Disassembler (
emu/src/ivory_disasm.c). - Side-Effect-Free Genera Symbol, Function & Stack Walker (
emu/src/ivory_sym_walk.c) feedingdebug_ctl,bug_report.c.ziparchives, ands7REPL. - Interactive Disassembly / Register / Stack / Memory Tabs in
Debug & Snapshots(ui_workbench.c). - Low-Cost On-Demand Symbolic Sampler (
sample-sym, ~120–150 LOC) extending existingdebug_ctl.csample [N]to export standard.foldedstacks forflamegraph.pl/speedscope.app(explicitly excluding costly background sampling or in-GUI flamegraph rendering). - Vendor-Neutral Beta-Tester Troubleshooting Guide & Portable Cross-Agent Skill (
docs/TROUBLESHOOTING.md+ portableSKILL.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 & 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.candivory_sym_walk.ccompile solely intoivory-xl1200(and unit tests), adding 0 bytes tolibivory_core.so/.dlland requiring noIVORY_CORE_ABI_VERSIONbump. - 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,modifiedbit 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 orBug Dump. - Reference Provenance: Opcode tables, addressing-mode syntax, and Genera object layouts derive exclusively from
emu/include/ivory_hw.h,docs/hardware-reference/, andgenera-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 inemu/include/ivory_hw.h. - Exact Format 1 (
FP+k,LP+k,SP-pop,SP-k,Immediate), Format 2 (signed 10-bit branch offset resolved totarget_vma:E|O), Format 3 (8-bit unsigned immediate /LDB/DPBbyte-specifier(byte ss pp)), and Format 4 (ENTRY-REST-ACCEPTED/ENTRY-REST-NOT-ACCEPTEDmin/max/restdecoding). - Annotates
CDR-JUMP(cdr == 3, skips Odd slot) andCDR-NIL(cdr == 1, function trailer / fence).
- Even (
- 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-CONSTANTwith formattedFIXNUM,CHARACTER,SINGLE-FLOAT,NIL/T,SYMBOL,LIST, orLOCATIVE.
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.cuses 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 fromemu/include/ivory_hw.h.- Alongside the compact single-line view for
ui_workbench.candreport.txt,ivory_disasm.cexposes 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 intoivasm asmwithout 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): ReadsDTP-STRING(ART-STRING/ART-FAT-STRING/DTP-ARRAYwithDTP-HEADER-Ilength & 4-char/word 8-bit ASCII packing, forwarding throughDTP-ARRAY-FORWARD/DTP-HEADER-FORWARDup toMAX_IND_HOPS). - Symbol Formatter (
ivory_sym_format_symbol): ReadsDTP-SYMBOLprint-name (sym + 0,DTP-HEADER-Psymbol header) and package cell (sym + 4→ package instance/string;+3is property list) into"PKG:NAME"or"NAME". - Stack-Cache-Aware Peek (
ivory_sym_peek_vma): Checks the active 128-wordcpu->stack_cachering (vma & 0x7F) before delegating toapi->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 to4096words, stopping at page faults or prior function headers) to locate the enclosingDTP-HEADER-I/DTP-EVEN-PC/ENTRYcompiled-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).
- Scans backward from
- Trap Vector Resolver (
ivory_sym_resolve_trap): Reads the active Rev 4*TRAP-DISPATCH-TABLE*entry or mapsIVORY_REV4_USTATE_*microstate IDs to human-readable names (MEMORY-DATA-ERROR,TRAP-ON-EXIT,STACK-OVERFLOW, etc.). - Symbolic Control-Stack Backtrace (
ivory_sym_backtrace): WalksFPframe links using the verified Ivory 2-word frame header (continuation,controlCR) and resolves each frame'sPCviaivory_sym_resolve_pc()+ argument count (cr.argument_size).
Immediate Integration Points
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.zipattachment.
- Replaces raw-only instruction & backtrace hex blocks with symbolic disassembly (
emu/src/debug_ctl.c(Live IPC & Puppet):disasm [hex_vma] [count](default: around currentPC,16words)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)
emu/src/emu_script.c(s7REPL):(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):
Overview & Controls(existing controls:Save Bug Dump (.zip)...,.snap,Video Recording...,Screenshot...,Reload Core, COW checkpoints, Breakpoints/Watchpoints).Registers & State: Complete live readout of Ivory CPU registers (PC,SP,FP,LP,CRbitfields: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.Disassembly & Stack:- Scrollable disassembly window centered on
PC(withFollow PCcheckbox, address jump box,Step 1/Step 10/Continuebuttons, and inline[BP]toggle buttons). - Scrollable symbolic backtrace list (
#0..#15) where clicking a frame jumps the disassembly view to that frame's returnPC.
- Scrollable disassembly window centered on
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.calready includes a ~50-line synchronoussample [N]command that stepsNchunks 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 sampledPC(plus optional 8-frame shallowFPwalk) through a tiny per-run(entry_vma -> name)cache overivory_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 externalflamegraph.plor browser-basedspeedscope.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 likespeedscope.appare vastly better at zero maintenance cost).
- Continuous always-on background sampling inside
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:
docs/TROUBLESHOOTING.md(human- and agent-readable reference):- One-click bug reporting: How to trigger
Bug Dumpin the GUI (orbug-reportvia 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.pyorscripts/xl1200-ctl.ps1).
- Unix:
- Triage playbook for common beta-tester issues: Boot PROM missing/swapped (
115988+115989), SCSI:rovs:rw(%Merlin-SCSI-data-protect), Y2K RTC clock prompt on unpatched Genera 8.3,Show FEP Directory9 GB bitmap scan delay,Disk Restore>2047 MiB paging trap, Windows firewall/Npcap/SDL3 video-driver diagnostics, and how to inspect an attachedivory-bug-report-*.zip.
- One-click bug reporting: How to trigger
- Portable Cross-Agent Debugging Skill (updating
.agents/skills/xl1200-live-debug/SKILL.mdand documenting agent-agnostic usage indocs/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), addingdisasm,bt-sym,inspect,sample-sym, andbug-reporttriage workflows.
- Standard YAML frontmatter (
4. Verification & Acceptance Criteria
| Phase | Automated Tests | End-to-End & Hygiene Gates |
|---|---|---|
| Phase 1: Disassembler | New 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 Dump | Expand 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 Tabs | Expand 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 Sampler | emu/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 Skill | Verify 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
| File | Action | Purpose |
|---|---|---|
emu/include/ivory_disasm.h, emu/src/ivory_disasm.c | New | From-scratch 40-bit Ivory instruction disassembler (host shell only) |
emu/include/ivory_sym_walk.h, emu/src/ivory_sym_walk.c | New | Read-only, cycle-safe Genera symbol/function/stack/trap walker |
emu/src/bug_report.c | Edit | Include symbolic disassembly & symbolic stack backtrace in report.txt |
emu/src/debug_ctl.c, emu/src/emu_script.c | Edit | Add disasm, bt-sym, inspect, trap-info, and lean sample-sym |
emu/src/ui_workbench.c | Edit | Add Registers, Disassembly/Stack, and Memory viewer tabs in Debug & Snapshots |
emu/tests/test_disasm.c, test_bug_report.c, test_ui_workbench.c, emu/Makefile | New / Edit | Unit 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.md | New / Edit | Beta-tester troubleshooting guide + cross-agent Unix & Windows live-debug skill |
- Weitek WTL1164/1165 (W3x64 family) —
weitek_WTL1164_1165_64bit_ieee_1986.pdf(mirror) - Weitek WTL3132/3332 (W3x64 family) —
weitek_WTL3132_3332_fpdp_1988.pdf(mirror) - Weitek WTL3167 (W3x64 core) —
weitek_WTL3167_coprocessor_1988.pdf(mirror)