The Pedigree Project  0.1
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
MIPS32VirtualAddressSpace Class Reference

#include <VirtualAddressSpace.h>

+ Inheritance diagram for MIPS32VirtualAddressSpace:
+ Collaboration diagram for MIPS32VirtualAddressSpace:

Public Member Functions

virtual bool isAddressValid (void *virtualAddress)
 
virtual bool isMapped (void *virtualAddress)
 
virtual bool map (physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)
 
virtual void getMapping (void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)
 
virtual void setFlags (void *virtualAddress, size_t newFlags)
 
virtual void unmap (void *virtualAddress)
 
virtual void * allocateStack ()
 
virtual void freeStack (void *pStack)
 
uintptr_t getPageTableChunk (uintptr_t chunkIdx)
 
- Public Member Functions inherited from VirtualAddressSpace
virtual void * expandHeap (ssize_t incr, size_t flags)
 
virtual bool mapHuge (physical_uintptr_t physAddress, void *virtualAddress, size_t count, size_t flags)
 
virtual StackallocateStack (size_t stackSz)
 
virtual void freeStack (Stack *pStack)=0
 
virtual VirtualAddressSpaceclone (bool copyOnWrite=true)=0
 
virtual void revertToKernelAddressSpace ()=0
 
virtual ~VirtualAddressSpace ()
 
void setHeap (void *heap, void *heapEnd)
 
virtual bool memIsInKernelHeap (void *pMem)=0
 
virtual bool memIsInHeap (void *pMem)=0
 
virtual void * getEndOfHeap ()=0
 
virtual uintptr_t getKernelStart () const =0
 
virtual uintptr_t getUserStart () const =0
 
virtual uintptr_t getUserReservedStart () const =0
 
virtual uintptr_t getDynamicLinkerAddress () const =0
 
virtual uintptr_t getKernelHeapStart () const =0
 
virtual uintptr_t getKernelHeapEnd () const =0
 
virtual uintptr_t getKernelCacheStart () const =0
 
virtual uintptr_t getKernelCacheEnd () const =0
 
virtual uintptr_t getKernelEventBlockStart () const =0
 
virtual uintptr_t getKernelModulesStart () const =0
 
virtual uintptr_t getKernelModulesEnd () const =0
 
virtual uintptr_t getDynamicStart () const
 
virtual uintptr_t getDynamicEnd () const
 
virtual uintptr_t getGlobalInfoBlock () const
 

Protected Member Functions

virtual ~MIPS32VirtualAddressSpace ()
 
- Protected Member Functions inherited from VirtualAddressSpace
 VirtualAddressSpace (void *Heap)
 

Private Member Functions

 MIPS32VirtualAddressSpace ()
 
 MIPS32VirtualAddressSpace (const MIPS32VirtualAddressSpace &)
 
MIPS32VirtualAddressSpaceoperator= (const MIPS32VirtualAddressSpace &)
 
void setPageTableChunk (uintptr_t chunkIdx, uintptr_t chunkAddr)
 
uintptr_t generateNullChunk ()
 

Private Attributes

uintptr_t m_pKusegDirectory [1024]
 

Static Private Attributes

static uintptr_t m_pKseg2Directory [512]
 
static MIPS32VirtualAddressSpace m_KernelSpace
 

Friends

class Processor
 
VirtualAddressSpaceVirtualAddressSpace::getKernelAddressSpace ()
 

Additional Inherited Members

- Static Public Member Functions inherited from VirtualAddressSpace
static EXPORTED_PUBLIC VirtualAddressSpacegetKernelAddressSpace ()
 
static VirtualAddressSpacecreate ()
 
- Public Attributes inherited from VirtualAddressSpace
void * m_Heap
 
void * m_HeapEnd
 
- Static Public Attributes inherited from VirtualAddressSpace
static const size_t KernelMode = 0x01
 
static const size_t Write = 0x02
 
static const size_t Execute = 0x04
 
static const size_t WriteThrough = 0x08
 
static const size_t CacheDisable = 0x10
 
static const size_t CopyOnWrite = 0x20
 
static const size_t Swapped = 0x40
 
static const size_t MemoryCoherent = 0x80
 
static const size_t Guarded = 0x100
 
static const size_t Shared = 0x200
 
static const size_t WriteCombine = 0x400
 
static const size_t Accessed = 0x800
 
static const size_t Dirty = 0x1000
 
static const size_t ClearDirty = 0x2000
 
static physical_uintptr_t m_ZeroPage = 0
 

Detailed Description

The X86VirtualAddressSpace implements the VirtualAddressSpace class for the mip32 processor, which means it encompasses paging (KUSEG) and KSEG0, KSEG1, KSEG2.

