mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Working on allocator
This commit is contained in:
parent
ded1e99fb9
commit
77f4895d48
@ -31,6 +31,7 @@
|
|||||||
#include <mm/map.h>
|
#include <mm/map.h>
|
||||||
#include <lib/buf.h>
|
#include <lib/buf.h>
|
||||||
#include <io/vga.h>
|
#include <io/vga.h>
|
||||||
|
#include <ke/time.h>
|
||||||
|
|
||||||
//-----------
|
//-----------
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ void MmInitPaging(void)
|
|||||||
//
|
//
|
||||||
// Get a page from an address
|
// 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));
|
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 !");
|
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));
|
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512]);
|
||||||
//DebugLog("pdp\t: %p\n", pdp);
|
DebugLog("pdp\t: %p\n", pdp);
|
||||||
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] & ~((KPAGESIZE - 1) | NX));
|
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] );
|
||||||
//DebugLog("pd\t: %p\n", pd);
|
DebugLog("pd\t: %p\n", pd);
|
||||||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~((KPAGESIZE - 1) | NX));
|
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] );
|
||||||
//DebugLog("pt\t: %p\n", pt);
|
DebugLog("pt\t: %p\n", pt);
|
||||||
|
|
||||||
pte_t *page = &pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512];
|
ulong index = ((ulong)virtualAddr / ((ulong)KPAGESIZE)) % 512;
|
||||||
//DebugLog("page (with flags): %p\n", page);
|
|
||||||
|
ulong *page = &(pt[index]);
|
||||||
|
DebugLog("page (with flags): %p\n", page);
|
||||||
|
KeSleep(6000);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Translates a virtual address to its physical equivalent
|
// Translates a virtual address to its physical equivalent
|
||||||
//
|
//
|
||||||
void *MmTransVirtToPhyAddr(void* virtualAddr)
|
void *MmTransVirtToPhyAddr(void* virtualAddr)
|
||||||
{
|
{
|
||||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||||
|
|
||||||
if (*page == (*page & ~((KPAGESIZE - 1) | NX))) {
|
if (*page == (*page & ~((KPAGESIZE - 1) | NX))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -270,7 +273,7 @@ void *MmTransPhyToVirtAddr(void* physicalAddr)
|
|||||||
//
|
//
|
||||||
void MmSetPage(void* virtualAddr, ulong flags)
|
void MmSetPage(void* virtualAddr, ulong flags)
|
||||||
{
|
{
|
||||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||||
|
|
||||||
*page |= flags;
|
*page |= flags;
|
||||||
|
|
||||||
@ -282,7 +285,7 @@ void MmSetPage(void* virtualAddr, ulong flags)
|
|||||||
//
|
//
|
||||||
void MmUnsetPage(void* virtualAddr, ulong flags)
|
void MmUnsetPage(void* virtualAddr, ulong flags)
|
||||||
{
|
{
|
||||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||||
|
|
||||||
*page &= (~flags);
|
*page &= (~flags);
|
||||||
|
|
||||||
@ -294,14 +297,11 @@ void MmUnsetPage(void* virtualAddr, ulong flags)
|
|||||||
//
|
//
|
||||||
void MmMapPage(void* virtualAddr, void* physicalAddr, 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("Request %p:%p with %lu\n", virtualAddr, physicalAddr, flags);
|
||||||
DebugLog("Page (at %p) %p : was %p\n", &page, page, *page);
|
|
||||||
|
|
||||||
*page = (ulong)physicalAddr | flags;
|
page[0] = (ulong)physicalAddr | flags;
|
||||||
|
|
||||||
DebugLog("Page (at %p) %p : is %p\n", &page, page, *page);
|
|
||||||
|
|
||||||
MmPhysicalPageTable[(ulong)physicalAddr
|
MmPhysicalPageTable[(ulong)physicalAddr
|
||||||
/ ((ulong)KPAGESIZE)
|
/ ((ulong)KPAGESIZE)
|
||||||
@ -318,7 +318,7 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
|||||||
//
|
//
|
||||||
void MmUnmapPage(void* virtualAddr)
|
void MmUnmapPage(void* virtualAddr)
|
||||||
{
|
{
|
||||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
ulong *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||||
|
|
||||||
MmPhysicalPageTable[(ulong)(MmTransVirtToPhyAddr(virtualAddr))
|
MmPhysicalPageTable[(ulong)(MmTransVirtToPhyAddr(virtualAddr))
|
||||||
/ ((ulong)KPAGESIZE)
|
/ ((ulong)KPAGESIZE)
|
||||||
|
Loading…
Reference in New Issue
Block a user