mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-11 07:36:57 +00:00
arm64/mem: Add MMU layer for GVA->GPA translation
A new function, mmu_gva_to_gpa(), will be the sole entry point for resolving guest virtual addresses. This initial implementation models the processor's state on reset. The function inspects the M bit from the emulated SCTLR_EL1 register. If the bit is clear, address mapping (GVA = GPA) is performed. This is an architecturally-mandated behavior required for the Arm guest to execute its initiall boot code before enabling virtual memory. Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
parent
a62aa833c0
commit
43bcf7e9a7
2 changed files with 52 additions and 0 deletions
16
core/arm64/mmu.cpp
Normal file
16
core/arm64/mmu.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include "mmu.h"
|
||||
|
||||
namespace pound::arm64::memory
|
||||
{
|
||||
int mmu_gva_to_gpa(pound::arm64::vcpu_state_t* vcpu, uint64_t gva, uint64_t* out_gpa)
|
||||
{
|
||||
const uint8_t SCTLR_EL1_M_BIT = (1 << 0);
|
||||
if (0 == (vcpu->sctlr_el1 & SCTLR_EL1_M_BIT))
|
||||
{
|
||||
*out_gpa = gva;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
} // namespace pound::arm64::memory
|
||||
36
core/arm64/mmu.h
Normal file
36
core/arm64/mmu.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
namespace pound::arn64::memory
|
||||
{
|
||||
/*
|
||||
* mmu_gva_to_gpa() - Translate a Guest Virtual Address to a Guest Physical Address.
|
||||
* @vcpu: A pointer to the vCPU state.
|
||||
* @gva: The Guest Virtual Address to translate.
|
||||
* @out_gpa: A pointer to a uint64_t where the resulting Guest Physical Address
|
||||
* will be stored on success.
|
||||
*
|
||||
* This function is the primary entry point for the emulated AArch64 Stage 1
|
||||
* MMU. It is responsible for resolving a virtual address used by the guest
|
||||
* into a physical address within the guest's physical address space.
|
||||
*
|
||||
* The translation behavior is dependent on the state of the emulated MMU,
|
||||
* primarily controlled by the SCTLR_EL1.M bit (MMU enable).
|
||||
*
|
||||
* If the MMU is disabled, this function performs an identity mapping, where
|
||||
* the GPA is identical to the GVA. This correctly models the processor's
|
||||
* behavior on reset and is the initial "stub" implementation.
|
||||
*
|
||||
* If the MMU is enabled, this function will perform a full, multi-level page
|
||||
* table walk, starting from the base address in TTBR0_EL1 or TTBR1_EL1. It
|
||||
* will parse translation table descriptors, check for permissions, and handle
|
||||
* different page sizes as configured in TCR_EL1.
|
||||
*
|
||||
* A failed translation will result in a fault. The caller is responsible for
|
||||
* checking the return value and initiating a synchronous exception if a fault
|
||||
* occurs. The contents of @out_gpa are undefined on failure.
|
||||
*
|
||||
* Return: 0 on successful translation. A negative error code on a translation
|
||||
* fault (e.g., for a page fault, permission error, or alignment fault).
|
||||
*/
|
||||
int mmu_gva_to_gpa(vcpu_state_t* vcpu, uint64_t gva, uint64_t* out_gpa);
|
||||
} // namespace pound::arn64::memory
|
||||
Loading…
Add table
Add a link
Reference in a new issue