XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsTODO docs/memory-expansion-plan.md

Memory Expansion Plan: Sparse RAM Backing & Merlin-II Expansion Memory Boards (> 8 MW → 127.875 MW / 895.875 MW)

Status: Future / Proposed Design Plan (Tier 1, Priority #4) — Not yet implemented. See docs/ROADMAP.md for overall sequencing, docs/emulator/core-and-acceleration.md for the already 4-GW-ready IvoryDcache, and docs/hardware-reference/03-virtual-memory-paging-and-gc.md for PHT/Zone 31 rules.

Target Emulator: C11 XL1200 Emulator (emu/)
Reference Sources (local-only developer assets): genera-original/sys.sct/i-sys/{configuration.lisp,io-register-definitions.lisp,sysdef.lisp,sysdf1.lisp}, emu/src/mem.c, emu/src/merlin.c, emu/src/snapshot.c


1. Executive Summary & Authentic Hardware Model

The default XL1200 configuration boots with 8 MW (0x00000000..0x007FFFFF, 64 MiB of host IvoryWords). While Machine Setup already exposes 8 / 16 / 32 / 64 MW presets and IvoryDcache (emu/src/cpu_decode.c) already uses an O(1) 1 KiB 24-bit PPN tag directory capable of scaling up to 4 GigaWords, three concrete gaps currently limit large-memory operation in emu/src/mem.c and emu/src/merlin.c:

  1. Eager Allocation (calloc): ivory_mem_init() eagerly zeroes and commits all ram_words * 8 bytes upfront (64 MW immediately consumes 512 MiB RSS; 256 MW consumes 2 GiB even when mostly untouched).
  2. Zone-31 Boot PROM Overlap Risk: Unmapped Zone 31 maps VMA 0xF8000000..0xFFFFFFFF → PMA 0x00000000..0x07FFFFFF, where PMA 0x07FE0000..0x07FEFFFF is the Wired Boot Comm Area & Boot PROM (IVORY_BOOT_PROM_BASE_PMA) and 0x08000000 is the Intel 82C54 PIT. Contiguous main-board RAM must stop cleanly at 0x07FDFFFF (127.875 MW = 2,046 quanta) so it never collides with Boot PROM or PIT MMIO.
  3. Missing Merlin-II Expansion Memory Boards (0x10000000, 0x20000000, 0x30000000): Per genera-original/sys.sct/i-sys/configuration.lisp:195-232 (find-merlin-boards), Merlin-II supports up to three dedicated expansion memory boards probed via ECO register (PMA 0x0A000008, MERLIN_VME_TIMEOUT_PMA):
BoardPhysical Address ApertureMax CapacityECO Register Nibble (0x0A000008)
Merlin Main Board0x00000000 .. 0x07FDFFFF127.875 MW (2,046 quanta)<3:0> %%merlin-eco-register-main (!= 0xF)
Merlin Memory Board #00x10000000 .. 0x1FFFFFFF256 MW (4,096 quanta)<7:4> %%merlin-eco-register-memory-0 (!= 0xF when present)
Merlin Memory Board #10x20000000 .. 0x2FFFFFFF256 MW (4,096 quanta)<11:8> %%merlin-eco-register-memory-1 (!= 0xF when present)
Merlin Memory Board #20x30000000 .. 0x3FFFFFFF256 MW (4,096 quanta)<15:12> %%merlin-eco-register-memory-2 (!= 0xF when present)
Combined Merlin-II Max4 disjoint banks below IO_BOARD0 (0x40000000)895.875 MW (~7.0 GiB virtual)Automatically synthesized from --ram-mw

2. Core ABI & Hot-Reload Invariants

  • Frozen Struct Sizes Preserved: sizeof(IvoryCpu) == 4096U, sizeof(IvoryMem) == 32768U, sizeof(MerlinBoard) == 278528U.
  • IvoryMem Slot Carving: Carve 1 uint64_t slot from IvoryMem::_reserved[937] → _reserved[936] for struct IvoryMemBanks *banks; (heap-allocated 4-bank descriptor owned by ivory_mem_init / ivory_mem_destroy).
  • 64-Bit Host Offset Safety: Every host pointer offset bank->base + (size_t)offset_words MUST cast indices to size_t so banks >= 512 MW (>= 4 GiB byte offset) never truncate under LP64 (Linux) or LLP64 (Windows x64).
  • Zero Static Globals: All bank state lives inside IvoryMemBanks (heap-owned per IvoryMem), keeping emu/build/obj/core/*.o at 0 writable .data/.bss.
flowchart TD
    PMA["32-bit Ivory PMA<br/>(from Zone 31, PHT, or DTP-PHYSICAL-ADDRESS)"]
    B0["Bank 0: Main Board<br/>0x0000_0000 .. min(main_words, 0x07FE_0000)<br/>Fast Path: mem->ram[pma]"]
    EXP["Banks 1..3: Expansion Boards 0..2<br/>slot = (pma >> 28) - 1 (for 0x1000..0x3FFF)<br/>Sparse mmap / VirtualAlloc"]
    MMIO["Boot PROM (0x07FE_0000) / PIT / NVRAM / IO0 / VRAM / VME"]

    PMA -->|"pma &lt; mem->ram_words"| B0
    PMA -->|"0x1000_0000 &lt;= pma &lt; 0x4000_0000"| EXP
    PMA -->|"Otherwise"| MMIO

3. Phase-by-Phase Technical Design

Phase 1: Sparse Host Reservation & Zone-31 Ceiling Enforcement (emu/include/emu_os.h, emu/src/mem.c)

  1. Portable Sparse Zero-Memory Allocator (emu_os.h):
    • POSIX: emu_sparse_alloc(size_t bytes) → mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0); emu_sparse_zero() → madvise(MADV_DONTNEED) on reset so cold power-reset immediately returns untouched pages to the OS!
    • Windows (_WIN32): VirtualAlloc(NULL, bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) (Windows commits anonymous zero pages lazily on first fault without consuming physical RAM until touched) and VirtualAlloc(..., MEM_RESET, ...) / re-reserve on cold reset.
  2. Hard Zone-31 Contiguous Cap:
    • Clamp Bank 0 (mem->ram_words) strictly to IVORY_MERLIN_MAX_MAIN_RAM_WORDS = 0x07FE0000U (127.875 MW).
    • Any requested --ram-mw above 127 MW keeps Bank 0 at 127.875 MW (leaving 0x07FE0000..0x07FEFFFF Boot Comm/PROM and 0x08000000 PIT completely intact) and spills the remainder into Expansion Boards 0–2!
    • Keep mem->ram[pma] as the zero-overhead Bank 0 fast path (pma < mem->ram_words) so Tier 0 / Tier 2 (cpu_zen4_loop.S) 8–127 MW performance has 0% regression.

Phase 2: Merlin-II Expansion Memory Boards 0–2 (0x10000000..0x3FFFFFFF)

  1. IvoryMemBanks Descriptor:
    typedef struct IvoryMemBank {
        uint32_t   base_pma;        /* 0x00000000, 0x10000000, 0x20000000, 0x30000000 */
        uint32_t   word_count;      /* 0 if unpopulated; <= 0x07FE0000 (b0) or 0x10000000 */
        IvoryWord *words;           /* Sparse host backing */
        uint64_t  *dirty_bitmap;    /* 1 bit per 256-word page (for COW & .snap) */
        uint32_t   dirty_bm_words;
    } IvoryMemBank;
    
    typedef struct IvoryMemBanks {
        IvoryMemBank bank[4];       /* 0=Main, 1=Mem0, 2=Mem1, 3=Mem2 */
        uint64_t     total_words;
    } IvoryMemBanks;
    
  2. Routing in mem.c (ivory_mem_raw_read_pma, ivory_mem_raw_write_pma, ivory_mem_peek_pma, ivory_mem_resolve_pma_page):
    • Bank 0 (pma < mem->ram_words): existing fast path unchanged.
    • Expansion banks (pma >= 0x10000000U && pma < 0x40000000U): uint32_t idx = pma >> 28; (1..3), uint32_t off = pma & 0x0FFFFFFFU;, bounds-check off < bank[idx].word_count. Unpopulated slots return IVORY_ERR_BUS_FAULT so IFEP's physical memory prober sizes each board accurately and writes the exact (start-ppn, n-pages) pairs into sys:main-memory-map!
    • ivory_mem_note_ram_write_pma() marks both bank[idx].dirty_bitmap and invalidates IvoryDcache via the full 24-bit ppn = pma >> 8 (already supported by ivory_dcache_set_idx()!).
    • Map-Cache (mc->host_page) caches direct pointers to bank[idx].words + page_off, so once translated via PHT, Zone 0–30 accesses to expansion RAM run at full native speed.
  3. Automatic ECO Nibble Synthesis (emu/src/merlin.c):
    • Update MERLIN_VME_TIMEOUT_PMA (0x0A000008) ECO nibbles <7:4>, <11:8>, <15:12> automatically based on populated expansion banks (0x1 when populated, 0xF when absent) unless overridden by :eco, so Genera's (si:find-merlin-boards) accurately reports each Merlin Memory Board #0..#2 and its size!

