Modify areaAdd api to be able to do more check

This commit is contained in:
Mathieu Maret 2021-10-28 18:33:02 +02:00
parent be080af906
commit ca399ee782
2 changed files with 16 additions and 14 deletions

View File

@ -18,27 +18,23 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr
vaddr_t areaAddr, descAddr, entryAddr;
allocSetup(sizeof(struct memArea), &areaAddr, &descAddr, &entryAddr);
areaAdd(descAddr, 1, FALSE);
areaAdd(descAddr, descAddr + PAGE_SIZE, FALSE);
if (entryAddr != descAddr)
areaAdd(entryAddr, 1, FALSE);
areaAdd(entryAddr, entryAddr + PAGE_SIZE, FALSE);
if (areaAddr != descAddr && areaAddr != entryAddr)
areaAdd(areaAddr, 1, FALSE);
areaAdd(areaAddr, areaAddr + PAGE_SIZE, FALSE);
//kernel bootstrap part
int nbPagesKernel = DIV_ROUND_UP((stackBottom - firstMemUsed), PAGE_SIZE);
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), nbPagesKernel, FALSE);
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), stackBottom, FALSE);
//Initial kernel stack
int nbPagesStack = DIV_ROUND_UP((stackTop - stackBottom), PAGE_SIZE);
areaAdd(ALIGN_DOWN(stackBottom, PAGE_SIZE), nbPagesStack, FALSE);
areaAdd(stackBottom, stackTop, FALSE);
// Rest of kernel code
int nbPagesKernelCode = DIV_ROUND_UP((lastUsed - stackTop), PAGE_SIZE);
areaAdd(ALIGN_DOWN(stackTop, PAGE_SIZE), nbPagesKernelCode, FALSE);
areaAdd(stackTop, lastUsed, FALSE);
// Rest of virtual mem is free
int nbFreePages = DIV_ROUND_UP((AREA_MEM_TOP - areaAddr), PAGE_SIZE);
areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), nbFreePages, TRUE);
areaAdd(areaAddr + PAGE_SIZE, AREA_MEM_TOP, TRUE);
// Create allocBank for the rest of the system
allocPopulate();
@ -122,16 +118,22 @@ vaddr_t areaAlloc(unsigned int nbPages, uint32_t flags)
return allocated->startAddr;
}
int areaAdd(vaddr_t addr, uint nbPages, int isFree)
int areaAdd(vaddr_t start, vaddr_t end, int isFree)
{
struct memArea **area;
int nbPages = (end-start)/PAGE_SIZE;
assert(nbPages >0);
assert(IS_ALIGNED(start, PAGE_SIZE));
assert(IS_ALIGNED(end, PAGE_SIZE));
struct memArea *newArea = (struct memArea *)malloc(sizeof(struct memArea));
if (!newArea)
return (vaddr_t)NULL;
newArea->nbPages = nbPages;
newArea->startAddr = addr;
newArea->startAddr = start;
if (isFree) {
area = &freeArea;

View File

@ -19,4 +19,4 @@ struct memArea {
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stack_bottom, vaddr_t stack_top);
vaddr_t areaAlloc(unsigned int nbPages, uint32_t flags);
int areaFree(vaddr_t addr);
int areaAdd(vaddr_t addr, uint nbPages, int isFree);
int areaAdd(vaddr_t begin, vaddr_t end, int isFree);