FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
ARM64Paging Class Reference

ARM64 virtual memory implementation. More...

#include <ARM64Paging.h>

Inheritance diagram for ARM64Paging:
MemoryContext

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

ARM64FirstTablem_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 MemoryContextgetCurrent ()
 Get currently active MemoryContext.
 
- Protected Attributes inherited from MemoryContext
SplitAllocatorm_alloc
 Physical memory allocator.
 
MemoryMapm_map
 Virtual memory layout.
 
Callback< MemoryContext, Addressm_mapRangeSparseCallback
 Callback object for mapRangeSparseCallback function.
 
Memory::Rangem_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 MemoryContextm_current = 0
 The currently active MemoryContext.
 

Detailed Description

ARM64 virtual memory implementation.

Definition at line 50 of file ARM64Paging.h.

Constructor & Destructor Documentation

◆ ARM64Paging() [1/2]

ARM64Paging::ARM64Paging ( MemoryMap map,
SplitAllocator alloc 
)

Constructor.

Parameters
mapVirtual memory map.
allocAllocator pointer of the physical memory page allocations.

Definition at line 28 of file ARM64Paging.cpp.

◆ ARM64Paging() [2/2]

ARM64Paging::ARM64Paging ( MemoryMap map,
Address  firstTableAddress,
Address  kernelBaseAddress 
)

Secondary constructor with pre-allocated 1st page table.

Parameters
mapVirtual memory map
firstTableAddressPhysical address of 1st page table
kernelBaseAddressPhysical base address of the kernel

Definition at line 45 of file ARM64Paging.cpp.

◆ ~ARM64Paging()

ARM64Paging::~ARM64Paging ( )
virtual

Destructor.

Definition at line 36 of file ARM64Paging.cpp.

References MemoryContext::m_alloc, m_firstTableAddr, PAGESIZE, and SplitAllocator::release().

Member Function Documentation

◆ access()

MemoryContext::Result ARM64Paging::access ( Address  virt,
Memory::Access access 
) const
virtual

Get Access flags for a virtual address.

Parameters
virtVirtual address to get Access flags for.
accessMemoryAccess object pointer.
Returns
Result code.

Implements MemoryContext.

Definition at line 240 of file ARM64Paging.cpp.

References access(), ARM64FirstTable::access(), MemoryContext::m_alloc, and m_firstTable.

Referenced by access().

◆ activate()

MemoryContext::Result ARM64Paging::activate ( bool  initializeMMU = false)
virtual

Activate the MemoryContext.

This function applies this MemoryContext on the hardware MMU.

Parameters
initializeMMUIf true perform (re)initialization of the MMU
Returns
Result code.

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().

◆ allocPageTable()

MemoryContext::Result ARM64Paging::allocPageTable ( Allocator::Range phys,
Allocator::Range virt 
)
private

◆ enableMMU()

MemoryContext::Result ARM64Paging::enableMMU ( )
private

◆ initialize()

MemoryContext::Result ARM64Paging::initialize ( )
virtual

◆ lookup()

MemoryContext::Result ARM64Paging::lookup ( Address  virt,
Address phys 
) const
virtual

Translate virtual address to physical address.

Parameters
virtVirtual address to lookup on input
physContains the physical address on output.
Returns
Result code

Implements MemoryContext.

Definition at line 235 of file ARM64Paging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::translate().

◆ map()

MemoryContext::Result ARM64Paging::map ( Address  virt,
Address  phys,
Memory::Access  access 
)
virtual

Map a physical page to a virtual address.

Parameters
virtVirtual address.
physPhysical address.
accessMemory access flags.
Returns
Result code

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.

◆ releaseRange()

MemoryContext::Result ARM64Paging::releaseRange ( Memory::Range range)
virtual

Release range of memory.

Parameters
rangeMemory range input
Returns
Result code.

Implements MemoryContext.

Definition at line 251 of file ARM64Paging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::releaseRange().

◆ releaseSection()

MemoryContext::Result ARM64Paging::releaseSection ( const Memory::Range range,
const bool  tablesOnly = false 
)
virtual

Release memory sections.

Deallocate all associated physical memory which resides in the given memory section range.

Parameters
rangeRange of memory sections to release
tablesOnlyTrue to only release associated page tables and do not release the actual mapped pages
Returns
Result code

Implements MemoryContext.

Definition at line 245 of file ARM64Paging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARM64FirstTable::releaseSection().

◆ setupPageTable()

void ARM64Paging::setupPageTable ( MemoryMap map,
Address  firstTableAddress,
Address  kernelBaseAddress 
)
private

Installs default mappings on 1st level page table.

Parameters
mapVirtual memory map
firstTableAddressPhysical address of 1st level page table
kernelBaseAddressPhysical address of the kernel base

◆ unmap()

MemoryContext::Result ARM64Paging::unmap ( Address  virt)
virtual

Unmap a virtual address.

This function removes a virtual to physical memory mapping without deallocating any physical memory.

Parameters
virtVirtual address to unmap.
Returns
Result code

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().

Field Documentation

◆ m_firstTable

ARM64FirstTable* ARM64Paging::m_firstTable
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().

◆ m_firstTableAddr

Address ARM64Paging::m_firstTableAddr
private

Physical address of the first level page table.

Definition at line 187 of file ARM64Paging.h.

Referenced by activate(), enableMMU(), initialize(), and ~ARM64Paging().

◆ m_kernelBaseAddr

Address ARM64Paging::m_kernelBaseAddr
private

Kernel base address.

Definition at line 190 of file ARM64Paging.h.

Referenced by initialize().


The documentation for this class was generated from the following files: