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.mdfor overall sequencing,docs/emulator/core-and-acceleration.mdfor the already 4-GW-readyIvoryDcache, anddocs/hardware-reference/03-virtual-memory-paging-and-gc.mdfor 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:
- Eager Allocation (
calloc):ivory_mem_init()eagerly zeroes and commits allram_words * 8bytes upfront (64 MW immediately consumes 512 MiB RSS; 256 MW consumes 2 GiB even when mostly untouched). - Zone-31 Boot PROM Overlap Risk: Unmapped Zone 31 maps
VMA 0xF8000000..0xFFFFFFFF→PMA 0x00000000..0x07FFFFFF, wherePMA 0x07FE0000..0x07FEFFFFis the Wired Boot Comm Area & Boot PROM (IVORY_BOOT_PROM_BASE_PMA) and0x08000000is the Intel 82C54 PIT. Contiguous main-board RAM must stop cleanly at0x07FDFFFF(127.875 MW=2,046quanta) so it never collides with Boot PROM or PIT MMIO. - Missing Merlin-II Expansion Memory Boards (
0x10000000,0x20000000,0x30000000): Pergenera-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):
| Board | Physical Address Aperture | Max Capacity | ECO Register Nibble (0x0A000008) |
|---|---|---|---|
| Merlin Main Board | 0x00000000 .. 0x07FDFFFF | 127.875 MW (2,046 quanta) | <3:0> %%merlin-eco-register-main (!= 0xF) |
| Merlin Memory Board #0 | 0x10000000 .. 0x1FFFFFFF | 256 MW (4,096 quanta) | <7:4> %%merlin-eco-register-memory-0 (!= 0xF when present) |
| Merlin Memory Board #1 | 0x20000000 .. 0x2FFFFFFF | 256 MW (4,096 quanta) | <11:8> %%merlin-eco-register-memory-1 (!= 0xF when present) |
| Merlin Memory Board #2 | 0x30000000 .. 0x3FFFFFFF | 256 MW (4,096 quanta) | <15:12> %%merlin-eco-register-memory-2 (!= 0xF when present) |
| Combined Merlin-II Max | 4 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. IvoryMemSlot Carving: Carve 1uint64_tslot fromIvoryMem::_reserved[937]→_reserved[936]forstruct IvoryMemBanks *banks;(heap-allocated 4-bank descriptor owned byivory_mem_init/ivory_mem_destroy).- 64-Bit Host Offset Safety: Every host pointer offset
bank->base + (size_t)offset_wordsMUST cast indices tosize_tso banks>= 512 MW(>= 4 GiBbyte offset) never truncate under LP64 (Linux) or LLP64 (Windows x64). - Zero Static Globals: All bank state lives inside
IvoryMemBanks(heap-owned perIvoryMem), keepingemu/build/obj/core/*.oat0writable.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 < mem->ram_words"| B0
PMA -->|"0x1000_0000 <= pma < 0x4000_0000"| EXP
PMA -->|"Otherwise"| MMIO3. Phase-by-Phase Technical Design
Phase 1: Sparse Host Reservation & Zone-31 Ceiling Enforcement (emu/include/emu_os.h, emu/src/mem.c)
- 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 coldpower-resetimmediately 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) andVirtualAlloc(..., MEM_RESET, ...)/ re-reserve on cold reset.
- POSIX:
- Hard Zone-31 Contiguous Cap:
- Clamp Bank 0 (
mem->ram_words) strictly toIVORY_MERLIN_MAX_MAIN_RAM_WORDS = 0x07FE0000U(127.875 MW). - Any requested
--ram-mwabove127 MWkeeps Bank 0 at127.875 MW(leaving0x07FE0000..0x07FEFFFFBoot Comm/PROM and0x08000000PIT 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.
- Clamp Bank 0 (
Phase 2: Merlin-II Expansion Memory Boards 0–2 (0x10000000..0x3FFFFFFF)
IvoryMemBanksDescriptor: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;- 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-checkoff < bank[idx].word_count. Unpopulated slots returnIVORY_ERR_BUS_FAULTso IFEP's physical memory prober sizes each board accurately and writes the exact(start-ppn, n-pages)pairs intosys:main-memory-map! ivory_mem_note_ram_write_pma()marks bothbank[idx].dirty_bitmapand invalidatesIvoryDcachevia the full 24-bitppn = pma >> 8(already supported byivory_dcache_set_idx()!).- Map-Cache (
mc->host_page) caches direct pointers tobank[idx].words + page_off, so once translated via PHT, Zone 0–30 accesses to expansion RAM run at full native speed.
- Bank 0 (
- 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 (0x1when populated,0xFwhen absent) unless overridden by:eco, so Genera's(si:find-merlin-boards)accurately reports eachMerlin Memory Board #0..#2and its size!
- Update
Phase 3: Multi-Region .snap Persistence, COW Checkpoints & UI Presets
- Sparse
.snapv2 (emu/src/snapshot.c):- Maintain backward compatibility loading
.snapv1 (ram_wordsBank 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!).
- Maintain backward compatibility loading
- COW Checkpoints (
IvoryCheckpointStore):- Track dirty-page bitmaps per populated bank (
bank_id << 24 | page_idxhash key) using the existing__builtin_ctzllclean-page skip loop.
- Track dirty-page bitmaps per populated bank (
- CLI, Config &
Machine SetupUI:- Allow
--ram-mw/:ram-mwup to895(preserving valid presets8,16,32,64,127,256,512MW inMachine Setup→Firmware & Memory), displaying the automatic bank split (e.g.256 MW = 127.875 MW Main + 128.125 MW Mem0).
- Allow
4. Verification & Acceptance Criteria
| Phase | Automated Tests | End-to-End Verification |
|---|---|---|
| Phase 1: Sparse Backing & Zone-31 Cap | emu/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–2 | test_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 & UI | test_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
| File | Action | Purpose |
|---|---|---|
emu/include/emu_os.h | Edit | Portable emu_sparse_alloc / emu_sparse_free / emu_sparse_zero (POSIX mmap + Win32 VirtualAlloc) |
emu/include/ivory_emu.h, emu/include/ivory_hw.h | Edit | IvoryMemBanks *banks in IvoryMem::_reserved[937], IVORY_MERLIN_MAX_MAIN_RAM_WORDS |
emu/src/mem.c, emu/src/merlin.c | Edit | Multi-bank PMA routing (0x10000000..0x3FFFFFFF), PHT/dcache coherence, ECO nibble synthesis |
emu/src/snapshot.c, emu/src/bug_report.c | Edit | Multi-bank COW dirty bitmaps, sparse .snap v2 sections, bank summary in report.txt |
emu/src/main.c, emu/src/ui_workbench.c | Edit | --ram-mw up to 895, Machine Setup RAM presets & bank split readout |
emu/tests/test_mem.c, test_merlin.c, test_snapshot_reload.c | Edit | Multi-bank memory, ECO probe, and multi-region .snap/COW tests |
- Intel 82C54 —
intel_82C54_pit.pdf