|
FreeNOS
|
ARM64 virtual memory implementation. More...
#include <ARM64Paging.h>
Public Member Functions | |
| ARM64Paging (MemoryMap *map, SplitAllocator *alloc) | |
| Constructor. | |
| ARM64Paging (MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress) | |
| Secondary constructor with pre-allocated 1st page table. | |
| virtual | ~ARM64Paging () |
| Destructor. | |
| virtual Result | initialize () |
| Initialize the MemoryContext. | |
| virtual Result | activate (bool initializeMMU=false) |
| Activate the MemoryContext. | |
| virtual Result | map (Address virt, Address phys, Memory::Access access) |
| Map a physical page to a virtual address. | |
| virtual Result | unmap (Address virt) |
| Unmap a virtual address. | |
| virtual Result | lookup (Address virt, Address *phys) const |
| Translate virtual address to physical address. | |
| virtual Result | access (Address virt, Memory::Access *access) const |
| Get Access flags for a virtual address. | |
| virtual Result | releaseSection (const Memory::Range &range, const bool tablesOnly=false) |
| Release memory sections. | |
| virtual Result | releaseRange (Memory::Range *range) |
| Release range of memory. | |
Public Member Functions inherited from MemoryContext | |
| MemoryContext (MemoryMap *map, SplitAllocator *alloc) | |
| Constructor. | |
| virtual | ~MemoryContext () |
| Destructor. | |
| virtual Result | mapRangeContiguous (Memory::Range *range) |
| Map a range of contiguous physical pages to virtual addresses. | |
| virtual Result | mapRangeSparse (Memory::Range *range) |
| Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses. | |
| virtual Result | unmapRange (Memory::Range *range) |
| Unmaps a range of virtual memory. | |
| virtual Result | release (Address virt) |
| Release a memory page mapping. | |
| virtual Result | findFree (Size size, MemoryMap::Region region, Address *virt) const |
| Find unused memory. | |
| virtual void | mapRangeSparseCallback (Address *phys) |
| Callback to provide intermediate Range object during mapRangeSparse() | |
Private Member Functions | |
| void | setupPageTable (MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress) |
| Installs default mappings on 1st level page table. | |
| MemoryContext::Result | allocPageTable (Allocator::Range &phys, Allocator::Range &virt) |
| Result | enableMMU () |
| Enable the MMU. | |
Private Attributes | |
| ARM64FirstTable * | m_firstTable |
| Pointer to the first level page table. | |
| Address | m_firstTableAddr |
| Physical address of the first level page table. | |
| Address | m_kernelBaseAddr |
| Kernel base address. | |
Additional Inherited Members | |
Public Types inherited from MemoryContext | |
| enum | Result { Success , InvalidAddress , InvalidSize , AlreadyExists , OutOfMemory , InvalidArgs } |
| Result codes. More... | |
| typedef enum MemoryContext::Result | Result |
| Result codes. | |
Static Public Member Functions inherited from MemoryContext | |
| static MemoryContext * | getCurrent () |
| Get currently active MemoryContext. | |
Protected Attributes inherited from MemoryContext | |
| SplitAllocator * | m_alloc |
| Physical memory allocator. | |
| MemoryMap * | m_map |
| Virtual memory layout. | |
| Callback< MemoryContext, Address > | m_mapRangeSparseCallback |
| Callback object for mapRangeSparseCallback function. | |
| Memory::Range * | m_savedRange |
| Saved range input for use in the mapRangeSparse Callback. | |
| Size | m_numSparsePages |
| Number of pages allocated via mapRangeSparse Callback. | |
Static Protected Attributes inherited from MemoryContext | |
| static MemoryContext * | m_current = 0 |
| The currently active MemoryContext. | |
ARM64 virtual memory implementation.
Definition at line 50 of file ARM64Paging.h.
| ARM64Paging::ARM64Paging | ( | MemoryMap * | map, |
| SplitAllocator * | alloc | ||
| ) |
Constructor.
| map | Virtual memory map. |
| alloc | Allocator pointer of the physical memory page allocations. |
Definition at line 28 of file ARM64Paging.cpp.
Secondary constructor with pre-allocated 1st page table.
| map | Virtual memory map |
| firstTableAddress | Physical address of 1st page table |
| kernelBaseAddress | Physical base address of the kernel |
Definition at line 45 of file ARM64Paging.cpp.
|
virtual |
Destructor.
Definition at line 36 of file ARM64Paging.cpp.
References MemoryContext::m_alloc, m_firstTableAddr, PAGESIZE, and SplitAllocator::release().
|
virtual |
Get Access flags for a virtual address.
| virt | Virtual address to get Access flags for. |
| access | MemoryAccess object pointer. |
Implements MemoryContext.
Definition at line 240 of file ARM64Paging.cpp.
References access(), ARM64FirstTable::access(), MemoryContext::m_alloc, and m_firstTable.
Referenced by access().
|
virtual |
Activate the MemoryContext.
This function applies this MemoryContext on the hardware MMU.
| initializeMMU | If true perform (re)initialization of the MMU |
Implements MemoryContext.
Definition at line 182 of file ARM64Paging.cpp.
References dsb, enableMMU(), isb, MemoryContext::m_current, m_firstTableAddr, MemoryContext::Success, ARM64Control::TranslationTable0, and ARM64Control::write().
Referenced by kernel_main().
|
private |
Definition at line 55 of file ARM64Paging.cpp.
References Allocator::Range::address, Allocator::Range::alignment, SplitAllocator::allocate(), MemoryContext::m_alloc, MemoryContext::OutOfMemory, PAGESIZE, Allocator::Range::size, Allocator::Success, and MemoryContext::Success.
Referenced by initialize().
|
private |
Enable the MMU.
Definition at line 119 of file ARM64Paging.cpp.
References SystemControlFlags::AlignCheckEnabled, dsb, SystemControlFlags::E0E, SystemControlFlags::EE, SystemControlFlags::InstrCache, MemoryContext::InvalidArgs, isb, m_firstTableAddr, MAIR_FIELD, MEM_ATTR_DEV, MEM_ATTR_NC, MEM_ATTR_NORMAL, ARM64Control::MemoryAttrIndirection, ARM64Control::MemoryModelFeature, SystemControlFlags::MMUEnabled, PA_RANGE, ARM64Control::read(), SystemControlFlags::SA, SystemControlFlags::SA0, SystemControlFlags::Stage1Cache, MemoryContext::Success, ARM64Control::SystemControl, TGRAN4, ARM64Control::TranslationTable0, ARM64Control::TranslationTableCtrl, ARM64Control::write(), and SystemControlFlags::WXN.
Referenced by activate().
|
virtual |
Initialize the MemoryContext.
Implements MemoryContext.
Definition at line 70 of file ARM64Paging.cpp.
References Memory::Range::access, Allocator::Range::address, allocPageTable(), Memory::Device, ARM64FirstTable::initialize(), MemoryMap::KernelData, MemoryContext::m_alloc, m_firstTable, m_firstTableAddr, m_kernelBaseAddr, MemoryContext::m_map, ARM64FirstTable::mapLarge(), MegaByte, MemoryContext::OutOfMemory, Memory::Range::phys, MemoryMap::range(), Memory::Readable, MemoryBlock::set(), Memory::Range::size, MemoryContext::Success, ARM64FirstTable::unmap(), Memory::Range::virt, and Memory::Writable.
Referenced by kernel_main().
|
virtual |
Translate virtual address to physical address.
| virt | Virtual address to lookup on input |
| phys | Contains the physical address on output. |
Implements MemoryContext.
Definition at line 235 of file ARM64Paging.cpp.
References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::translate().
|
virtual |
Map a physical page to a virtual address.
| virt | Virtual address. |
| phys | Physical address. |
| access | Memory access flags. |
Implements MemoryContext.
Definition at line 210 of file ARM64Paging.cpp.
References isb, MemoryContext::m_alloc, MemoryContext::m_current, m_firstTable, ARM64FirstTable::map(), and tlb_invalidate.
|
virtual |
Release range of memory.
| range | Memory range input |
Implements MemoryContext.
Definition at line 251 of file ARM64Paging.cpp.
References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::releaseRange().
|
virtual |
Release memory sections.
Deallocate all associated physical memory which resides in the given memory section range.
| range | Range of memory sections to release |
| tablesOnly | True to only release associated page tables and do not release the actual mapped pages |
Implements MemoryContext.
Definition at line 245 of file ARM64Paging.cpp.
References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::releaseSection().
|
private |
Installs default mappings on 1st level page table.
| map | Virtual memory map |
| firstTableAddress | Physical address of 1st level page table |
| kernelBaseAddress | Physical address of the kernel base |
|
virtual |
Unmap a virtual address.
This function removes a virtual to physical memory mapping without deallocating any physical memory.
| virt | Virtual address to unmap. |
Implements MemoryContext.
Definition at line 224 of file ARM64Paging.cpp.
References isb, MemoryContext::m_alloc, MemoryContext::m_current, m_firstTable, tlb_invalidate, and ARM64FirstTable::unmap().
|
private |
Pointer to the first level page table.
Definition at line 184 of file ARM64Paging.h.
Referenced by access(), initialize(), lookup(), map(), releaseRange(), releaseSection(), and unmap().
|
private |
Physical address of the first level page table.
Definition at line 187 of file ARM64Paging.h.
Referenced by activate(), enableMMU(), initialize(), and ~ARM64Paging().
|
private |