Working on allocator
This commit is contained in:
parent
ded1e99fb9
commit
77f4895d48
|
@ -31,6 +31,7 @@
|
|||
#include <mm/map.h>
|
||||
#include <lib/buf.h>
|
||||
#include <io/vga.h>
|
||||
#include <ke/time.h>
|
||||
|
||||
//-----------
|
||||
|
||||
|
@ -220,7 +221,7 @@ void MmInitPaging(void)
|
|||
//
|
||||
// Get a page from an address
|
||||
//
|
||||
static pte_t *MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
||||
static ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr) //XXX MUST CREATE NEW ENTRIES IN TREE
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||
|
||||
|
@ -228,27 +229,29 @@ static pte_t *MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
|||
KeStartPanic("MmSetPage() Out of bound of the address space !");
|
||||
}
|
||||
|
||||
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512] & ~((KPAGESIZE - 1) | NX | NX));
|
||||
//DebugLog("pdp\t: %p\n", pdp);
|
||||
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] & ~((KPAGESIZE - 1) | NX));
|
||||
//DebugLog("pd\t: %p\n", pd);
|
||||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~((KPAGESIZE - 1) | NX));
|
||||
//DebugLog("pt\t: %p\n", pt);
|
||||
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512]);
|
||||
DebugLog("pdp\t: %p\n", pdp);
|
||||
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] );
|
||||
DebugLog("pd\t: %p\n", pd);
|
||||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] );
|
||||
DebugLog("pt\t: %p\n", pt);
|
||||
|
||||
pte_t *page = &pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512];
|
||||
//DebugLog("page (with flags): %p\n", page);
|
||||
ulong index = ((ulong)virtualAddr / ((ulong)KPAGESIZE)) % 512;
|
||||
|
||||
ulong *page = &(pt[index]);
|
||||
DebugLog("page (with flags): %p\n", page);
|
||||
KeSleep(6000);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Translates a virtual address to its physical equivalent
|
||||
//
|
||||
void *MmTransVirtToPhyAddr(void* virtualAddr)
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
if (*page == (*page & ~((KPAGESIZE - 1) | NX))) {
|
||||
return NULL;
|
||||
|
@ -270,7 +273,7 @@ void *MmTransPhyToVirtAddr(void* physicalAddr)
|
|||
//
|
||||
void MmSetPage(void* virtualAddr, ulong flags)
|
||||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
*page |= flags;
|
||||
|
||||
|
@ -282,7 +285,7 @@ void MmSetPage(void* virtualAddr, ulong flags)
|
|||
//
|
||||
void MmUnsetPage(void* virtualAddr, ulong flags)
|
||||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
*page &= (~flags);
|
||||
|
||||
|
@ -294,14 +297,11 @@ void MmUnsetPage(void* virtualAddr, ulong flags)
|
|||
//
|
||||
void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
||||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
DebugLog("Request %p:%p with %lu\n", virtualAddr, physicalAddr, flags);
|
||||
DebugLog("Page (at %p) %p : was %p\n", &page, page, *page);
|
||||
|
||||
*page = (ulong)physicalAddr | flags;
|
||||
|
||||
DebugLog("Page (at %p) %p : is %p\n", &page, page, *page);
|
||||
page[0] = (ulong)physicalAddr | flags;
|
||||
|
||||
MmPhysicalPageTable[(ulong)physicalAddr
|
||||
/ ((ulong)KPAGESIZE)
|
||||
|
@ -318,7 +318,7 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
|||
//
|
||||
void MmUnmapPage(void* virtualAddr)
|
||||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
MmPhysicalPageTable[(ulong)(MmTransVirtToPhyAddr(virtualAddr))
|
||||
/ ((ulong)KPAGESIZE)
|
||||
|
|
Loading…
Reference in New Issue