finished the rework of vmmap.c etc.

This commit is contained in:
Eric J. Bowersox
2013-04-23 01:49:58 -06:00
parent 4c6b86ffbd
commit b23fd6b6e5
7 changed files with 644 additions and 232 deletions

View File

@@ -39,22 +39,52 @@
#include <comrogue/types.h>
#include <comrogue/compiler_macros.h>
#include <comrogue/internals/mmu.h>
#include <comrogue/internals/rbtree.h>
#include <comrogue/internals/startup.h>
/*------------------------------------------
* The COMROGUE memory management subsystem
*------------------------------------------
*/
/* Nodes in the page table tree. */
typedef struct tagPAGENODE {
RBTREENODE rbtn; /* RBT node containing physical address as key */
PPAGETAB ppt; /* pointer to page table */
} PAGENODE, *PPAGENODE;
/* Virtual memory context. */
typedef struct tagVMCTXT {
PTTB pTTB; /* pointer to the TTB */
PTTBAUX pTTBAux; /* pointer to the TTB auxiliary data */
UINT32 uiMaxIndex; /* max index into the above tables */
RBTREE rbtPageTables; /* tree containing page tables this context owns */
} VMCTXT, *PVMCTXT;
CDECL_BEGIN
/* Low-level maintenance functions */
extern void _MmFlushCacheForPage(KERNADDR vmaPage, BOOL bWriteback);
extern void _MmFlushCacheForSection(KERNADDR vmaSection, BOOL bWriteback);
extern void _MmFlushTLBForPage(KERNADDR vmaPage);
extern void _MmFlushTLBForPageAndContext(KERNADDR vmaPage, UINT32 uiASID);
extern void _MmFlushTLBForSection(KERNADDR vmaSection);
extern void _MmFlushTLBForSectionAndContext(KERNADDR vmaSection, UINT32 uiASID);
extern PTTB _MmGetTTB0(void);
extern void _MmSetTTB0(PTTB pTTB);
/* Kernel address space functions */
extern KERNADDR _MmAllocKernelAddr(UINT32 cpgNeeded);
extern void _MmFreeKernelAddr(KERNADDR kaBase, UINT32 cpgToFree);
/* Page mapping functions */
extern PHYSADDR MmGetPhysAddr(PTTB pTTB, KERNADDR vma);
extern HRESULT MmDemapPages(PTTB pTTB, PTTBAUX pTTBAux, KERNADDR vmaBase, UINT32 cpg);
extern HRESULT MmMapPages(PTTB pTTB, PTTBAUX pTTBAux, PHYSADDR paBase, KERNADDR vmaBase, UINT32 cpg,
extern PHYSADDR MmGetPhysAddr(PVMCTXT pvmctxt, KERNADDR vma);
extern HRESULT MmDemapPages(PVMCTXT pvmctxt, KERNADDR vmaBase, UINT32 cpg);
extern HRESULT MmMapPages(PVMCTXT pvmctxt, PHYSADDR paBase, KERNADDR vmaBase, UINT32 cpg,
UINT32 uiTableFlags, UINT32 uiPageFlags, UINT32 uiAuxFlags);
extern HRESULT MmMapKernelPages(PTTB pTTB, PTTBAUX pTTBAux, PHYSADDR paBase, UINT32 cpg, UINT32 uiTableFlags,
extern HRESULT MmMapKernelPages(PHYSADDR paBase, UINT32 cpg, UINT32 uiTableFlags,
UINT32 uiPageFlags, UINT32 uiAuxFlags, PKERNADDR pvmaLocation);
extern HRESULT MmDemapKernelPages(PTTB pTTB, PTTBAUX pTTBAux, KERNADDR vmaBase, UINT32 cpg);
extern HRESULT MmDemapKernelPages(KERNADDR vmaBase, UINT32 cpg);
/* Initialization functions only */
extern void _MmInit(PSTARTUP_INFO pstartup);

View File

@@ -103,6 +103,7 @@
/* TTB auxiliary descriptor bits */
#define TTBAUX_SACRED 0x00000001 /* sacred entry, do not deallocate */
#define TTBAUX_UNWRITEABLE 0x00000002 /* entry unwriteable */
/* Small page table entry bits */
#define PGTBLSM_XN 0x00000001 /* Execute-Never */
@@ -131,20 +132,21 @@
/* Page auxiliary descriptor bits */
#define PGAUX_SACRED 0x00000001 /* sacred entry, do not deallocate */
#define PGAUX_UNWRITEABLE 0x00000002 /* entry unwriteable */
/* Combinations of flags we use regularly. */
#define TTBFLAGS_LIB_CODE TTBPGTBL_ALWAYS
#define PGTBLFLAGS_LIB_CODE (PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP10)
#define PGAUXFLAGS_LIB_CODE PGAUX_SACRED
#define PGAUXFLAGS_LIB_CODE (PGAUX_SACRED | PGAUX_UNWRITEABLE)
#define TTBFLAGS_KERNEL_CODE TTBPGTBL_ALWAYS
#define PGTBLFLAGS_KERNEL_CODE (PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP01)
#define PGAUXFLAGS_KERNEL_CODE PGAUX_SACRED
#define PGAUXFLAGS_KERNEL_CODE (PGAUX_SACRED | PGAUX_UNWRITEABLE)
#define TTBFLAGS_KERNEL_DATA TTBPGTBL_ALWAYS
#define PGTBLFLAGS_KERNEL_DATA (PGTBLSM_XN | PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP01)
#define PGAUXFLAGS_KERNEL_DATA PGAUX_SACRED
#define TTBFLAGS_INIT_CODE TTBFLAGS_KERNEL_CODE
#define PGTBLFLAGS_INIT_CODE PGTBLFLAGS_KERNEL_CODE
#define PGAUXFLAGS_INIT_CODE 0
#define PGAUXFLAGS_INIT_CODE PGAUX_UNWRITEABLE
#define TTBFLAGS_INIT_DATA TTBFLAGS_KERNEL_DATA
#define PGTBLFLAGS_INIT_DATA PGTBLFLAGS_KERNEL_DATA
#define PGAUXFLAGS_INIT_DATA 0
@@ -207,7 +209,8 @@ typedef union tagTTB {
/* TTB auxiliary descriptor */
typedef struct tagTTBAUXENTRY {
unsigned sacred : 1; /* sacred TTB - should never be deallocated */
unsigned reserved : 31; /* reserved for future allocation */
unsigned unwriteable : 1; /* entry is not writeable */
unsigned reserved : 30; /* reserved for future allocation */
} TTBAUXENTRY, *PTTBAUXENTRY;
/* TTB auxiliary table entry */
@@ -246,7 +249,8 @@ typedef union tagPGTBL {
/* page auxiliary descriptor */
typedef struct tagPGAUXENTRY {
unsigned sacred : 1; /* sacred page - should never be deallocated */
unsigned reserved : 31; /* reserved for future allocation */
unsigned unwriteable : 1; /* entry is not writeable */
unsigned reserved : 30; /* reserved for future allocation */
} PGAUXENTRY, *PPGAUXENTRY;
/* page table auxiliary entry */
@@ -264,6 +268,9 @@ typedef struct tagPAGETAB {
/* VMA index macros */
#define mmVMA2TTBIndex(vma) (((vma) >> (SYS_PAGE_BITS + SYS_PGTBL_BITS)) & ((1 << SYS_TTB_BITS) - 1))
#define mmVMA2PGTBLIndex(vma) (((vma) >> SYS_PAGE_BITS) & ((1 << SYS_PGTBL_BITS) - 1))
#define mmIndices2VMA3(ttb, pgtbl, ofs) \
((((ttb) & ((1 << SYS_TTB_BITS) - 1)) << (SYS_PAGE_BITS + SYS_PGTBL_BITS)) | \
(((pgtbl) & ((1 << SYS_PGTBL_BITS) - 1)) << SYS_PAGE_BITS) | ((ofs) & (SYS_PAGE_SIZE - 1)))
/*
* Data structures for the Master Page Database.

View File

@@ -82,9 +82,10 @@ typedef struct tagRBTREE {
PRBTREENODE ptnRoot; /* pointer to root of tree */
} RBTREE, *PRBTREE;
/* Macro to initialize the tree head. */
/* Tree macros. */
#define rbtInitTree(ptree, pfnCompare) \
do { (ptree)->pfnTreeCompare = (pfnCompare); (ptree)->ptnRoot = NULL; } while (0)
#define rbtIsEmpty(ptree) MAKEBOOL(!((ptree)->ptnRoot))
/* Type of function used by RbtWalk. */
typedef BOOL (*PFNRBTWALK)(PRBTREE, PRBTREENODE, PVOID);

View File

@@ -104,5 +104,6 @@
#define MEMMGR_E_ENDTTB SCODE_CAST(0x86010004) /* tried to "walk off" end of TTB */
#define MEMMGR_E_NOSACRED SCODE_CAST(0x86010005) /* tried to demap a "sacred" entry */
#define MEMMGR_E_NOKERNSPC SCODE_CAST(0x86010006) /* no kernel space */
#define MEMMGR_E_RECURSED SCODE_CAST(0x86010007) /* tried to recurse into page allocation */
#endif /* __SCODE_H_INCLUDED */