1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Working on Paging API #67

This commit is contained in:
Adrien Bourmault 2020-01-11 00:05:34 +01:00
parent ee73150891
commit 40cd623b97

View File

@ -14,8 +14,6 @@
pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE)));
ulong *MmPhysicalPageTable;
extern MemoryMap_t memoryMap;
extern ulong _text;
extern ulong _text_end;
extern ulong _rodata;
@ -23,9 +21,11 @@ extern ulong _rodata_end;
extern ulong _data;
extern ulong _data_end;
extern MemoryMap_t memoryMap;
ulong MmStackGuards[2] = { 0 };
ulong MmVirtLastAddress = 0;
ulong MmPhysLastKernelAddress = 0;
ulong MmPhysLastKernAddress = 0;
enum
{
@ -59,8 +59,8 @@ void MmInitPaging(void)
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
// Difference between the end of kernel and the begin of userspace
MmPhysLastKernelAddress = (ulong)(_heap_start + _heap_max);
ulong diffKernUsr = (ulong)USERSPACE - MmPhysLastKernelAddress - KPAGESIZE;
MmPhysLastKernAddress = (ulong)(_heap_start + _heap_max);
ulong diffKernUsr = (ulong)USERSPACE - MmPhysLastKernAddress - KPAGESIZE;
// Maximum VIRTUAL address in memory
MmVirtLastAddress = phRamSize + diffKernUsr;
@ -161,22 +161,22 @@ void MmInitPaging(void)
//DebugLog("\tSection .rodata at %p\n", curAddrPT);
}
// While we're inside the kernel pages
else if ((ulong)curAddrPT <= MmPhysLastKernelAddress) {
else if ((ulong)curAddrPT <= MmPhysLastKernAddress) {
MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE;
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
if ((ulong)curAddrPT == MmPhysLastKernelAddress) {
if ((ulong)curAddrPT == MmPhysLastKernAddress) {
//DebugLog("\tLast page of kernel at %p\n", curAddrPT);
}
}
// While we're inside the userspace pages
else if ((ulong)curAddrPT >= USERSPACE) {
MmPT[index] = ((ulong)curAddrPT - diffKernUsr); // Not present for instance, unallocated
MmPT[index] = ((ulong)curAddrPT - diffKernUsr) | PRESENT; // Not present for instance
xedni = (((ulong)curAddrPT - diffKernUsr) / ((ulong)KPAGESIZE));
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
if ((ulong)curAddrPT == USERSPACE) {
//DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr);
DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr);
}
}
else {
@ -229,7 +229,7 @@ void *MmTransVirtToPhyAddr(void* virtualAddr)
ulong virtAddrPage = (ulong)virtualAddr & ( ~(KPAGESIZE - 1));
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
if (*page & PRESENT) {
if (*page == (*page & ~(KPAGESIZE - 1))) {
return NULL;
}
@ -241,7 +241,7 @@ void *MmTransPhyToVirtAddr(void* physicalAddr)
ulong phyAddrPage = (ulong)physicalAddr & ( ~(KPAGESIZE - 1));
return (void*)( MmPhysicalPageTable[(ulong)physicalAddr
/ ((ulong)KPAGESIZE)
+ ((ulong)physicalAddr - phyAddrPage) ] );
] + ((ulong)physicalAddr - phyAddrPage));
}
//
@ -287,13 +287,13 @@ void MmUnmapPage(void* virtualAddr)
{
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
*page &= (~PRESENT);
*page = 0;
KeFlushTlbSingle(*page);
}
//
// Find physical unallocated pages
// Find a free block of pages
//
void *MmGetPhyPageBlock(size_t size, bool usermode) {
void *startPhyPage = 0;
@ -307,7 +307,7 @@ void *MmGetPhyPageBlock(size_t size, bool usermode) {
if (!usermode) {
startPhyPage = MmTransVirtToPhyAddr((void*)KPAGESIZE + 1);
endPhyPage = (void*)MmPhysLastKernelAddress;
endPhyPage = (void*)MmPhysLastKernAddress;
} else {
startPhyPage = MmTransVirtToPhyAddr((void*)USERSPACE);
endPhyPage = (void*)(phRamSize & ~(KPAGESIZE - 1));