diff --git a/include/mm/palloc.h b/include/mm/palloc.h index b3ffe15..ba591c9 100644 --- a/include/mm/palloc.h +++ b/include/mm/palloc.h @@ -40,6 +40,7 @@ typedef struct AllocatedPage_t{ //----------------------------------------------------------------------------// error_t MmGetFreePageFrame(void **framePtr, size_t *pageNumber, size_t size); +error_t MmTestBusyPage(void); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index 64156fe..fabe03b 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -102,10 +102,6 @@ static error_t InitMemoryMap(void) KernLog("\tAvailable RAM size : %u MB\n", memoryMap.freeRamSize / MB); - // Magic value in memory to prevent smashing - ulong * heapStart = BtLoaderInfo.stackEndAddr + 8; - *heapStart = 0xbad00badbad00bad; - return EOK; } @@ -133,6 +129,30 @@ size_t MmGetAvailZoneSize(void *start) { return 0; } +bool MmIsFailingZoneSize(void *start) { + uint i; + + // Because the kernel is the kernel + if (start < BtLoaderInfo.stackEndAddr + 16) + return 0; + + // Search the zone where the start address is + for (i = 0; i < memoryMap.length; i++) { + // if the address is in a failing zone, we can return 1 + if ( + (memoryMap.entry[i].type == BADRAM_ZONE) && + (ulong)start >= (ulong)memoryMap.entry[i].addr && + (ulong)start < ((ulong)memoryMap.entry[i].addr + + (ulong)memoryMap.entry[i].length) + ) { + return 1; + } + } + + // If there is no zone, we return a 0 size + return 0; +} + void *MmGetFirstAvailZone(void *start) { uint i; void *current = 0; diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 04b5599..fbf9c1f 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -159,13 +159,13 @@ void MmInitPaging(void) MmPT[index] = (ulong)curAddrPT | PRESENT; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; MmStackGuards[0] = (ulong)curAddrPT; - DebugLog("\tStack Guard at %p\n", curAddrPT); + //DebugLog("\tStack Guard at %p\n", curAddrPT); } else if ((ulong)curAddrPT == (ulong)BtLoaderInfo.kernelEndAddr) { MmPT[index] = (ulong)curAddrPT | PRESENT; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; MmStackGuards[1] = (ulong)curAddrPT; - DebugLog("\tStack Guard at %p\n", curAddrPT); + //DebugLog("\tStack Guard at %p\n", curAddrPT); } // SECTION .TEXT PROTECTION else if ((ulong)curAddrPT >= (ulong)&_text && (ulong)curAddrPT <= (ulong)&_text_end) { diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c index 340a494..a402034 100644 --- a/kaleid/kernel/mm/palloc.c +++ b/kaleid/kernel/mm/palloc.c @@ -41,12 +41,12 @@ static AllocatedPage_t busyPagesList = { (void*)0, 0, (AllocatedPage_t*)0 }; //--------- -static bool MmIsPageBusy(void *phyAddr) { +static bool isPageBusy(void *phyPageAddr) { AllocatedPage_t *busyPage = &busyPagesList; bool isBusy = false; while(busyPage->next) { - busyPages = busyPage->next; + busyPage = busyPage->next; DebugLog("Busy page at %p\n", busyPage->phyAddress); if (phyPageAddr == busyPage->phyAddress) { @@ -58,6 +58,35 @@ static bool MmIsPageBusy(void *phyAddr) { return isBusy; } +static void addPageToBusyList(void *phyPageAddr, ulong id) { + AllocatedPage_t *busyPage = &busyPagesList; + + while(busyPage->next) { + busyPage = busyPage->next; + } + + AllocatedPage_t *newBusyPage = (AllocatedPage_t*)malloc(sizeof(AllocatedPage_t)); + newBusyPage->phyAddress = phyPageAddr; + newBusyPage->id = id; + busyPage->next = newBusyPage; +} + +static void removePageFromBusyList(void *phyPageAddr) { + AllocatedPage_t *busyPage = &busyPagesList; + AllocatedPage_t *prevBusyPage = NULL; + + while(busyPage->next) { + prevBusyPage = busyPage; + busyPage = busyPage->next; + + if (phyPageAddr == busyPage->phyAddress) { + prevBusyPage->next = busyPage->next; + free(busyPage); + break; + } + } +} + // // Returns a structure that describes a pageframe // @@ -67,6 +96,29 @@ error_t MmGetFreePageFrame(void **framePtr, size_t *pageNumber, size_t size) { return EOK; } +error_t MmTestBusyPage(void) { + DebugLog("Adding pages \n"); + addPageToBusyList((void*)0x123456789, 56); + addPageToBusyList((void*)0x555666666, 69); + addPageToBusyList((void*)0x454545454, 5); + DebugLog("\nVerifying busy 1\n"); + isPageBusy((void*)0x123456789); + DebugLog("\nVerifying busy 2\n"); + isPageBusy((void*)0); + DebugLog("\nVerifying busy 3\n"); + isPageBusy((void*)0x1234567894); + + DebugLog("\nRemoving first\n"); + removePageFromBusyList((void*)0x123456789); + isPageBusy((void*)0x1234567894); + DebugLog("\nRemoving others\n"); + removePageFromBusyList((void*)0x555666666); + removePageFromBusyList((void*)0x454545454); + + isPageBusy((void*)0x1234567894); + + return EOK; +} diff --git a/kaleid/kernel/sh/testcmds.c b/kaleid/kernel/sh/testcmds.c index 07b90f5..4207ae1 100644 --- a/kaleid/kernel/sh/testcmds.c +++ b/kaleid/kernel/sh/testcmds.c @@ -259,7 +259,7 @@ error_t CmdPageBlock(int argc, char **argv, char *cmdline) size_t pageNum = 0; - error_t err = MmGetFreePageFrame((void**)0x12345678, &pageNum, (size_t)4096); + error_t err = MmTestBusyPage(); return err; }