Phase 3: Multi-Region .snap Persistence, COW Checkpoints & UI Presets

  • Sparse .snap v2 (emu/src/snapshot.c):
    • Maintain backward compatibility loading .snap v1 (ram_words Bank 0 only).
    • Write Bank 1–3 sparse non-zero 256-word pages in tagged sections (only non-zero touched pages are serialized, so a 256 MW machine with 20 MW active still produces a tiny .snap!).
  • COW Checkpoints (IvoryCheckpointStore):
    • Track dirty-page bitmaps per populated bank (bank_id << 24 | page_idx hash key) using the existing __builtin_ctzll clean-page skip loop.
  • CLI, Config & Machine Setup UI:
    • Allow --ram-mw / :ram-mw up to 895 (preserving valid presets 8, 16, 32, 64, 127, 256, 512 MW in Machine Setup → Firmware & Memory), displaying the automatic bank split (e.g. 256 MW = 127.875 MW Main + 128.125 MW Mem0).

4. Verification & Acceptance Criteria

PhaseAutomated TestsEnd-to-End Verification
Phase 1: Sparse Backing & Zone-31 Capemu/tests/test_mem.c: verify 128 MW request caps Bank 0 at 0x07FE0000, leaving Boot PROM (0x07FE0000) & PIT (0x08000000) fault-free; verify sparse allocation does not spike RSS.Boot genuine fep330/rom.dump with --ram-mw 64 and --ram-mw 127; verify clean FEP> prompt and power-reset.
Phase 2: Expansion Boards 0–2test_mem.c: verify read/write/PHT translation/Map-Cache/watchpoints/IvoryDcache invalidation across 0x10000000, 0x20000000, 0x30000000, and IVORY_ERR_BUS_FAULT on unpopulated slots; test_merlin.c: verify ECO nibbles <15:4>.Boot genuine Genera 8.3 with --ram-mw 256; evaluate (si:find-merlin-boards) and (room) to confirm Genera discovers Merlin Memory Board #0 and reports the full expanded physical memory pool.
Phase 3: .snap, COW & UItest_snapshot_reload.c: verify sparse .snap save/load + COW checkpoint rewind with data in both Bank 0 and Bank 1 (0x10000000+), plus .snap v1 backward-compatibility check.Linux (make -C emu all test) + Windows MinGW-w64/Wine (test-win) pass 100%; sizeof(IvoryMem) == 32768U and readelf -WS 0 .data/.bss verified.

5. File Impact Summary

FileActionPurpose
emu/include/emu_os.hEditPortable emu_sparse_alloc / emu_sparse_free / emu_sparse_zero (POSIX mmap + Win32 VirtualAlloc)
emu/include/ivory_emu.h, emu/include/ivory_hw.hEditIvoryMemBanks *banks in IvoryMem::_reserved[937], IVORY_MERLIN_MAX_MAIN_RAM_WORDS
emu/src/mem.c, emu/src/merlin.cEditMulti-bank PMA routing (0x10000000..0x3FFFFFFF), PHT/dcache coherence, ECO nibble synthesis
emu/src/snapshot.c, emu/src/bug_report.cEditMulti-bank COW dirty bitmaps, sparse .snap v2 sections, bank summary in report.txt
emu/src/main.c, emu/src/ui_workbench.cEdit--ram-mw up to 895, Machine Setup RAM presets & bank split readout
emu/tests/test_mem.c, test_merlin.c, test_snapshot_reload.cEditMulti-bank memory, ECO probe, and multi-region .snap/COW tests
Related Chip Datasheets (1)All Component Datasheets →