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 standaloneIVPVIdle Yield Device) anddocs/color-graphics-plan.md(Univision UDC-3400 & Symbolics FrameThrower). Seedocs/ROADMAP.mdfor 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:
- One canonical
VmeDeviceOpsdevice registry supporting up toVME_MAX_DEVICES = 8plugged cards simultaneously with non-overlapping A32/A24 byte-address apertures. - Both Merlin-II VMEbus access paths:
- Polled VMEbus (
0x88000040..0x88000140): used bysys: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 bysys:make-bus-address/sys:make-bus-arrayfor low-latency MMIO and bulk framebuffer transfers with all 4 Merlin-II shuffle modes (:none,:byte,:nibble,:bit).
- Polled VMEbus (
- 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-IIvme_hp(<3>) /vme_lp(<2>) with authentic IACK vector readback. - Unified
IVORY_CORE_ABI_VERSION = 5Uand 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 & 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_FB2. 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) == 4096Usizeof(IvoryMem) == 32768Usizeof(MerlinBoard) == 278528U
MerlinBoardslot carving (emu/include/ivory_emu.h):- Carve 2
uint64_tslots fromMerlinBoard::_reserved[1054]→_reserved[1052]:struct VmeBus *vme;(opaque heap-allocated bus container owned bymerlin_init/merlin_destroy;NULLwhen no VME cards are attached or in minimal unit tests).uint32_t pv_idle_yield_us; uint32_t _vme_pad;(inline hot-path flag checked atL_outer_reloadincpu.cwith zero extra pointer dereference whenIVPVidle yield is active).
- Carve 2
- Zero writable
.data/.bssinemu/build/obj/core/*.o(verified viareadelf -WS). - Zero OS/SDL headers inside
vme_bus.cor any VME device file compiled intoCORE_SRCS. Host callbacks (display scanout, RPC doorbell, host monotonic clock) are wired frommain.cthroughIvoryCoreApiv5. - Hot-reload & snapshot safety: Never store DSO-internal function pointers inside
MerlinBoard;VmeBusrebuilds itsconst VmeDeviceOps *pointers onvme_bus_rebind_ops()after adlopen/LoadLibraryAreload (keyed by integerVmeCardKindenum +core_cookie, identical toIvoryDcache).
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 withIVORY_ERR_INVALID_ARG.- Unmapped reads/writes return
false→vme_buslatchesVME_BERR(0x20) in VIC068BESR!
3.2 Polled VMEbus Access (genera-original/sys.sct/i-sys/vme-bus.lisp:521-577)
| Merlin-II PMA | Register | Behavior |
|---|---|---|
0x88000040 | merlin-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-register | Latches 32-bit VME data with shuffle mode (0=none, 1=byte-swap, 2=nibble-swap, 3=bit-reverse) |
0x880000C0 | merlin-ii-vme-polled-write-request-register | Initiates VME write to byte address val using latched data, SIZ, and VIC AMOD |
0x88000100 | merlin-ii-vme-polled-read-request-register | If 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 |
0x88000140 | merlin-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 AMOD | vic-amod-source | 6-bit VME Address Modifier (0x09 = A32 non-privileged data, 0x0D = A32 supervisory, 0x39 = A24) |
VIC BESR | vic-bus-error-status-register | Bit <5> (0x20) = VME_BERR latched on unmapped probe; cleared when guest writes 0 |
Critical Probing & Vector Contracts:
find-univision-controllers,ft::probe-system-slots, andpv-probe-board-pprobe VME slots insidecondition-case. Unpopulated addresses must latchBESR.VME_BERR(0x20) so Genera signalsvme-bus-errorrather than misdetecting empty slots as hardware.- Vector
0x5Fis reserved by Genera (interrupts.lisp:1332) for the Solstice slave trigger;vme_busrejects card registration or vector writes selecting0x5F.
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 (00none,0132-bit byte-swap,10nibble-swap,11bit-reverse pervme-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 >= 0xC0000000inemu/src/mem.cdirectly tovme_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)ORsops->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-IIMERLIN_IRQ_MII_VME_HIGH(bit 3) andMERLIN_IRQ_MII_VME_LOW(bit 2) insidemerlin_refresh_irq_cache().- During
IACK(IA = 0),vme_busqueries registered cards claiming the requested IRQ level (1..7) in slot order and latches the winning card's 8-bit vector intopolled_data.
4. Disjoint VME A32 Slot Map
| VME A32 Base | Size | Card | Default IRQ / Vector | Reference Plan |
|---|---|---|---|---|
0x1000_0000 | 1 KiB | IVPV (Idle / Mouse / RPC) | IRQ 4 / 0x60 | docs/genera-pv.md |
0x1400_0000 | 32 MiB | IVFB (Optional Separate Linear Color Card) | — | docs/genera-pv.md (Low Priority) |
0x9000_0000 | 16 MiB | Univision UDC-3400 | VBLANK IRQ (configurable) | docs/color-graphics-plan.md |
Probed (probe.ibin) | Board-defined | Symbolics FrameThrower (Photon + AVP) | VSYNC IRQ | docs/color-graphics-plan.md |
5. Phased Implementation & Verification Gates
| Phase | Deliverables | Verification & Gate Criteria |
|---|---|---|
| Phase 1: Core Bus & Shuffle Engine | New 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 Hooks | Bump 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
| File | Action | Purpose |
|---|---|---|
emu/include/ivory_hw.h | Edit | Merlin-II VME polled/direct/VIC068 register offsets & shuffle constants |
emu/include/ivory_emu.h | Edit | VmeBus *vme + pv_idle_yield_us in MerlinBoard::_reserved, VmeDeviceOps, VmeDisplayInfo |
emu/include/ivory_core_api.h | Edit | Bump IVORY_CORE_ABI_VERSION to 5U, expose VME attach/query/scanout table entries |
emu/src/vme_bus.c | New | Shared VMEbus registry, polled/direct routing, 4 shuffle modes, BERR, IRQ/IACK |
emu/src/merlin.c, mem.c, core_api.c, core_loader.c | Edit | Wire VMEbus into Merlin-II MMIO, PMA >= 0xC0000000, ABI v5 validation |
emu/src/debug_ctl.c, snapshot.c | Edit | vme-list inspection command and extensible SNAP_CHUNK_VME hook |
emu/tests/test_vme_bus.c, emu/Makefile | New / Edit | Dedicated VMEbus unit test suite |
- VTC / Cypress VIC068A —
cypress_VIC068A_VAC068A_users_guide.pdf(mirror)