Multi-Architecture Common Lisp Assembler & Disassembler Plan (tools/ivasm/)
Status: Implemented (DONE — Phases 1–3; Phase 4 standalone ECL packaging deferred) — Implemented as zero-dependency portable ANSI Common Lisp (
tools/ivasm/, ASDF systemivasm+ pure-CLsrc/load.lisp) verified on SBCL, ECL, and CLISP, with 100% C ↔ CL S-expression parity againstemu/src/ivory_disasm.cand 0-byte-diff round-trips on authenticIFEP promJ,.fep, and.flodbinaries. Seedocs/ROADMAP.md.
Target Toolchain: Standalone portable ANSI Common Lisp (tools/ivasm/, ASDF system ivasm) — zero libivory_core ABI impact
Reference Sources: emu/include/ivory_hw.h, docs/hardware-reference/01-cpu-data-types-and-registers.md, docs/hardware-reference/02-isa-and-execution-semantics.md, docs/instruction-set-lexicon.md, docs/boot-rom.md, docs/ifep-file-formats-and-decompilation.md, and local-only genera-original/sys.sct/i-compiler/
1. Executive Summary & Goals
Reverse-engineering Symbolics firmware (IFEP promJ, i328-kernel.fep, .flod overlays, .ibin drivers) and authoring clean-room Ivory code (starting with a custom XL1200 Boot PROM) require a bidirectional assembler and disassembler that understands both 40-bit Ivory instructions and Symbolics binary file containers.
Key requirements:
- Shared Lisp-Style S-Expression Syntax: Disassembler output — both from this standalone Common Lisp tool and from the C disassembler (
emu/src/ivory_disasm.c) specified indocs/debugger-profiler-plan.md— uses a single canonical S-expression surface syntax directly accepted as assembler input. - Portable ANSI Common Lisp (SBCL + ECL + CLISP): Primary development targets SBCL, while ECL and CLISP (all packaged in Nix) run the automated test suite to eliminate SBCL-isms and guarantee ANSI CL portability. Native standalone / Windows packaging via ECL C-compilation is deferred to Phase 4; running locally on SBCL is sufficient for Phases 1–3.
- Multi-Architecture Core: Pluggable architecture backends via CLOS generic functions so the assembler/disassembler handles Ivory Rev 4/4A first and extends cleanly to FrameThrower binaries (AVP sync microsequencer tables in
i328-framethrower.sync, Photon ASQ microcode inmicroload-74.ibin, and.ibinhardware drivers) fordocs/color-graphics-plan.md. - Native Ivory Binary Container Construction & Parsing: Direct read/write support for
IFEP promimages (combinedrom.dumpand split 64 KiB115988/115989EPROMs),.fepkernels/BOLs (20-byte-chunk interleaved 1,280-byte pages),.floddynamic overlays ("IFEP overlayH", Kernel UID, command table), and.ibinFASL files. - Immediate Flagship Use Case: Assembling the clean-room XL1200 SCSI & CD-ROM Boot PROM specified in
docs/custom-boot-prom-plan.md(incorporating Merlin-II cache and Boot Comm Area lessons fromSymbolics-XL1200_MiSTer/tools/bootprom.py, extended with ISO-9660 CD-ROM IFEP kernel boot).
flowchart TD
SRC["Canonical Lisp S-Expression Source<br/>(Hand-Written or Disassembled)"]
C_DIS["emu/src/ivory_disasm.c<br/>(debug_ctl disasm --lisp / Bug Dump)"]
subgraph IVASM["tools/ivasm/ (Portable ANSI CL: SBCL + ECL + CLISP)"]
CORE["Core Engine<br/>cl:read IR, Multi-Pass Label/Branch Solver,<br/>CLOS Architecture & Container Protocols"]
IVORY["Arch Backend: :ivory-rev4<br/>256 Opcodes, Formats 1-4, Fullwords,<br/>CDR-JUMP / Halfword Packer, Macros"]
FT["Arch Backend: :framethrower (Future)<br/>AVP Sync Microcode & Photon ASQ"]
FMT["Container Backends<br/>:ifep-prom, :ifep-fep, :ifep-flod,<br/>:ibin-fasl, :raw-words"]
end
OUT_PROM["Boot PROM Images<br/>rom.dump + 115988 / 115989"]
OUT_FEP["IFEP Kernels & Overlays<br/>.fep / .flod"]
OUT_IBIN["Genera FASL Analysis & Build<br/>.ibin"]
C_DIS -- "Shared S-Expr Contract" --> SRC
SRC --> CORE
CORE <--> IVORY
CORE <-.-> FT
CORE <--> FMT
FMT <--> OUT_PROM
FMT <--> OUT_FEP
FMT <--> OUT_IBIN2. Canonical Lisp S-Expression Syntax (Shared C & CL Contract)
The assembly/disassembly format is valid Common Lisp S-expression syntax readable directly by cl:read without a custom lexer. Every file emitted by ivasm disasm or ivory-xl1200 (debug_ctl disasm --lisp) is directly valid input to ivasm asm.
2.1 Module & Section Structure
(module :arch :ivory-rev4
:format :ifep-prom
:entry boot-entry
:meta (:prom-version "J" :comment "Clean-room XL1200 SCSI/CD-ROM Boot PROM")
(section :vma #xF8007162 :name :code
(:label boot-entry)
(entry-rest-not-accepted 0 0)
;; Format 1: operand modes (fp k), (lp k), (sp-pop), (sp k), (imm v)
(push (imm #x02))
(push-address (fp 2))
(add (sp-pop) (imm 1))
;; Format 3: 8-bit immediate / byte specifier (byte size position)
(ldb (byte 8 16) (lp 3))
;; Format 2: PC-relative branch resolved automatically across passes
(branch-false wait-loop)
;; Fullword call starter (always occupies a full 40-bit word;
;; packer inserts CDR-JUMP / NOOP automatically if currently at :odd)
(call-compiled-even scsi-init)
;; Raw 40-bit tagged word / inline constant
(word :cdr :next :dtp :fixnum :data #x0A000004)
;; Explicit 40-bit packed word control (emitted by disassembler when
;; non-default CDR codes or unreachable odd halfwords must round-trip)
(:word :cdr :jump
:even (branch done)
:odd (noop))
(:label wait-loop)
(branch wait-loop)
(:label done)
(return-single (sp-pop))))
2.2 Syntax & Packing Rules
| Construct | Syntax | Semantics |
|---|---|---|
| Operand — Frame / Local / Stack | (fp k), (lp k), (sp-pop), (sp k) | Format 1 addressing modes (k in 0..255). |
| Operand — Immediate | (imm v) | Format 1 signed 8-bit immediate (-128..127) or Format 3 unsigned 8-bit immediate (0..255), validated against the opcode descriptor. |
| Operand — Byte Specifier | (byte ss pp) | Format 3 10-bit (size, position) specifier for ldb, dpb, char-ldb, p-ldb, p-dpb, p-tag-ldb, p-tag-dpb. |
| Branch Target | label-sym or (target :vma #x... :slot :even|:odd) | Format 2 signed 10-bit halfword displacement (-512..+511 halfwords). Symbolic labels resolve automatically; raw numeric targets allow exact disassembly of slices without inventing labels. |
| Entry Header | (entry-rest-accepted min max) / (entry-rest-not-accepted min max) | Format 4 entry instruction (always aligned to :even halfword). |
| Fullword Call Starters | (call-compiled-even target), (call-compiled-odd target), (call-indirect addr), (call-generic addr) (+ -prefetch variants) | Full 40-bit instruction (DTP 0o50..0o57). Automatically aligns to a word boundary when packing free-form code. |
| Inline Constant / Raw Word | (word :cdr :next|:nil|:normal|:jump :dtp <tag> :data <u32>) | Emits an exact 40-bit Ivory word (cdr<39:38>, dtp<37:32>, data<31:0>). Defaults: :cdr :next, :dtp :fixnum. |
| Explicit Packed Word | (:word :cdr <cdr> :even <insn> :odd <insn>) | Locks both halfwords and the 2-bit CDR code explicitly. Used by the disassembler whenever a word has CDR-JUMP (cdr=3), CDR-NIL (cdr=1), or a non-canonical odd slot so disassembly → assembly round-trips bit-for-bit. |
| Alignment & Origin | (:align-word) / (:org #x...) | Pads :odd halfword to next word boundary (via CDR-JUMP or NOOP) or sets section VMA cursor. |
| Annotations | ; #xF8007162:E [3:62:01234567] SI::FOO+0x4 | All addresses, hex dumps, and resolved Genera symbol names are emitted strictly as ; comments so the file remains clean cl:read input. |
2.3 C ↔ Common Lisp Compatibility Contract (emu/src/ivory_disasm.c)
To keep docs/debugger-profiler-plan.md and tools/ivasm/ synchronized:
- Both share the exact same lowercase hyphenated mnemonic table derived from
emu/include/ivory_hw.h(e.g.,push,push-address,branch-false,call-compiled-even,entry-rest-not-accepted,ldb,memory-read). emu/src/ivory_disasm.cexposes both a compact single-line debugger layout (forui_workbench.candreport.txt) and a--lispexport mode (debug_ctl disasm --lisp <vma> <count>and(emu/disasm vma count :lisp)) that emits a complete(module :arch :ivory-rev4 ... (section :vma ...))S-expression ready forivasm asm.- A shared golden test corpus verifies that C disassembly (
--lisp) and CL disassembly produce identical S-expression forms across all 256 opcodes, Formats 1–4, fullwords,CDR-JUMP, and inline constants.
3. Portable ANSI Common Lisp Architecture
3.1 Zero-Dependency ASDF Layout (tools/ivasm/)
To ensure offline Nix builds and seamless portability across SBCL, ECL, and CLISP, tools/ivasm/ uses pure ANSI Common Lisp + ASDF with zero Quicklisp or third-party runtime dependencies:
tools/ivasm/
├── ivasm.asd # ASDF system definition (:depends-on ())
├── bin/
│ └── ivasm # Thin CLI wrapper invoking sbcl/ecl/clisp
├── src/
│ ├── package.lisp # Package definitions (ivasm, ivasm.core, ivasm.ivory, ...)
│ ├── compat.lisp # ~100 LOC portability shim (argv, exit, binary octet streams)
│ ├── arch-protocol.lisp # CLOS generic protocol for target architectures
│ ├── format-protocol.lisp # CLOS generic protocol for binary file containers
│ ├── ir.lisp # S-expression reader, macro expander, sections, labels, fixups
│ ├── assembler.lisp # Multi-pass assembler (relaxation, relocation, diagnostics)
│ ├── disassembler.lisp # Generic disassembler + canonical S-expr pretty-printer
│ ├── arch/
│ │ ├── ivory/
│ │ │ ├── word.lisp # 40-bit Ivory word (cdr, dtp, data) & tag tables
│ │ │ ├── opcodes.lisp # All 256 Rev 4/4A opcodes, Formats 1-4, fullwords
│ │ │ ├── codec.lisp # Encode/decode + halfword/CDR-JUMP packer
│ │ │ └── macros.lisp # Assembly helper macros (Merlin PMA I/O, frames, loops)
│ │ └── framethrower/ # (Phase 3+) AVP sync sequencer & Photon ASQ microcode
│ │ └── backend.lisp
│ ├── formats/
│ │ ├── raw-words.lisp # Flat 5-byte / 8-byte LE 40-bit word streams
│ │ ├── ifep-prom.lisp # IFEP prom container (rom.dump + split 115988/115989)
│ │ ├── ifep-fep.lisp # .fep kernel/BOL (1,280B 20-byte-chunk interleaved pages)
│ │ ├── ifep-flod.lisp # .flod overlay ("IFEP overlayH", UID, command directory)
│ │ └── ibin-fasl.lisp # .ibin FASL parser/disassembler (+ Phase 3 emitter)
│ └── cli.lisp # Subcommands: asm, disasm, inspect, verify-roundtrip
└── tests/
├── suite.lisp # Portable test runner (no external test framework needed)
├── test-ivory-isa.lisp # All 256 opcodes, Formats 1-4, CDR-JUMP, branch bounds
├── test-formats.lisp # Synthetic IFEP prom, .fep, .flod, .ibin round-trips
└── test-real-media.lisp # Optional bit-exact round-trip on local ROM/IFEP (SKIP if absent)
3.2 Multi-CL Portability Policy (SBCL, ECL, CLISP)
| Implementation | Nix Package | Role | Enforcement |
|---|---|---|---|
| SBCL | pkgs.sbcl | Primary development target & daily CLI driver | Strict compile-time warnings treated as test failures (handler-bind). |
| ECL | pkgs.ecl | Portability gate (bytecode & C-compiler semantics) + future Phase 4 standalone binary candidate | Full test suite run in Nix (make -C tools/ivasm test-ecl). |
| CLISP | pkgs.clisp | Portability gate (strict ANSI CL, catches SBCL/CLOS/path/stream assumptions) | Full test suite run in Nix (make -C tools/ivasm test-clisp). |
Strict portability rules:
- All implementation-specific calls (
command-line-arguments,exit, binary(unsigned-byte 8)I/O, environment variables) live exclusively insrc/compat.lispbehind#+sbcl/#+ecl/#+clispreader conditionals. - No reliance on
sb-ext,sb-sys,sb-alien,sb-mop, Gray streams, or reader macros outside standard ANSI CL. - Integer arithmetic uses explicit
(ldb (byte width pos) ...)and fixed masks rather than fixnum-size assumptions (CLISP/ECL 32-bit/64-bit fixnum limits differ from SBCL). flake.nixaddspkgs.sbcl,pkgs.ecl, andpkgs.clispto the devShell (or a dedicated.#lispdevShell merged intodefault) so all three implementations are reproducible across machines.
4. Multi-Architecture & Binary Container Protocols
4.1 CLOS Architecture Protocol (arch-protocol.lisp)
Each target CPU or microcode engine subclasses target-architecture and implements six generic functions:
(arch-name arch)— keyword identifier (:ivory-rev4,:framethrower-avp,:framethrower-asq).(arch-word-spec arch)— word width in bits, sub-word slot structure, and endianness.(arch-expand-macro arch form env)— architecture-specific assembly macros before encoding.(arch-encode-form arch form cursor symtab)— encodes one instruction or directive into concrete words or unresolved relocation records.(arch-resolve-fixup arch fixup symtab)— patches branch displacements, call targets, and constant addresses once section layouts stabilize.(arch-decode-region arch bytes base-vma)— decodes raw target words into canonical S-expression forms + comment annotations.
Long-Term FrameThrower Backend (arch/framethrower/):
- Directly supports Phase 3 of
docs/color-graphics-plan.md:- Disassembling Genera's
probe.ibin,photon-hardware.ibin,avp-hardware.ibin, andcommand-queue.ibin(Ivory code inside:ibin-faslcontainers). - Parsing and disassembling
i328-framethrower.sync(AVP Am2910-based sync microsequencer tables) andmicroload-74.ibin(Photon ASQ pixel-engine microcode) once their instruction bitfields are documented from driver disassembly.
- Disassembling Genera's
4.2 Binary Container Backends (formats/)
| Format Keyword | File Types | Read / Disasm | Assemble / Emit | Key Structural Details (from docs/ifep-file-formats-and-decompilation.md) |
|---|---|---|---|---|
:raw-words | .bin, memory dumps | Phase 1 | Phase 1 | Flat 5-byte LE or 8-byte LE 40-bit Ivory words. |
:ifep-prom | rom.dump, 115988+115989 | Phase 1 | Phase 1 | 30-byte "IFEP prom<v>" header, 5-byte LE packed 40-bit words, section descriptors (vma, len), 32-bit additive checksum of payload bytes, footer (entry_vma, 0xFFFFFFFF); automatic split/join of sequential Low 64 KiB (115988, 0x00000..0x0FFFF) and High 64 KiB (115989, 0x10000..0x1FFFF) EPROM images. |
:ifep-fep | i328-kernel.fep, i325-bol.fep | Phase 2 | Phase 2 | 1,280-byte disk pages packed as 64 × 20-byte chunks (tags first: 4 × 8-bit tag/CDR bytes [0..3], followed by 4 × 32-bit LE data words [4..19]); Page 0 descriptor table (extent loads + inline FEP-COMMUNICATION-AREA patches) and 32-bit ones-complement checksum in w[5]. |
:ifep-flod | *.flod overlays | Phase 2 | Phase 3 | "IFEP overlayH" header, 64-bit Kernel Build UID (5c3931aef3e75a93 for IFEP 328), command directory table (command name, argument template, entry VMA), checksummed sections targeting the 0xF8001100 overlay window. |
:ibin-fasl | *.ibin Genera FASLs | Phase 2 | Phase 3 | Symbolics Ivory binary load file opcode stream (compiled function headers, instruction words, constant vectors, symbol/package intern records). |
5. Phased Implementation Plan
Phase 1 — Core Engine, :ivory-rev4, :ifep-prom & Shared C/CL Syntax (~2–3 days)
- Implement
compat.lisp,arch-protocol.lisp,format-protocol.lisp,ir.lisp, multi-passassembler.lisp, anddisassembler.lisp. - Implement full
:ivory-rev4ISA backend (all 256 opcodes, Formats 1–4, fullwords,CDR-JUMP/halfword packer, branch range checks). - Implement
:raw-wordsand:ifep-prom(both combinedrom.dumpand split115988/115989EPROM images). - Lock the canonical S-expression syntax with
emu/src/ivory_disasm.cvia a shared golden test corpus. - Pass full unit suite on SBCL, ECL, and CLISP inside
nix develop. - Milestone Gate: Disassemble local user-supplied
fep330/rom.dump→ reassemble withivasm asm→ byte-identicalIFEP promJoutput (including 32-bit checksum and split115988/115989hashes).
Phase 2 — :ifep-fep, :ifep-flod & :ibin-fasl Inspection/Disassembly (~2–3 days)
- Add
:ifep-fep20-byte-chunk page unpacker/packer and:ifep-flodoverlay parser/inspector (ivasm inspectdumps Kernel UID, section map, and command directory table). - Add
:ibin-faslparser and disassembler capable of extracting and disassembling every compiled function in Genera.ibinfiles (including FrameThrower'sprobe.ibin,photon-hardware.ibin,avp-hardware.ibin, andmicroload-74.ibin). - Unblocks Phase 1 & Phase 2 of
docs/custom-boot-prom-plan.md.
Phase 3 — .flod / .ibin Emission, Macro Kit & :framethrower Plugin (~2–3 days)
- Implement
:ifep-flodemitter (generating valid checksummed overlays with Kernel UID and command directory entries) and initial:ibin-faslemitter. - Add Ivory assembly macro kit (structured
defproc, loop/branch helpers, Merlin-II PMA I/O macros, WD33C93A register helpers). - Add
:framethrowerarchitecture plugin skeleton for AVP sync microcode and Photon ASQ binary analysis.
Phase 4 (Later / Optional) — Standalone Native & Windows Distribution via ECL
- Evaluate
ecl(asdf:make-build :type :program) to compileivasminto self-contained native Linux and Windows (MinGW-w64) executables without requiring end users to install a Lisp runtime. Out of scope until Phases 1–3 stabilize.
6. Verification & Testing Strategy
- Multi-CL Portability Gate: Every commit passes
make -C tools/ivasm test-all, executing the identical test suite undersbcl,ecl, andclisp. - ISA Coverage Gate: Unit tests encode and decode all 256 Ivory opcodes across all addressing modes, branch offset extremes (
-512,0,+511), byte specifiers, fullwords, andCDR-JUMP/CDR-NILpacking edge cases. - C ↔ CL Cross-Check Gate: Feed identical raw 40-bit instruction test vectors through both
emu/src/ivory_disasm.c --lispandivasm disasm, verify identical canonical S-expressions, then feed the C disassembler's output directly intoivasm asmand assert bit-identical 40-bit output. - Authentic Firmware Round-Trip Gate (Optional Local Media): When local user-supplied
rom.dumpori328-kernel.fepis present, verifydisasm → asmproduces 0 differing bytes; cleanly reportSKIPwhen proprietary media is absent (zero copyrighted binaries ever committed to the repository).
- Western Digital WD33C93A —
wd_WD33C93A_datasheet_and_appnotes_1990.pdf(mirror) - Western Digital WD33C93A —
wd_WD33C93A_scsi_datasheet.pdf(mirror)