Dynamic paging functionnal #67
This commit is contained in:
parent
5ae13125bc
commit
3fe1a3cfec
|
@ -182,7 +182,7 @@ void MmInitPaging(void)
|
|||
//
|
||||
// Get a page from an address
|
||||
//
|
||||
static pte_t MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
||||
static pte_t *MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~(KPAGESIZE - 1));
|
||||
|
||||
|
@ -197,7 +197,7 @@ static pte_t MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
|||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~(KPAGESIZE - 1));
|
||||
//DebugLog("pt\t: %p\n", pt);
|
||||
|
||||
ulong page = (ulong)pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512];
|
||||
pte_t *page = &pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512];
|
||||
//DebugLog("page (with flags): %p\n", page);
|
||||
|
||||
return page;
|
||||
|
@ -210,13 +210,13 @@ static pte_t MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
|||
void *MmTransVirtToPhyAddr(void* virtualAddr)
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~(KPAGESIZE - 1));
|
||||
pte_t page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
if (page == (page & ~(KPAGESIZE - 1))) {
|
||||
if (*page == (*page & ~(KPAGESIZE - 1))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void*)((page & ~(KPAGESIZE - 1))+ ((ulong)virtualAddr - (ulong)virtAddrPage));
|
||||
return (void*)((*page & ~(KPAGESIZE - 1))+ ((ulong)virtualAddr - (ulong)virtAddrPage));
|
||||
}
|
||||
|
||||
void *MmTransPhyToVirtAddr(void* physicalAddr)
|
||||
|
@ -229,11 +229,11 @@ void *MmTransPhyToVirtAddr(void* physicalAddr)
|
|||
//
|
||||
void MmSetPage(void* virtualAddr, ulong flags)
|
||||
{
|
||||
pte_t page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
page |= flags;
|
||||
*page |= flags;
|
||||
|
||||
KeFlushTlbSingle(page);
|
||||
KeFlushTlbSingle(*page);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -241,11 +241,11 @@ void MmSetPage(void* virtualAddr, ulong flags)
|
|||
//
|
||||
void MmUnsetPage(void* virtualAddr, ulong flags)
|
||||
{
|
||||
pte_t page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
page &= (~flags);
|
||||
*page &= (~flags);
|
||||
|
||||
KeFlushTlbSingle(page);
|
||||
KeFlushTlbSingle(*page);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -253,11 +253,11 @@ void MmUnsetPage(void* virtualAddr, ulong flags)
|
|||
//
|
||||
void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
||||
{
|
||||
pte_t page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
page = ((ulong)physicalAddr & ~(KPAGESIZE - 1)) | flags;
|
||||
*page = ((ulong)physicalAddr & ~(KPAGESIZE - 1)) | flags;
|
||||
|
||||
KeFlushTlbSingle(page);
|
||||
KeFlushTlbSingle(*page);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -265,11 +265,11 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
|||
//
|
||||
void MmUnmapPage(void* virtualAddr)
|
||||
{
|
||||
pte_t page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
page = 0;
|
||||
*page = 0;
|
||||
|
||||
KeFlushTlbSingle(page);
|
||||
KeFlushTlbSingle(*page);
|
||||
}
|
||||
|
||||
//-----------
|
||||
|
|
|
@ -204,6 +204,38 @@ error_t CmdPageTranslateVirtToPhy(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
PRESENT = 1 << 0,
|
||||
READWRITE = 1 << 1,
|
||||
USERMODE = 1 << 2,
|
||||
WRITETHR = 1 << 3,
|
||||
CACHEDIS = 1 << 4,
|
||||
ACCESSED = 1 << 5,
|
||||
DIRTY = 1 << 6,
|
||||
HUGE = 1 << 7,
|
||||
NX = 1UL << 63
|
||||
};
|
||||
|
||||
error_t CmdPageMap(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
void *virtual = (void*)atoul(argv[1]);
|
||||
void *physical = (void*)atoul(argv[2]);
|
||||
|
||||
MmMapPage(virtual, physical, PRESENT | READWRITE);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdPageUnmap(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
void *virtual = (void*)atoul(argv[1]);
|
||||
|
||||
MmUnmapPage(virtual);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdPageTranslatePhyToVirt(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
void *address = (void*)atoul(argv[1]);
|
||||
|
@ -222,10 +254,6 @@ error_t CmdPF(int argc, char **argv, char *cmdline)
|
|||
{
|
||||
ulong *address = (ulong*)(ulong)atoul(argv[1]);
|
||||
|
||||
if (!address) {
|
||||
address = (ulong *)0x80000000;
|
||||
}
|
||||
|
||||
KernLog("Provoking Page Fault at %#x\n", address);
|
||||
|
||||
KernLog("It contained %#x\n", *address);
|
||||
|
@ -284,8 +312,8 @@ static Command_t testcmdtable[] =
|
|||
{ "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"},
|
||||
{ "transvtp", CmdPageTranslateVirtToPhy, "Translate a virtual to"
|
||||
" physical address (paging)"},
|
||||
{ "transptv", CmdPageTranslatePhyToVirt, "Translate a physical to"
|
||||
" virtual address (paging)"},
|
||||
{ "pmap", CmdPageMap, "Map a page to given physical addr" },
|
||||
{ "punmap", CmdPageUnmap, "Unmap a page" },
|
||||
{ "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
||||
{ "shell", CmdShell, "Start a new shell (nested)", },
|
||||
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
||||
|
|
Loading…
Reference in New Issue