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>