diff --git a/include/mm/paging.h b/include/mm/paging.h index b0f5568..c4f2845 100644 --- a/include/mm/paging.h +++ b/include/mm/paging.h @@ -33,7 +33,7 @@ #define KPAGESIZE (4 * KB) #define UPAGESIZE (4 * KB) -#define USERSPACE 0x100000000 +#define USERSPACE 0x200000000 //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index b13f0c6..bbd6c46 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -201,6 +201,10 @@ void MmInitPaging(void) MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; } + else { + MmPT[index] = (ulong)0; + MmPhysicalPageTable[xedni] = (ulong)0; + } } } } @@ -292,7 +296,12 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags) { pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr); - *page = ((ulong)physicalAddr & ~((KPAGESIZE - 1) | NX)) | 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; + + DebugLog("Page (at %p) %p : is %p\n", &page, page, *page); MmPhysicalPageTable[(ulong)physicalAddr / ((ulong)KPAGESIZE) diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c index 6ce3356..bd808a3 100644 --- a/kaleid/kernel/mm/palloc.c +++ b/kaleid/kernel/mm/palloc.c @@ -158,21 +158,32 @@ ulong MmAllocPageFrameEx(void ***frameListPtr, size_t *pageNumber, size_t size, ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; //DebugLog("Allocating %d pages...\n", *pageNumber); - - for (void *curPage = (void*)(MmPhysLastKernAddress + KPAGESIZE); curPage < (void*)phRamSize; curPage += KPAGESIZE) { - if (!isPageBusy(curPage)) { - (*frameListPtr)[curNumber] = curPage; - inBlock = true; - //DebugLog("Select page : %p\n", curPage); - if (++curNumber >= *pageNumber) { - break; + if (contiguous) { + for (void *curPage = (void*)(MmPhysLastKernAddress + KPAGESIZE); curPage < (void*)phRamSize; curPage += KPAGESIZE) { + if (!isPageBusy(curPage)) { + (*frameListPtr)[curNumber] = curPage; + inBlock = true; + //DebugLog("Select page : %p\n", curPage); + if (++curNumber >= *pageNumber) { + break; + } + } else { + inBlock = false; + } + if (contiguous) + if (!inBlock) + curNumber = 0; + } + } else { + for (void *curPage = (void*)(MmPhysLastKernAddress + KPAGESIZE); curPage < (void*)phRamSize; curPage += KPAGESIZE) { + if (!isPageBusy(curPage)) { + (*frameListPtr)[curNumber] = curPage; + //DebugLog("Select page : %p\n", curPage); + if (++curNumber >= *pageNumber) { + break; + } } - } else { - inBlock = false; } - if (contiguous) - if (!inBlock) - curNumber = 0; } if (curNumber != *pageNumber) { @@ -236,8 +247,8 @@ error_t MmMapPageFrame(ulong id, void *virtAddr, ulong flags) } if (id == busyPage->id) { + DebugLog("Map %p at %p\n", busyPage->phyAddress, virtAddr + offset); MmMapPage((void*)((ulong)virtAddr + offset), busyPage->phyAddress, flags); - //DebugLog("Map %p at %p\n", busyPage->phyAddress, virtAddr + offset); offset += KPAGESIZE; } } @@ -285,18 +296,39 @@ error_t MmTestBusyPage(void) /* } */ ulong a = KeGetTicks(); - tab[j++] = MmAllocPageFrame(50*MB, NORMAL); - tab[j++] = MmAllocPageFrame(50*MB, NORMAL); - tab[j++] = MmAllocPageFrame(50*MB, NORMAL); - tab[j++] = MmAllocPageFrame(50*MB, NORMAL); - tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + DebugLog("Start alloc : %lu s\n", a/1000); + tab[j++] = MmAllocPageFrame(30*MB, NORMAL); ulong b = KeGetTicks(); - - DebugLog("Alloc time per MB : %lu\n", (b-a)/5/5); - - //printBusyPages(); + DebugLog("End alloc : %lu s\n", b/1000); + DebugLog("Alloc time : %lu s\n", (b-a)/1000); DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB); + a = KeGetTicks(); + DebugLog("Start alloc : %lu s\n", a/1000); + tab[j++] = MmAllocPageFrame(20*MB, NORMAL); + b = KeGetTicks(); + DebugLog("End alloc : %lu s\n", b/1000); + DebugLog("Alloc time : %lu s\n", (b-a)/1000); + DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB); + + j = 0; + + a = KeGetTicks(); + DebugLog("Start free : %lu ms\n", a); + MmFreePageFrame(tab[j++]); + b = KeGetTicks(); + DebugLog("End free : %lu ms\n", b); + DebugLog("Free time : %lu ms\n", (b-a)); + DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB); + + a = KeGetTicks(); + DebugLog("Start map : %lu ms\n", a); + MmMapPageFrame(tab[1], (void*)USERSPACE, PRESENT | USERMODE | READWRITE); + b = KeGetTicks(); + DebugLog("End map : %lu ms\n", b); + DebugLog("Map time : %lu ms\n", (b-a)); + //printBusyPages(); + DebugLog("Finished !\n"); return EOK;