Ivory Assembler & Disassembler (tools/ivasm/)
tools/ivasm/ is a standalone, portable ANSI Common Lisp multi-architecture assembler, disassembler, and binary container toolkit for Symbolics Ivory Rev 4/4A firmware and binaries (plus skeleton microcode backends for FrameThrower AVP/ASQ).
It shares the exact canonical Lisp S-expression syntax emitted by the C11 emulator's live disassembler (emu/src/ivory_disasm.c), requires zero external Quicklisp libraries, and runs on SBCL, ECL, and GNU CLISP.
1. Quickstart & CLI Reference
Invoke the CLI launcher at tools/ivasm/bin/ivasm. By default it runs under sbcl; override the runtime with IVASM_LISP=sbcl|ecl|clisp.
# Assemble S-expression source into a combined IFEP promJ image + split 64 KiB EPROMs
./tools/ivasm/bin/ivasm asm prom/src/boot-prom.lisp \
-o prom/build/custom-rom.dump \
--split-lo prom/build/115988-custom.bin \
--split-hi prom/build/115989-custom.bin
# Assemble an IFEP 328 .flod overlay
./tools/ivasm/bin/ivasm asm prom/overlays/hello-overlay.lisp \
-o prom/build/custom-diag.flod
# Disassemble any supported binary (format auto-detected by header/magic)
./tools/ivasm/bin/ivasm disasm prom/build/custom-rom.dump -o /tmp/custom-rom.lisp
# Inspect container headers, sections, checksums, and .flod command tables
./tools/ivasm/bin/ivasm inspect prom/build/custom-rom.dump
./tools/ivasm/bin/ivasm inspect prom/build/custom-diag.flod
# Verify byte-for-byte 0-diff disassemble -> reassemble round-trip
./tools/ivasm/bin/ivasm verify-roundtrip prom/build/custom-rom.dump
# Split or join 64 KiB physical EPROM dumps (115988 low + 115989 high)
./tools/ivasm/bin/ivasm split-prom rom.dump 115988.bin 115989.bin
./tools/ivasm/bin/ivasm join-prom 115988.bin 115989.bin -o rom.dump
# Run with an alternate Common Lisp implementation
IVASM_LISP=ecl ./tools/ivasm/bin/ivasm inspect prom/build/custom-rom.dump
IVASM_LISP=clisp ./tools/ivasm/bin/ivasm inspect prom/build/custom-rom.dump
Subcommand Summary
| Command | Arguments & Flags | Behavior |
|---|---|---|
asm | <in.lisp> -o <out.bin> [--format <fmt>] [--split-lo <115988> --split-hi <115989>] | Multi-pass assembly (macro expansion, halfword packing, label/fixup resolution, container serialization). --format overrides the module's :format. |
disasm | <in.bin> [-o <out.lisp>] [--format <fmt>] | Disassembles container into canonical (module ...) S-expressions (stdout if -o omitted). |
inspect | <in.bin> [--format <fmt>] | Prints container format, byte size, entry VMA, header metadata, section ranges, and .flod command tables. |
verify-roundtrip | <in.bin> [--format <fmt>] | Disassembles <in.bin>, reassembles the output in memory, and checks byte-for-byte equality (0 diffs). |
split-prom | <in.dump> <out-lo-115988> <out-hi-115989> | Splits an IFEP prom image into two zero-padded 64 KiB EPROM files. |
join-prom | <in-lo-115988> <in-hi-115989> -o <out.dump> | Concatenates low + high 64 KiB EPROM dumps into a combined rom.dump. |
Accepted --format values: raw-words (raw), ifep-prom (prom), ifep-fep (fep), ifep-flod (flod), ibin-fasl (ibin). When omitted, detect-format-from-octets identifies "IFEP overlayH" (:ifep-flod), "IFEP prom" (:ifep-prom), #xF013 (:ibin-fasl), 1,280-byte-aligned Page 0 header 0x48 (:ifep-fep), or falls back to :raw-words.
2. Package Architecture & Source Layout
tools/ivasm/ uses a small CLOS architecture/format registry so new instruction sets or binary containers can be added without modifying the core assembler loop:
tools/ivasm/
├── Makefile # test-sbcl, test-ecl, test-clisp, test-golden-c, test-real-media, test-all
├── ivasm.asd # Optional ASDF system definition (zero external dependencies)
├── bin/ivasm # Portable POSIX launcher (IVASM_LISP=sbcl|ecl|clisp)
├── src/
│ ├── package.lisp # Packages: ivasm.core, ivasm.ivory, ivasm.framethrower, ivasm.formats, ivasm.cli
│ ├── compat.lisp # Portable CLI args, exit, binary octet I/O, define-constant (SBCL/ECL/CLISP)
│ ├── ir.lisp # IR structs (ir-module, ir-section, ir-fixup) & recursive (:include ...) reader
│ ├── arch-protocol.lisp # CLOS generics: arch-word-spec, arch-expand-macro, arch-pack-section-items, arch-resolve-fixup, arch-decode-region
│ ├── format-protocol.lisp # CLOS generics: read-container, write-container, inspect-container
│ ├── assembler.lisp # Two-pass global assembler (macro expansion -> layout -> cross-section fixups)
│ ├── disassembler.lisp # Container disassembly to canonical S-expression string
│ ├── cli.lisp # CLI parser & subcommand dispatch
│ ├── load.lisp # Plain CL loader (used by bin/ivasm & Makefile without requiring ASDF)
│ ├── arch/
│ │ ├── ivory/
│ │ │ ├── word.lisp # 40-bit word helpers, 4 CDR codes, 64 DTP tags, internal register names
│ │ │ ├── opcodes.lisp # Complete 256-entry Ivory Rev 4/4A opcode table & operand formats
│ │ │ ├── codec.lisp # Halfword/fullword encoder & decoder, 10-bit branch & call fixups
│ │ │ └── macros.lisp # Built-in Ivory assembly macro kit (defproc, pma-read/write, defstring, ...)
│ │ └── framethrower/
│ │ └── backend.lisp # Skeleton backends: :framethrower-avp (64-bit) and :framethrower-asq (32-bit)
│ └── formats/
│ ├── raw-words.lisp # :raw-words (5-byte little-endian packed 40-bit words)
│ ├── ifep-prom.lisp # :ifep-prom (IFEP promJ/H/E, section checksums, 64 KiB split/join)
│ ├── ifep-fep.lisp # :ifep-fep (1,280B pages, 20B tag-first chunks, Page 0 descriptors, ones-comp checksum)
│ ├── ifep-flod.lisp # :ifep-flod (IFEP overlayH v1, 64-bit Kernel UID, command table)
│ └── ibin-fasl.lisp # :ibin-fasl (#xF013 QFASL/IBIN decoder + round-trip serializer)
└── tests/
├── suite.lisp # Portable unit tests (run on SBCL, ECL, and CLISP)
├── test-golden-c.lisp # 304-case C (emu/build/test_disasm) <-> CL syntax/encoding cross-check
└── test-real-media.lisp # 0-diff round-trip verification on authentic local PROM/.fep/.flod/.ibin files
Registered Architectures
| Keyword | Word Width | Status |
|---|---|---|
:ivory-rev4 | 40 bits (5 B) | Complete Ivory Rev 4/4A encoder, decoder, macro kit, and 256-entry ISA table |
:framethrower-avp | 64 bits (8 B) | Skeleton architecture backend (word / raw 64-bit microcode words) for future FrameThrower work |
:framethrower-asq | 32 bits (4 B) | Skeleton architecture backend (word / raw 32-bit microcode words) for future FrameThrower work |
3. Canonical Ivory S-Expression Assembly Syntax
Every source file is a standard Common Lisp S-expression read with *read-eval* bound to nil (safe against arbitrary reader evaluation).
Module & Section Structure
(module :arch :ivory-rev4
:format :ifep-prom
:entry boot-entry
:meta (:prom-version "J"
:header-words (#x00000001 #x01F80410 #x4A000000 #x08000001 #x00000053))
(section :vma #xF8007162 :name :code
(:include "hw-defs.lisp")
(:include "entry.lisp")
...))
:entry: integer VMA or symbolic label defined in any section.(:include "relpath.lisp"): recursively splices forms from a file relative to the including file's directory.:meta: format-specific plist::ifep-prom::prom-version("J"),:header-words(5 u32s), optional:pad-to(e.g.,131072) and:tail-non-zero.:ifep-flod::version(1),:header-pad,:kernel-uid(16-hex-char string),:commands ((:name "..." :doc "..." :entry label) ...).:ifep-fep: Page 0 descriptors and inline patches preserved transparently during round-trips.
Directives & Explicit Word Forms
| Form | Meaning |
|---|---|
(:label sym) | Binds sym to the current (vma . slot) (:even or :odd). Case-insensitive. |
(:align-word) | If currently at the :odd halfword slot, finalizes the pending word with :cdr :jump + :odd (no-op) so the next item starts on an :even word boundary. |
(word :cdr :next :dtp :fixnum :data #x1234) | Emits an exact full 40-bit tagged word (auto-aligns to word boundary). :data may be an integer or a symbolic label / defconst constant. |
(:word :cdr :next :even (<instr>) :odd (<instr>)) | Emits an explicitly paired 40-bit packed instruction word (used for exact round-trip fidelity and pinning entry-* / CDR-JUMP headers). |
Addressing Modes & Instruction Operands
Standard 18-bit halfword instructions pack automatically two per 40-bit word (even then odd). Fullword instructions (word constants, call-compiled-even, call-compiled-odd, call-indirect, call-generic, and -prefetch variants) automatically align to a word boundary and emit a single 40-bit word.
| Operand Form | Encoding / Meaning |
|---|---|
(fp N) | Frame Pointer offset N (0..255; arguments start at (fp 2)) |
(lp N) | Local Pointer offset N (0..255; locals allocated via (push-n-nils (imm K))) |
(sp N) | Stack Pointer relative offset N (1..255) |
(sp-pop) | Pop top-of-stack (SP mode, offset 0) |
(imm N) | 8-bit immediate (0..255 unsigned or -128..127 signed depending on opcode) |
(byte size pos) | Byte-field immediate for ldb, dpb, p-ldb, p-dpb, char-ldb, etc. (((size - 1) << 5) | pos) |
label or (target :vma #x... :slot :even|:odd) | Branch target (10-bit signed halfword displacement [-512, +511] from the branch instruction's halfword PC) |
:microsecond-clock, :control-register, etc. | Named Ivory internal registers for read-internal-register / write-internal-register |
:value, :effect, :return, :multiple | Disposition keywords for finish-call-n ((finish-call-n :value N)) |
:tos, :constant-nil, :constant-t | Return source keywords for return-single |
10-bit Branch Range: Ivory halfword branches carry a 10-bit signed halfword displacement ([-512, +511] halfwords ≈ ±255 words). Keep individual defproc bodies compact (< ~200 words) so intra-procedure branches never overflow.
4. Built-In Ivory Macro Kit (arch/ivory/macros.lisp)
Macros expand recursively in Pass 1 before instruction packing and fixup resolution:
| Macro | Expansion / Behavior |
|---|---|
(defconst NAME VAL) | Defines a compile-time integer constant resolved inside macros, word :data, and call starters. |
(defproc NAME (min [max] [:rest t]) body...) | Emits (:align-word), (:label NAME), and (entry-rest-not-accepted (+ 2 min) (+ 2 max)) (or entry-rest-accepted when :rest t). |
(push-fixnum N) | Emits (push (imm N)) when -128 <= N <= 127, otherwise a fullword (word :cdr :next :dtp :fixnum :data N). |
(push-pma ADDR) | Emits (word :cdr :next :dtp :physical-address :data ADDR) for direct Merlin-II physical bus access. |
(push-locative ADDR) | Emits (word :cdr :next :dtp :locative :data ADDR) (accepts integer or symbolic label). |
(pma-read ADDR) | (push-pma ADDR) followed by (memory-read (imm #x2C0)) (RAW_READ cycle 11). |
(pma-write ADDR VAL) | (push-pma ADDR), (push-fixnum VAL), (memory-write (sp-pop)). |
(merlin-led CODE) | Shorthand for (pma-write #x0A000000 CODE). |
(call-void FN arg1 ... argN) | Emits (call-compiled-even FN), each arg form, and (finish-call-n :effect N). |
(call-val FN arg1 ... argN) | Emits (call-compiled-even FN), each arg form, and (finish-call-n :value N). |
(defstring LABEL "text") | Emits word-aligned NUL-terminated packed little-endian 4-char/word DTP-FIXNUM words (used by Boot PROM console routines). |
(def-ivory-string LABEL "text") | Emits an authentic uncompressed Ivory 8-bit DTP-STRING object (DTP-HEADER-I #x50000000 | len followed by packed LE DTP-FIXNUM words — passable directly to IFEP FORMAT). |
(ret-tos) / (ret-fixnum N) | Emits (return-single :tos) (preceded by (push-fixnum N) for ret-fixnum). |
(gvar-get ADDR) | Raw-reads Zone 31 global at ADDR onto TOS (push-locative + memory-read (imm #x2C0)). |
(gvar-store ADDR val-forms...) | Pushes locative ADDR, evaluates val-forms..., and executes (memory-write (sp-pop)). |
call-void / call-val Argument Counting: call-void and call-val pass (length arg-forms) as the argument count N to finish-call-n. Whenever an argument requires more than one instruction (for example computing tid + 7), emit (call-compiled-even fn) ... (finish-call-n :value|:effect N) explicitly instead of nesting multi-instruction expressions inside call-void / call-val.
5. Binary Container Formats (src/formats/)
| Format Keyword | Container Spec | Key Implementation Details |
|---|---|---|
:raw-words | Raw 5-byte LE Ivory words | Data<7:0>, Data<15:8>, Data<23:16>, Data<31:24>, (CDR<<6)|DTP |
:ifep-prom | IFEP prom<ver> (J/H/E) | 30-byte header ("IFEP prom" + ver + 5×u32), checksummed (vma, nwords, 5B words, u32 byte-sum) sections, (entry_vma, 0xFFFFFFFF) footer, plus 64 KiB 115988/115989 split/join |
:ifep-fep | Disk-resident .fep kernel | 1,280-byte pages (64 × 20-byte tag-first chunks: 4 tag bytes + 4 u32 LE payload words), Page 0 3-word descriptors (target_vma, spec, source), inline patches, and 32-bit ones-complement end-around-carry checksum (w[5]) |
:ifep-flod | IFEP overlayH v1 dynamic overlay | "IFEP overlayH" header, 64-bit Kernel Build UID (5c3931aef3e75a93 for IFEP 328), command directory (name, doc, resolved :entry VMA), and checksummed overlay sections (typically 0xF8001100+) |
:ibin-fasl | #xF013 QFASL / IBIN compiled Lisp | Opcode-level QFASL/IBIN parser, inspect summary, and 0-diff round-trip serializer |
6. Verification & Test Suites
Run the full multi-CL and cross-implementation test matrix from tools/ivasm/Makefile:
# Run individual CL runtime suites (9/9 unit tests each)
make -C tools/ivasm test-sbcl
make -C tools/ivasm test-ecl
make -C tools/ivasm test-clisp
# 304-case C (emu/src/ivory_disasm.c) <-> CL syntax & encoding cross-check
make -C emu tests-build
make -C tools/ivasm test-golden-c
# Byte-exact 0-diff round-trip checks against local user-supplied PROM/.fep/.flod/.ibin media
make -C tools/ivasm test-real-media
# Run all 5 gates in sequence
make -C tools/ivasm test-all
test-sbcl/test-ecl/test-clisp: verifies 40-bit word encoding, halfword packing, CDR-Jump, fullword calls, branch fixups, macro expansion,:ifep-prom/:ifep-fep/:ifep-flod/:ibin-faslcontainers, and FrameThrower skeleton backends with zero SBCL warnings.test-golden-c: executesemu/build/test_disasm --emit-goldento export 304 representative Ivory instructions in canonical Lisp S-expression form and confirmstools/ivasm/reassembles every single one back to the exact original 40-bit word.test-real-media: automatically skips absent git-ignored media and verifies 0-byte-diff round-trips on any locally present Boot PROM dumps,.fepkernels,.flodoverlays, and.ibinfiles.