Virtual addressing on MIPS is a little complex. There are two paged areas - KUSEG and KSEG2. The former is intended for user applications and is located in the lower 2GB of the address space. The latter is intended for kernel use and is located in the highest 1GB of the address space. It is normal practice to store the current page table in KSEG2, so that a full 2MB of physical RAM doesn't have to be assigned per address space. However, this causes problems, as the MIPS TLB is rather small and it is possible that an entry for the page table doesn't exist, so a TLB refill will fault.

In this case, the CPU will double fault and enter our 'normal' exception entry point. The exception handler must fix up the TLB so that the piece of page table being accessed by the TLB refill handler is present. The CPU will then return to its original faulting instruction, fault again, but this time the TLB refill handler will be able to take care of the miss.

We consider the page table as a set of 4KB chunks. It is important to note that because the R4000 is in essence a 64-bit CPU, the design of the 'standard' page table is that each entry is 64 bits long. This gives us more bits to play with (in the 32-bit version), but doubles the size of the page table.

So the page table covers 4GB / 4KB = 1M pages, each entry being 2 words in size (64-bits) = 2M words.

But to map the page table into KSEG2, we split the page table down again into 4KB chunks, which means we have 2M / 1K (1K being 4KB / 4bytes per word) = 2048 words.

Here however, we have a problem. VirtualAddressSpace objects are part of Process objects, which are stored on the kernel heap (which is in KSEG2). So in order to fix up the page table which maps KSEG2, we need to do a lookup... in KSEG2!

Obviously this wouldn't work, so we set the page table entr(ies) containing this VirtualAddressSpace as a permanent (or 'wired') TLB entry. That way we can be certain that it will always be present.

One further optimisation is that while the KUSEG mappings will be different through each address space, the KSEG2 mappings will all be the same - we want the kernel heap to look the same from every address space! Thus, we can split our page table 'directory' into two chunks - the KUSEG chunk and the KSEG2 chunk (which will be static across all VirtualAddressSpace objects). This has the added advantage that we can get rid of mappings for the 1GB of KSEG0 and KSEG1 mappings in between KUSEG and KSEG2, as these areas aren't paged.

So that's 1024 words to map KUSEG, and 512 words to map KSEG2.

Definition at line 96 of file kernel/core/processor/mips32/VirtualAddressSpace.h.

Constructor & Destructor Documentation

MIPS32VirtualAddressSpace::~MIPS32VirtualAddressSpace ( )
protectedvirtual

The destructor does nothing

Definition at line 61 of file mips32/VirtualAddressSpace.cc.

References PhysicalMemoryManager::freePage(), PhysicalMemoryManager::instance(), and m_pKusegDirectory.

MIPS32VirtualAddressSpace::MIPS32VirtualAddressSpace ( )
private

The constructor for already present paging structures

Definition at line 45 of file mips32/VirtualAddressSpace.cc.

References m_pKseg2Directory, and m_pKusegDirectory.

MIPS32VirtualAddressSpace::MIPS32VirtualAddressSpace ( const MIPS32VirtualAddressSpace )
private

The copy-constructor

Note
NOT implemented

Member Function Documentation

void * MIPS32VirtualAddressSpace::allocateStack ( )
virtual

Allocates a single stack for a thread. Will use the default kernel thread size.

Implements VirtualAddressSpace.

Definition at line 300 of file mips32/VirtualAddressSpace.cc.

References Dec, ERROR, Hex, m_pKseg2Directory, m_pKusegDirectory, and NOTICE.

uintptr_t MIPS32VirtualAddressSpace::generateNullChunk ( )
private

Obtains a new physical frame and generates 'null' entries throughout.

Definition at line 328 of file mips32/VirtualAddressSpace.cc.

References PhysicalMemoryManager::allocatePage(), PhysicalMemoryManager::instance(), PAGE_SIZE, and panic().

Referenced by map().

+ Here is the caller graph for this function:

void MIPS32VirtualAddressSpace::getMapping ( void *  virtualAddress,
physical_uintptr_t &  physicalAddress,
size_t &  flags 
)
virtual

Get the physical address and the flags associated with the specific virtual address.

Note
This function is only valid on memory that was mapped with VirtualAddressSpace::map() and that is still mapped or marked as swapped out.
Parameters
[in]virtualAddressthe address in the virtual address space
[out]flagsthe flags
[out]physicalAddressthe physical address

Implements VirtualAddressSpace.

Definition at line 220 of file mips32/VirtualAddressSpace.cc.

References getPageTableChunk(), and panic().

uintptr_t MIPS32VirtualAddressSpace::getPageTableChunk ( uintptr_t  chunkIdx)

