misc modifications

This commit is contained in:
Adrien Bourmault 2020-01-15 01:34:46 +01:00
parent d13472712d
commit 69b0a65a0f
4 changed files with 55 additions and 35 deletions

View File

@ -42,7 +42,7 @@ typedef struct AllocatedPage_t{
//----------------------------------------------------------------------------//
ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous);
ulong MmAllocPageFrame(void ***frameListPtr, size_t *pageNumber, size_t size, bool contiguous);
void MmFreePageFrame(ulong id);
error_t MmTestBusyPage(void);

View File

@ -105,7 +105,8 @@ static error_t InitMemoryMap(void)
return EOK;
}
size_t MmGetAvailZoneSize(void *start) {
size_t MmGetAvailZoneSize(void *start)
{
uint i;
// Because the kernel is the kernel
@ -129,7 +130,8 @@ size_t MmGetAvailZoneSize(void *start) {
return 0;
}
bool MmIsFailingZoneSize(void *start) {
bool MmIsFailingZoneSize(void *start)
{
uint i;
// Because the kernel is the kernel
@ -153,7 +155,8 @@ bool MmIsFailingZoneSize(void *start) {
return 0;
}
void *MmGetFirstAvailZone(void *start) {
void *MmGetFirstAvailZone(void *start)
{
uint i;
void *current = 0;
@ -194,7 +197,8 @@ void *MmGetFirstAvailZone(void *start) {
return current;
}
void MmPrintMemoryMap(void) {
void MmPrintMemoryMap(void)
{
char avStr[15];
extern int shcol;

View File

@ -49,6 +49,11 @@ static bool isPageBusy(void *phyPageAddr)
AllocatedPage_t *busyPage = &busyPagesList;
bool isBusy = false;
// In case of NVS, ACPI or BADRAM zone, considered busy
if (!MmGetAvailZoneSize(phyPageAddr))
return true;
// Search in the busylist if the phy addr is here
while(busyPage->next) {
busyPage = busyPage->next;
if (phyPageAddr == busyPage->phyAddress) {
@ -62,9 +67,14 @@ static bool isPageBusy(void *phyPageAddr)
static void printBusyPages(void)
{
AllocatedPage_t *busyPage = &busyPagesList;
while(busyPage->next) {
busyPage = busyPage->next;
KernLog("Busy page at %p\n", busyPage->phyAddress);
if (!busyPage->next) {
KernLog("No busy page\n");
} else {
while(busyPage->next) {
busyPage = busyPage->next;
KernLog("Busy page at %p\n", busyPage->phyAddress);
}
}
}
@ -102,12 +112,12 @@ static void removePageFromBusyList(void *phyPageAddr)
//
// Returns an id to identify a page frame allocated (kernel)
//
ulong MmAllocPageFrame(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;
frameListPtr = (void**)malloc(sizeof(void*)*(*pageNumber));
*frameListPtr = (void**)malloc(sizeof(void*)*(*pageNumber));
size_t curNumber = 0;
bool inBlock = false;
@ -121,7 +131,7 @@ ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, boo
for (void *curPage = (void*)MmPhysLastKernAddress; curPage < (void*)phRamSize; curPage += KPAGESIZE) {
if (!isPageBusy(curPage)) {
frameListPtr[curNumber] = curPage;
(*frameListPtr)[curNumber] = curPage;
inBlock = true;
//DebugLog("Select page : %p\n", curPage);
if (++curNumber >= *pageNumber) {
@ -136,8 +146,8 @@ ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, boo
}
for (size_t i = 0; i < *pageNumber; i++) {
addPageToBusyList(frameListPtr[i], id);
//DebugLog("Allocating page : %p\n", frameListPtr[i]);
addPageToBusyList((*frameListPtr)[i], id);
//DebugLog("Allocating page : %p\n", *frameListPtr[i]);
}
return id;
@ -164,53 +174,64 @@ error_t MmTestBusyPage(void)
DebugLog("\nBusy pages\n");
printBusyPages();
DebugLog("\nAlloc 6677 bytes\n");
void **ptr = NULL;
size_t n = 0;
ulong id1 = MmAllocPageFrame (ptr, &n, 6677, NORMAL);
ulong id1 = MmAllocPageFrame(&ptr, &n, 6677, NORMAL);
DebugLog("\nAlloc 6677 bytes : %p, %d pages, first at %p\n", ptr, n, ptr[0]);
DebugLog("\nAlloc 9045 bytes\n");
void **ptr2 = NULL;
size_t n2 = 0;
ulong id2 = MmAllocPageFrame (ptr2, &n2, 9045, NORMAL);
ulong id2 = MmAllocPageFrame(&ptr2, &n2, 9045, NORMAL);
DebugLog("\nAlloc 9045 bytes: %p, %d pages, first at %p\n", ptr2, n2, ptr2[0]);
DebugLog("\nAlloc 1200 bytes\n");
void **ptr3 = NULL;
size_t n3 = 0;
ulong id3 = MmAllocPageFrame (ptr3, &n3, 1200, NORMAL);
ulong id3 = MmAllocPageFrame(&ptr3, &n3, 1200, NORMAL);
DebugLog("\nAlloc 1200 bytes: %p, %d pages, first at %p\n", ptr3, n3, ptr3[0]);
DebugLog("\nAlloc 4096 bytes\n");
void **ptr4 = NULL;
size_t n4 = 0;
ulong id4 = MmAllocPageFrame (ptr3, &n3, 4096, NORMAL);
DebugLog("\nAlloc 4097 bytes\n");
ulong id4 = MmAllocPageFrame(&ptr4, &n4, 4096, NORMAL);
DebugLog("\nAlloc 4096 bytes: %p, %d pages, first at %p\n", ptr4, n4, ptr4[0]);
void **ptr5 = NULL;
size_t n5 = 0;
ulong id5 = MmAllocPageFrame (ptr3, &n3, 4097, NORMAL);
ulong id5 = MmAllocPageFrame(&ptr5, &n5, 4097, NORMAL);
DebugLog("\nAlloc 4097 bytes: %p, %d pages, first at %p\n", ptr5, n5, ptr5[0]);
printBusyPages();
DebugLog("\nFree 6677 and 1200 bytes\n");
MmFreePageFrame(id1);
MmFreePageFrame(id3);
DebugLog("\nFree 6677 and 1200 bytes\n");
DebugLog("\nAlloc 10000 bytes\n");
void **ptr6 = NULL;
size_t n6 = 0;
ulong id6 = MmAllocPageFrame (ptr3, &n3, 10000, NORMAL);
ulong id6 = MmAllocPageFrame(&ptr6, &n6, 10000, NORMAL);
DebugLog("\nAlloc 10000 bytes: %p, %d pages, first at %p\n", ptr6, n6, ptr6[0]);
printBusyPages();
DebugLog("\nFree 10000 bytes\n");
MmFreePageFrame(id6);
DebugLog("\nFree 10000 bytes\n");
printBusyPages();
DebugLog("\nAlloc 10000 bytes contiguous\n");
void **ptr7 = NULL;
size_t n7 = 0;
ulong id7 = MmAllocPageFrame (ptr3, &n3, 10000, CONTIGUOUS);
ulong id7 = MmAllocPageFrame(&ptr7, &n7, 10000, CONTIGUOUS);
DebugLog("\nAlloc 10000 bytes contiguous: %p, %d pages, first at %p\n", ptr7, n7, ptr7[0]);
printBusyPages();
MmFreePageFrame(id1);
MmFreePageFrame(id2);
MmFreePageFrame(id3);
MmFreePageFrame(id4);
MmFreePageFrame(id5);
MmFreePageFrame(id6);
MmFreePageFrame(id7);
DebugLog("\nFree all bytes\n");
printBusyPages();

View File

@ -254,11 +254,6 @@ error_t CmdPageUnmap(int argc, char **argv, char *cmdline)
error_t CmdPageBlock(int argc, char **argv, char *cmdline)
{
size_t size = (size_t)atoi(argv[1]);
bool usermode = (bool)atoi(argv[2]);
size_t pageNum = 0;
error_t err = MmTestBusyPage();
return err;
}