FreeNOS
Public Member Functions | Private Attributes
IntelPaging Class Reference

Intel virtual memory implementation. More...

#include <IntelPaging.h>

Inheritance diagram for IntelPaging:
MemoryContext

Public Member Functions

 IntelPaging (MemoryMap *map, SplitAllocator *alloc)
 Constructor. More...
 
 IntelPaging (MemoryMap *map, Address pageDirectory, SplitAllocator *alloc)
 Constructor. More...
 
virtual ~IntelPaging ()
 Destructor. More...
 
virtual Result initialize ()
 Initialize the MemoryContext. More...
 
virtual Result activate (bool initializeMMU=false)
 Activate the MemoryContext. More...
 
virtual Result map (Address virt, Address phys, Memory::Access access)
 Map a physical page to a virtual address. More...
 
virtual Result unmap (Address virt)
 Unmap a virtual address. More...
 
virtual Result lookup (Address virt, Address *phys) const
 Translate virtual address to physical address. More...
 
virtual Result access (Address virt, Memory::Access *access) const
 Get Access flags for a virtual address. More...
 
virtual Result releaseSection (const Memory::Range &range, const bool tablesOnly=false)
 Release memory sections. More...
 
virtual Result releaseRange (Memory::Range *range)
 Release range of memory. More...
 
- Public Member Functions inherited from MemoryContext
 MemoryContext (MemoryMap *map, SplitAllocator *alloc)
 Constructor. More...
 
virtual ~MemoryContext ()
 Destructor. More...
 
virtual Result mapRangeContiguous (Memory::Range *range)
 Map a range of contiguous physical pages to virtual addresses. More...
 
virtual Result mapRangeSparse (Memory::Range *range)
 Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses. More...
 
virtual Result unmapRange (Memory::Range *range)
 Unmaps a range of virtual memory. More...
 
virtual Result release (Address virt)
 Release a memory page mapping. More...
 
virtual Result findFree (Size size, MemoryMap::Region region, Address *virt) const
 Find unused memory. More...
 
virtual void mapRangeSparseCallback (Address *phys)
 Callback to provide intermediate Range object during mapRangeSparse() More...
 

Private Attributes

IntelPageDirectorym_pageDirectory
 Pointer to page directory in kernel's virtual memory. More...
 
Address m_pageDirectoryAddr
 Physical address of the page directory. More...
 
bool m_pageDirectoryAllocated
 Set to true if page directory was allocated by this class. More...
 

Additional Inherited Members

- Public Types inherited from MemoryContext
enum  Result {
  Success, InvalidAddress, InvalidSize, AlreadyExists,
  OutOfMemory
}
 Result codes. More...
 
typedef enum MemoryContext::Result Result
 Result codes. More...
 
- Static Public Member Functions inherited from MemoryContext
static MemoryContextgetCurrent ()
 Get currently active MemoryContext. More...
 
- Protected Attributes inherited from MemoryContext
SplitAllocatorm_alloc
 Physical memory allocator. More...
 
MemoryMapm_map
 Virtual memory layout. More...
 
Callback< MemoryContext, Addressm_mapRangeSparseCallback
 Callback object for mapRangeSparseCallback function. More...
 
Memory::Rangem_savedRange
 Saved range input for use in the mapRangeSparse Callback. More...
 
Size m_numSparsePages
 Number of pages allocated via mapRangeSparse Callback. More...
 
- Static Protected Attributes inherited from MemoryContext
static MemoryContextm_current = 0
 The currently active MemoryContext. More...
 

Detailed Description

Intel virtual memory implementation.

Definition at line 43 of file IntelPaging.h.

Constructor & Destructor Documentation

◆ IntelPaging() [1/2]

IntelPaging::IntelPaging ( MemoryMap map,
SplitAllocator alloc 
)

Constructor.

Allocates new page tables for the paged memory context.

Parameters
mapVirtual memory map.
allocAllocator for physical memory page allocations.

Definition at line 23 of file IntelPaging.cpp.

◆ IntelPaging() [2/2]

IntelPaging::IntelPaging ( MemoryMap map,
Address  pageDirectory,
SplitAllocator alloc 
)

Constructor.

Assign the given page directory to this paged memory context. This constructor does not allocate new page tables.

Parameters
mapVirtual memory map.
pageDirectoryPhysical address of the page directory to use.
allocAllocator for physical memory page allocations.

Definition at line 31 of file IntelPaging.cpp.

◆ ~IntelPaging()

IntelPaging::~IntelPaging ( )
virtual

Member Function Documentation

◆ access()

MemoryContext::Result IntelPaging::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 130 of file IntelPaging.cpp.

References IntelPageDirectory::access(), MemoryContext::m_alloc, and m_pageDirectory.

◆ activate()

MemoryContext::Result IntelPaging::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 95 of file IntelPaging.cpp.

References MemoryContext::m_current, m_pageDirectoryAddr, MemoryContext::Success, and IntelCore::writeCR3().

Referenced by IntelKernel::IntelKernel().

◆ initialize()

MemoryContext::Result IntelPaging::initialize ( )
virtual

◆ lookup()

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

Translate virtual address to physical address.

Parameters
virtVirtual address to lookup
physTranslated physical memory address on output
Returns
Result code

Implements MemoryContext.

Definition at line 125 of file IntelPaging.cpp.

References MemoryContext::m_alloc, m_pageDirectory, and IntelPageDirectory::translate().

◆ map()

MemoryContext::Result IntelPaging::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 103 of file IntelPaging.cpp.

References MemoryContext::m_alloc, MemoryContext::m_current, m_pageDirectory, IntelPageDirectory::map(), MemoryContext::Success, and tlb_flush.

◆ releaseRange()

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

Release range of memory.

Parameters
rangeMemory range input
Returns
Result code.

Implements MemoryContext.

Definition at line 141 of file IntelPaging.cpp.

References MemoryContext::m_alloc, m_pageDirectory, and IntelPageDirectory::releaseRange().

◆ releaseSection()

MemoryContext::Result IntelPaging::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 135 of file IntelPaging.cpp.

References MemoryContext::m_alloc, m_pageDirectory, and IntelPageDirectory::releaseSection().

◆ unmap()

MemoryContext::Result IntelPaging::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 114 of file IntelPaging.cpp.

References MemoryContext::m_alloc, MemoryContext::m_current, m_pageDirectory, MemoryContext::Success, tlb_flush, and IntelPageDirectory::unmap().

Field Documentation

◆ m_pageDirectory

IntelPageDirectory* IntelPaging::m_pageDirectory
private

Pointer to page directory in kernel's virtual memory.

Definition at line 162 of file IntelPaging.h.

Referenced by access(), initialize(), lookup(), map(), releaseRange(), releaseSection(), and unmap().

◆ m_pageDirectoryAddr

Address IntelPaging::m_pageDirectoryAddr
private

Physical address of the page directory.

Definition at line 165 of file IntelPaging.h.

Referenced by activate(), initialize(), and ~IntelPaging().

◆ m_pageDirectoryAllocated

bool IntelPaging::m_pageDirectoryAllocated
private

Set to true if page directory was allocated by this class.

Definition at line 168 of file IntelPaging.h.

Referenced by initialize(), and ~IntelPaging().


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