mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Working on page allocator (4) #67
This commit is contained in:
parent
aeb1ca721b
commit
8437b854ca
@ -40,6 +40,7 @@ typedef struct AllocatedPage_t{
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
error_t MmGetFreePageFrame(void **framePtr, size_t *pageNumber, size_t size);
|
||||
error_t MmTestBusyPage(void);
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user