user_space #4
@ -18,27 +18,23 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr
|
|||||||
|
|
||||||
vaddr_t areaAddr, descAddr, entryAddr;
|
vaddr_t areaAddr, descAddr, entryAddr;
|
||||||
allocSetup(sizeof(struct memArea), &areaAddr, &descAddr, &entryAddr);
|
allocSetup(sizeof(struct memArea), &areaAddr, &descAddr, &entryAddr);
|
||||||
areaAdd(descAddr, 1, FALSE);
|
areaAdd(descAddr, descAddr + PAGE_SIZE, FALSE);
|
||||||
if (entryAddr != descAddr)
|
if (entryAddr != descAddr)
|
||||||
areaAdd(entryAddr, 1, FALSE);
|
areaAdd(entryAddr, entryAddr + PAGE_SIZE, FALSE);
|
||||||
if (areaAddr != descAddr && areaAddr != entryAddr)
|
if (areaAddr != descAddr && areaAddr != entryAddr)
|
||||||
areaAdd(areaAddr, 1, FALSE);
|
areaAdd(areaAddr, areaAddr + PAGE_SIZE, FALSE);
|
||||||
|
|
||||||
//kernel bootstrap part
|
//kernel bootstrap part
|
||||||
int nbPagesKernel = DIV_ROUND_UP((stackBottom - firstMemUsed), PAGE_SIZE);
|
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), stackBottom, FALSE);
|
||||||
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), nbPagesKernel, FALSE);
|
|
||||||
|
|
||||||
//Initial kernel stack
|
//Initial kernel stack
|
||||||
int nbPagesStack = DIV_ROUND_UP((stackTop - stackBottom), PAGE_SIZE);
|
areaAdd(stackBottom, stackTop, FALSE);
|
||||||
areaAdd(ALIGN_DOWN(stackBottom, PAGE_SIZE), nbPagesStack, FALSE);
|
|
||||||
|
|
||||||
// Rest of kernel code
|
// Rest of kernel code
|
||||||
int nbPagesKernelCode = DIV_ROUND_UP((lastUsed - stackTop), PAGE_SIZE);
|
areaAdd(stackTop, lastUsed, FALSE);
|
||||||
areaAdd(ALIGN_DOWN(stackTop, PAGE_SIZE), nbPagesKernelCode, FALSE);
|
|
||||||
|
|
||||||
// Rest of virtual mem is free
|
// Rest of virtual mem is free
|
||||||
int nbFreePages = DIV_ROUND_UP((AREA_MEM_TOP - areaAddr), PAGE_SIZE);
|
areaAdd(areaAddr + PAGE_SIZE, AREA_MEM_TOP, TRUE);
|
||||||
areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), nbFreePages, TRUE);
|
|
||||||
|
|
||||||
// Create allocBank for the rest of the system
|
// Create allocBank for the rest of the system
|
||||||
allocPopulate();
|
allocPopulate();
|
||||||
@ -122,16 +118,22 @@ vaddr_t areaAlloc(unsigned int nbPages, uint32_t flags)
|
|||||||
return allocated->startAddr;
|
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;
|
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));
|
struct memArea *newArea = (struct memArea *)malloc(sizeof(struct memArea));
|
||||||
if (!newArea)
|
if (!newArea)
|
||||||
return (vaddr_t)NULL;
|
return (vaddr_t)NULL;
|
||||||
|
|
||||||
newArea->nbPages = nbPages;
|
newArea->nbPages = nbPages;
|
||||||
newArea->startAddr = addr;
|
newArea->startAddr = start;
|
||||||
|
|
||||||
if (isFree) {
|
if (isFree) {
|
||||||
area = &freeArea;
|
area = &freeArea;
|
||||||
|
@ -19,4 +19,4 @@ struct memArea {
|
|||||||
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stack_bottom, vaddr_t stack_top);
|
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);
|
vaddr_t areaAlloc(unsigned int nbPages, uint32_t flags);
|
||||||
int areaFree(vaddr_t addr);
|
int areaFree(vaddr_t addr);
|
||||||
int areaAdd(vaddr_t addr, uint nbPages, int isFree);
|
int areaAdd(vaddr_t begin, vaddr_t end, int isFree);
|
||||||
|
Loading…
Reference in New Issue
Block a user