user_space #4

Merged
mathieu merged 40 commits from user_space into master 2021-11-04 16:17:36 +01:00
2 changed files with 16 additions and 14 deletions
Showing only changes of commit ca399ee782 - Show all commits

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);