Intended to be called solely by MIPS32TlbManager. Returns the physical address of the chunkIdx'th 4KB chunk of the page table.

Definition at line 283 of file mips32/VirtualAddressSpace.cc.

References Dec, ERROR, m_pKseg2Directory, and m_pKusegDirectory.

Referenced by getMapping(), MIPS32TlbManager::interrupt(), isMapped(), and map().

+ Here is the caller graph for this function:

bool MIPS32VirtualAddressSpace::isAddressValid ( void *  virtualAddress)
virtual

Is a particular virtual address valid?

Parameters
[in]virtualAddressthe virtual address to check
Returns
true, if the address is valid, false otherwise

Implements VirtualAddressSpace.

Definition at line 73 of file mips32/VirtualAddressSpace.cc.

bool MIPS32VirtualAddressSpace::isMapped ( void *  virtualAddress)
virtual

Checks whether a mapping the the specific virtual address exists. Pages marked as swapped out are not considered mapped.

Note
This function must be valid on all the valid addresses within the virtual address space.
Parameters
[in]virtualAddressthe virtual address
Returns
true, if a mapping exists, false otherwise

Implements VirtualAddressSpace.

Definition at line 79 of file mips32/VirtualAddressSpace.cc.

References getPageTableChunk(), and panic().

bool MIPS32VirtualAddressSpace::map ( physical_uintptr_t  physicalAddress,
void *  virtualAddress,
size_t  flags 
)
virtual

Map a specific physical page (of size PhysicalMemoryManager::getPageSize()) at a specific location into the virtual address space.

Note
This function must also work on pages marked as swapped out.
Parameters
[in]physicalAddressthe address of the physical page that should be mapped into the virtual address space.
[in]virtualAddressthe virtual address at which the page apears within the virtual address space.
[in]flagsflags that describe which accesses should be allowed on the page.
Returns
true, if successfull, false otherwise
Todo:
When is an entry global? In KSEG2? But the page table TLB entries are ASID specific... hmm.

Implements VirtualAddressSpace.

Definition at line 120 of file mips32/VirtualAddressSpace.cc.

References VirtualAddressSpace::CacheDisable, generateNullChunk(), getPageTableChunk(), Hex, panic(), physicalAddress(), WARNING, and VirtualAddressSpace::Write.

MIPS32VirtualAddressSpace& MIPS32VirtualAddressSpace::operator= ( const MIPS32VirtualAddressSpace )
private

The copy-constructor

Note
Not implemented
void MIPS32VirtualAddressSpace::setFlags ( void *  virtualAddress,
size_t  newFlags 
)
virtual

Set the flags of the page at a specific virtual address.

Note
The page must have been mapped with VirtualAddressSpace::map() and the page must still be mapped or marked as swapped out.
Parameters
[in]virtualAddressthe virtual address
[in]newFlagsthe flags

Implements VirtualAddressSpace.

Definition at line 275 of file mips32/VirtualAddressSpace.cc.

void MIPS32VirtualAddressSpace::unmap ( void *  virtualAddress)
virtual

Remove the page at the specific virtual address from the virtual address space.

Note
This function is only valid on memory that was mapped with VirtualAddressSpace::map() and that is still mapped or marked as swapped out.
Parameters
[in]virtualAddressthe virtual address

Implements VirtualAddressSpace.

Definition at line 279 of file mips32/VirtualAddressSpace.cc.

Friends And Related Function Documentation

friend class Processor
friend

Processor::switchAddressSpace() needs access to m_PhysicalPageDirectory

Definition at line 100 of file kernel/core/processor/mips32/VirtualAddressSpace.h.

Member Data Documentation

MIPS32VirtualAddressSpace MIPS32VirtualAddressSpace::m_KernelSpace
staticprivate

The kernel virtual address space

Definition at line 150 of file kernel/core/processor/mips32/VirtualAddressSpace.h.

uintptr_t MIPS32VirtualAddressSpace::m_pKseg2Directory
staticprivate

Our 'directory' for KSEG2. Shared across all address spaces.

Definition at line 147 of file kernel/core/processor/mips32/VirtualAddressSpace.h.

Referenced by allocateStack(), getPageTableChunk(), and MIPS32VirtualAddressSpace().

uintptr_t MIPS32VirtualAddressSpace::m_pKusegDirectory[1024]
private

Our 'directory' - contains the physical address of each page table 'chunk' for KUSEG.

Definition at line 145 of file kernel/core/processor/mips32/VirtualAddressSpace.h.

Referenced by allocateStack(), getPageTableChunk(), MIPS32VirtualAddressSpace(), and ~MIPS32VirtualAddressSpace().


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