5.6 SafeMemory - Physical RAM Backend

<< Click to Display Table of Contents >>

Navigation:  ASA-EMulatR Reference Guide > Introduction > Architecture Overview > Chapter 5 - Memory System Architecture >

5.6 SafeMemory - Physical RAM Backend

5.6.1 Role

 

SafeMemory implements actual physical RAM storage. It is the "dumb backend" — intentionally simple, with no architectural knowledge.

 

Characteristics: byte-addressable, bounds-checked, thread-safe, deterministic, no ordering semantics. SafeMemory does not perform translation, enforce barriers, track reservations, or understand CPUs.

 


 

5.6.2 Internal Layout

 

SafeMemory is discontinuous in PA space but contiguous internally. Two PA regions map into a single contiguous buffer:

 

SafeMemory offset 0x0000_0000 — PA range 0x0000_0000–0x0001_0000 — Low 64 KB (includes HWRPB at +0x2000)

SafeMemory offset 0x0001_0000 — PA range 0x8000_0000–0x8_8000_0000 — Main RAM (32 GB)

Total size: 64 KB + 32 GB = 0x8_0001_0000 bytes

 

The PA→offset translation is:

 

// Region 1: Low 64 KB (PA 0x0 - 0x10000) → offset = PA directly

// Region 2: Main RAM (PA 0x80000000 - 0x880000000)

// → offset = (pa - 0x80000000) + 0x00010000

 


 

5.6.3 Sparse Memory Backing

 

SafeMemory uses SparseMemoryBacking (SparseMemoryBacking.h, 507 lines) for on-demand page allocation. Physical pages are allocated only when first accessed via ensurePage(pageIdx), using atomic page pointers (std::atomic<quint8*>) for thread safety. This avoids pre-allocating the full 32 GB address space. The allocatedBytes() method reports actual memory consumption versus the total addressable range.

 


 

5.6.4 API

 

SafeMemory provides typed load/store methods at all standard widths (load8/store8 through load64/store64) plus a generic load(offset, size, &out) and store(offset, size, value). All methods return MEM_STATUS. getSpan(offset, requestedLen, intent) returns a MemorySpan for direct pointer access, truncated at 64 KB page boundaries.

 

Implementation: SafeMemory.h (253 lines) + SafeMemory.cpp.

 

Key design point: No AlphaMemorySystem — HWRPB lives in SafeMemory at PA 0x2000, written directly via GuestMemory spans during initialization. PAL is C++ code, not a memory region. This eliminates data duplication and synchronization issues.

 

See Also: memoryLib/SafeMemory.h; memoryLib/SparseMemoryBacking.h.