XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsTODO docs/vme-bus-plan.md

Merlin-II VMEbus & VIC068 Bridge Plan (vme_bus.c)

Status: Future / Proposed Design Plan (Tier 1.5 Foundation) — Not yet implemented. Shared hardware-bus prerequisite for docs/genera-pv.md (starting with the standalone IVPV Idle Yield Device) and docs/color-graphics-plan.md (Univision UDC-3400 & Symbolics FrameThrower). See docs/ROADMAP.md for overall sequencing.

Target Emulator: C11 XL1200 Emulator (emu/)
Reference Sources (local-only developer assets): genera-original/sys.sct/i-sys/{vme-defs.lisp,vme-bus.lisp,interrupts.lisp,io-register-definitions.lisp}, docs/hardware-reference/04-merlin-ii-core-and-vmebus.md


1. Executive Summary & Goals

Currently, emu/src/merlin.c backs VIC068 and VMEbus control registers (0x80000000, 0x88000000, 0x8FF80000) with a passive uint32_t vic068[0x100] array and routes no VMEbus transactions. Every expansion card on the XL1200 — whether authentic hardware (Univision UDC-3400, Symbolics FrameThrower) or paravirtual (IVPV idle/mouse/RPC, optional separate IVFB linear color card) — relies on the exact same Merlin-II VMEbus master/interrupt plumbing.

Extracting the VMEbus bridge into its own module (emu/src/vme_bus.c) and plan delivers:

  1. One canonical VmeDeviceOps device registry supporting up to VME_MAX_DEVICES = 8 plugged cards simultaneously with non-overlapping A32/A24 byte-address apertures.
  2. Both Merlin-II VMEbus access paths:
    • Polled VMEbus (0x88000040..0x88000140): used by sys:bus-read / sys:bus-write, tv:vme-read-32, board probing (find-univision-controllers, ft::probe-system-slots, pv-probe-board-p), and VME Interrupt Acknowledge (IACK, IA = 0).
    • Direct VMEbus Master Window (PMA 0xC0000000..0xFFFFFFFF): used by sys:make-bus-address / sys:make-bus-array for low-latency MMIO and bulk framebuffer transfers with all 4 Merlin-II shuffle modes (:none, :byte, :nibble, :bit).
  3. Authentic VIC068 VME-BERR & IRQ1–7 routing: Unpopulated slot probes latch vic-bus-error-status.VME-BERR (#x20) instead of returning silent zeros, and VME IRQ lines route cleanly to Merlin-II vme_hp (<3>) / vme_lp (<2>) with authentic IACK vector readback.
  4. Unified IVORY_CORE_ABI_VERSION = 5U and strict preservation of all frozen hot-reload struct sizes.
flowchart LR
    subgraph Core["libivory_core.so / .dll (Pure ISO C11)"]
        MEM["mem.c<br/>PMA 0xC0000000..0xFFFFFFFF<br/>(Direct VME Window)"]
        MERLIN["merlin.c<br/>PMA 0x80000000..0x8FF800FF<br/>(Polled VME &amp; VIC068)"]
        VME["vme_bus.c<br/>VmeBus Registry (up to 8 cards)<br/>Shuffle Engine, BERR, IRQ1..7, IACK"]
        C_PV["vme_ivpv.c<br/>IVPV (0x1000_0000)"]
        C_UNI["vme_univision.c<br/>UDC-3400 (0x9000_0000)"]
        C_FT["vme_framethrower.c<br/>FrameThrower (probed)"]
        C_FB["vme_ivfb.c (Optional)<br/>Linear Color (0x1400_0000)"]
    end

    MEM -->|"Direct A32/A24 + Shuffle"| VME
    MERLIN -->|"Polled R/W + IACK + VIC068"| VME
    VME -->|"vme_hp / vme_lp IRQ"| MERLIN
    VME --> C_PV
    VME --> C_UNI
    VME --> C_FT
    VME --> C_FB

2. Core ABI v5 & Hot-Reload Invariants

All changes must preserve emu/AGENTS.md and .agents/rules/ivory-cpu-isa.md:

  • Frozen struct sizes:
    • sizeof(IvoryCpu) == 4096U
    • sizeof(IvoryMem) == 32768U
    • sizeof(MerlinBoard) == 278528U
  • MerlinBoard slot carving (emu/include/ivory_emu.h):
    • Carve 2 uint64_t slots from MerlinBoard::_reserved[1054] → _reserved[1052]:
      1. struct VmeBus *vme; (opaque heap-allocated bus container owned by merlin_init/merlin_destroy; NULL when no VME cards are attached or in minimal unit tests).
      2. uint32_t pv_idle_yield_us; uint32_t _vme_pad; (inline hot-path flag checked at L_outer_reload in cpu.c with zero extra pointer dereference when IVPV idle yield is active).
  • Zero writable .data/.bss in emu/build/obj/core/*.o (verified via readelf -WS).
  • Zero OS/SDL headers inside vme_bus.c or any VME device file compiled into CORE_SRCS. Host callbacks (display scanout, RPC doorbell, host monotonic clock) are wired from main.c through IvoryCoreApi v5.
  • Hot-reload & snapshot safety: Never store DSO-internal function pointers inside MerlinBoard; VmeBus rebuilds its const VmeDeviceOps * pointers on vme_bus_rebind_ops() after a dlopen/LoadLibraryA reload (keyed by integer VmeCardKind enum + core_cookie, identical to IvoryDcache).

3. Hardware & Register Specification

3.1 VmeDeviceOps & Device Registry (emu/src/vme_bus.c)

#define VME_MAX_DEVICES 8U

typedef enum VmeCardKind {
    VME_CARD_NONE         = 0,
    VME_CARD_IVPV         = 1, /* Paravirtual idle / mouse / RPC (docs/genera-pv.md) */
    VME_CARD_UNIVISION    = 2, /* Univision UDC-3400 (docs/color-graphics-plan.md) */
    VME_CARD_FRAMETHROWER = 3, /* Symbolics FrameThrower (docs/color-graphics-plan.md) */
    VME_CARD_IVFB         = 4  /* Optional separate linear color card (low priority) */
} VmeCardKind;

