This commit introduces a proper abstraction layer for all read and write
operations.
The previous approach of directly calculating a Host Virtual Address
(HVA) from a Guest Physical Address (GPA) via gpa_to_hva() forces every
part of the emulator that touches guest memory to be aware of the
underlying host pointer, which is poor design.
This new layer introduces a suite of guest_mem_read{b,w,l,q} and
guest_mem_write{b,w,l,q} fuctions. All future memory accesses from the
emulated CPU should be performed through these functions.
The code has also been moved into the pound::aarch64 namespace for
better organization.
Signed-off-by: Ronald Caesar <github43132@proton.me>
In emulating guests with a simple, flat memory model, we frequently need
to translate a guest physical address (GPA) into a host virtual address
(HVA). This is a hot path operation that must be efficient as possible.
This commit introduces gpa_to_hva(), a static inline helper function
designed for this purpose. The implementation relies on the fundamental
pre-condition that the guest's physical RAM is backed by a single,
contiguous region of host virtual memory (typically acquired via mmap).
It treats the GPA not as a pointer but as a direct byte offset from the
base of this host mapping.
This approach is optimal for performance for two key reasons:
1. The translation is a single pointer-offset calculation, which
typically compiles to a single LEA intruction on x86-64.
2. It preserves memory access locality. When a guest performs
sequential accesses, the host's accesses are also sequential,
allowing the host CPU's hardware prefetcher to function effectively.
This helper provides the fast path for simple RAM accesses. More
complex address spaces involving discontiguous memory or MMIO regions
will require a slower, lookup-based translation mechanism. This
function is not intended for those cases.
Signed-off-by: Ronald Caesar <github43132@proton.me>
Introduce the basic data structures required to manage the architectural
state of an emulated ARMv8 guest. This is a foundational patch for a
forthcoming emulator framework.
The core of this change is the `vcpu_state_t` structure, which holds
the essential user-visible state of a single virtual CPU (vCPU),
including the general-purpose registers, stack pointer, program counter,
and PSTATE.
The state for all vCPUs is aligned to the CPU L1 cache line. This design
choice ensures that there is no false sharing between physical host
cores running separate vCPU emulation threads.
Signed-off-by: Ronald Caesar <github43132@proton.me>