From 2bec082b2d1373f1b592d731312281e0ef18c666 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 14 Jan 2020 16:58:38 +0100 Subject: [PATCH] Page allocator functionnal #67 --- include/mm/palloc.h | 4 +++- kaleid/kernel/mm/palloc.c | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/mm/palloc.h b/include/mm/palloc.h index ba591c9..ad7c688 100644 --- a/include/mm/palloc.h +++ b/include/mm/palloc.h @@ -39,7 +39,9 @@ typedef struct AllocatedPage_t{ //----------------------------------------------------------------------------// -error_t MmGetFreePageFrame(void **framePtr, size_t *pageNumber, size_t size); +ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous); +void MmFreePageFrame(ulong id); + error_t MmTestBusyPage(void); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c index 98b61da..cb0c2d7 100644 --- a/kaleid/kernel/mm/palloc.c +++ b/kaleid/kernel/mm/palloc.c @@ -100,9 +100,9 @@ static void removePageFromBusyList(void *phyPageAddr) } // -// Returns an id to identify a page frame allocated +// Returns an id to identify a page frame allocated (kernel) // -ulong MmAllocKernelPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous) +ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous) { static ulong id = 0; *pageNumber = (((ulong)size - 1) / KPAGESIZE) + 1; @@ -143,7 +143,7 @@ ulong MmAllocKernelPageFrame(void **frameListPtr, size_t *pageNumber, size_t siz return id; } -void MmFreeKernelPageFrame(ulong id) +void MmFreePageFrame(ulong id) { AllocatedPage_t *busyPage = &busyPagesList; @@ -164,50 +164,50 @@ error_t MmTestBusyPage(void) DebugLog("\nAlloc 6677 bytes\n"); void **ptr = NULL; size_t n = 0; - ulong id1 = MmAllocKernelPageFrame (ptr, &n, 6677, false); + ulong id1 = MmAllocPageFrame (ptr, &n, 6677, false); DebugLog("\nAlloc 9045 bytes\n"); void **ptr2 = NULL; size_t n2 = 0; - ulong id2 = MmAllocKernelPageFrame (ptr2, &n2, 9045, false); + ulong id2 = MmAllocPageFrame (ptr2, &n2, 9045, false); DebugLog("\nAlloc 1200 bytes\n"); void **ptr3 = NULL; size_t n3 = 0; - ulong id3 = MmAllocKernelPageFrame (ptr3, &n3, 1200, false); + ulong id3 = MmAllocPageFrame (ptr3, &n3, 1200, false); DebugLog("\nAlloc 4096 bytes\n"); void **ptr4 = NULL; size_t n4 = 0; - ulong id4 = MmAllocKernelPageFrame (ptr3, &n3, 4096, false); + ulong id4 = MmAllocPageFrame (ptr3, &n3, 4096, false); DebugLog("\nAlloc 4097 bytes\n"); void **ptr5 = NULL; size_t n5 = 0; - ulong id5 = MmAllocKernelPageFrame (ptr3, &n3, 4097, false); + ulong id5 = MmAllocPageFrame (ptr3, &n3, 4097, false); printBusyPages(); DebugLog("\nFree 6677 and 1200 bytes\n"); - MmFreeKernelPageFrame(id1); - MmFreeKernelPageFrame(id3); + MmFreePageFrame(id1); + MmFreePageFrame(id3); DebugLog("\nAlloc 10000 bytes\n"); void **ptr6 = NULL; size_t n6 = 0; - ulong id6 = MmAllocKernelPageFrame (ptr3, &n3, 10000, false); + ulong id6 = MmAllocPageFrame (ptr3, &n3, 10000, false); printBusyPages(); DebugLog("\nFree 10000 bytes\n"); - MmFreeKernelPageFrame(id6); + MmFreePageFrame(id6); printBusyPages(); DebugLog("\nAlloc 10000 bytes contiguous\n"); void **ptr7 = NULL; size_t n7 = 0; - ulong id7 = MmAllocKernelPageFrame (ptr3, &n3, 10000, true); + ulong id7 = MmAllocPageFrame (ptr3, &n3, 10000, true); printBusyPages();