typedef struct VmeDisplayInfo {
    bool     active;
    uint32_t width;
    uint32_t height;
    uint32_t bpp;
    uint32_t dirty_seq;
    char     label[32];
} VmeDisplayInfo;

typedef struct VmeDeviceOps {
    VmeCardKind kind;
    const char *name;
    bool (*read)(void *ctx, uint32_t vme_addr, uint8_t size, uint8_t amod, uint32_t *out);
    bool (*write)(void *ctx, uint32_t vme_addr, uint8_t size, uint8_t amod, uint32_t val);
    void (*tick)(void *ctx, uint64_t delta_us);
    void (*reset)(void *ctx);
    void (*destroy)(void *ctx);
    /* Optional interrupt interface (VME IRQ levels 1..7) */
    uint8_t (*pending_irq_mask)(const void *ctx); /* bit (level-1) for IRQ1..7 */
    bool    (*ack_irq)(void *ctx, uint8_t level, uint8_t *out_vector);
    /* Optional display scanout for color cards */
    bool (*get_display_info)(const void *ctx, uint32_t head_idx, VmeDisplayInfo *out);
    bool (*render_rgba)(void *ctx, uint32_t head_idx, uint32_t *rgba_out, uint32_t max_pixels);
} VmeDeviceOps;
  • Each registered slot stores (VmeCardKind kind, uint32_t base_addr, uint32_t size_bytes, uint8_t addr_space_mask, void *ctx, const VmeDeviceOps *ops).
  • vme_bus_register() rejects overlapping byte ranges with IVORY_ERR_INVALID_ARG.
  • Unmapped reads/writes return false → vme_bus latches VME_BERR (0x20) in VIC068 BESR!

3.2 Polled VMEbus Access (genera-original/sys.sct/i-sys/vme-bus.lisp:521-577)

Merlin-II PMARegisterBehavior
0x88000040merlin-ii-vme-direct-am-register<1:0> = Direct window A32 <31:30>, <3:2> = ASIZ, <5:4> = FC
0x88000080 (+ shuffle <29:28>)merlin-ii-vme-polled-data-registerLatches 32-bit VME data with shuffle mode (0=none, 1=byte-swap, 2=nibble-swap, 3=bit-reverse)
0x880000C0merlin-ii-vme-polled-write-request-registerInitiates VME write to byte address val using latched data, SIZ, and VIC AMOD
0x88000100merlin-ii-vme-polled-read-request-registerIf IA = 1: initiates VME read at val and latches result into polled_data. If IA = 0: executes VME IACK cycle for IRQ level (val >> 1) & 7 and latches 8-bit vector into polled_data
0x88000140merlin-ii-vme-polled-am-register<15:14> = SIZ (0=4B, 1=1B, 2=2B, 3=3B), <13> = IA (1=data, 0=IACK), <12> = MWB
VIC AMODvic-amod-source6-bit VME Address Modifier (0x09 = A32 non-privileged data, 0x0D = A32 supervisory, 0x39 = A24)
VIC BESRvic-bus-error-status-registerBit <5> (0x20) = VME_BERR latched on unmapped probe; cleared when guest writes 0
IMPORTANT

Critical Probing & Vector Contracts:

  • find-univision-controllers, ft::probe-system-slots, and pv-probe-board-p probe VME slots inside condition-case. Unpopulated addresses must latch BESR.VME_BERR (0x20) so Genera signals vme-bus-error rather than misdetecting empty slots as hardware.
  • Vector 0x5F is reserved by Genera (interrupts.lisp:1332) for the Solstice slave trigger; vme_bus rejects card registration or vector writes selecting 0x5F.

3.3 Direct VMEbus Master Window (PMA 0xC0000000 .. 0xFFFFFFFF)

  • Bits <31:30> == 2'b11: Direct VME master aperture (genera-original/sys.sct/i-sys/vme-bus.lisp:314-343).
  • Bits <29:28>: Shuffle mode (00 none, 01 32-bit byte-swap, 10 nibble-swap, 11 bit-reverse per vme-defs.lisp:423-426).
  • Bits <27:0>: 28-bit longword offset within active 1 GiB window: vme_byte_addr = ((direct_am.addr & 0x3U) << 30) | ((pma & 0x0FFFFFFFU) << 2).
  • Route PMA >= 0xC0000000 in emu/src/mem.c directly to vme_bus_direct_read/write() so future framebuffer bulk copies bypass generic MMIO switch overhead.

3.4 VME Interrupt Aggregation & IACK

  • vme_bus_refresh_irqs(MerlinBoard *board) ORs ops->pending_irq_mask(ctx) across all registered devices, masks against VIC068 enable registers (enable-vic-vme-interrupt / disable-vic-vme-interrupt, vme-defs.lisp:463-470), and updates Merlin-II MERLIN_IRQ_MII_VME_HIGH (bit 3) and MERLIN_IRQ_MII_VME_LOW (bit 2) inside merlin_refresh_irq_cache().
  • During IACK (IA = 0), vme_bus queries registered cards claiming the requested IRQ level (1..7) in slot order and latches the winning card's 8-bit vector into polled_data.

4. Disjoint VME A32 Slot Map

VME A32 BaseSizeCardDefault IRQ / VectorReference Plan
0x1000_00001 KiBIVPV (Idle / Mouse / RPC)IRQ 4 / 0x60docs/genera-pv.md
0x1400_000032 MiBIVFB (Optional Separate Linear Color Card)—docs/genera-pv.md (Low Priority)
0x9000_000016 MiBUnivision UDC-3400VBLANK IRQ (configurable)docs/color-graphics-plan.md
Probed (probe.ibin)Board-definedSymbolics FrameThrower (Photon + AVP)VSYNC IRQdocs/color-graphics-plan.md

5. Phased Implementation & Verification Gates

PhaseDeliverablesVerification & Gate Criteria
Phase 1: Core Bus & Shuffle EngineNew emu/src/vme_bus.c + declarations in ivory_hw.h / ivory_emu.h; carve VmeBus *vme + pv_idle_yield_us from MerlinBoard::_reserved; route polled & direct VME in merlin.c and mem.c.New emu/tests/test_vme_bus.c: tests all 4 shuffle modes (:none/:byte/:nibble/:bit), sub-word 1/2/3/4-byte polled reads/writes, VME_BERR latching on unmapped probes, overlap rejection, IRQ1–7 → vme_hp/vme_lp + IACK vector readback, #x5F rejection.
Phase 2: Core ABI v5 & Snapshot/Reload HooksBump IVORY_CORE_ABI_VERSION to 5U in ivory_core_api.h + core_loader.c; add vme_bus_rebind_ops() reload hook + optional tagged SNAP_CHUNK_VME extensibility in snapshot.c; add vme-list command to debug_ctl.c.make -C emu clean all test test-e2e (Linux) + TARGET_OS=windows all dist-win test-win (Wine); readelf -WS emu/build/obj/core/*.o confirms 0 .data/.bss; test_snapshot_reload verifies hot-reload parity with an attached dummy VME card.

6. File Impact Summary

FileActionPurpose
emu/include/ivory_hw.hEditMerlin-II VME polled/direct/VIC068 register offsets & shuffle constants
emu/include/ivory_emu.hEditVmeBus *vme + pv_idle_yield_us in MerlinBoard::_reserved, VmeDeviceOps, VmeDisplayInfo
emu/include/ivory_core_api.hEditBump IVORY_CORE_ABI_VERSION to 5U, expose VME attach/query/scanout table entries
emu/src/vme_bus.cNewShared VMEbus registry, polled/direct routing, 4 shuffle modes, BERR, IRQ/IACK
emu/src/merlin.c, mem.c, core_api.c, core_loader.cEditWire VMEbus into Merlin-II MMIO, PMA >= 0xC0000000, ABI v5 validation
emu/src/debug_ctl.c, snapshot.cEditvme-list inspection command and extensible SNAP_CHUNK_VME hook
emu/tests/test_vme_bus.c, emu/MakefileNew / EditDedicated VMEbus unit test suite
Related Chip Datasheets (1)All Component Datasheets →