Give stack information to area

This commit is contained in:
Mathieu Maret 2021-10-28 00:32:35 +02:00
parent 9ae500f06e
commit 7b9ceba6b2
3 changed files with 11 additions and 5 deletions

View File

@ -12,7 +12,9 @@ static struct memArea *usedArea;
static int areaMergeFreeArea(struct memArea *prev, struct memArea *next);
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed)
//Kernel stack is inside firstMemUsed-lastUsed
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr_t stackTop)
{
list_init(freeArea);
list_init(usedArea);
@ -25,8 +27,12 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed)
if (areaAddr != descAddr && areaAddr != entryAddr)
areaAdd(areaAddr, 1, FALSE);
int nbPages = DIV_ROUND_UP((lastUsed - firstMemUsed), PAGE_SIZE);
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), nbPages, FALSE);
int nbPagesKernel = DIV_ROUND_UP((lastUsed - firstMemUsed), PAGE_SIZE);
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), nbPagesKernel, FALSE);
if(stackBottom > lastUsed){
int nbPagesStack = DIV_ROUND_UP((stackTop - stackBottom), PAGE_SIZE);
areaAdd(ALIGN_DOWN(stackBottom, PAGE_SIZE), nbPagesStack, FALSE);
}
//TODO: fix the 300
areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), 300 , TRUE);
allocPopulate();

View File

@ -15,7 +15,7 @@ struct memArea {
struct memArea *prev;
};
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed);
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);

View File

@ -161,7 +161,7 @@ void kmain(unsigned long magic, unsigned long addr)
serialSetup(115200);
printf("[Setup] allocation system\n");
areaInit(firstUsedByMem, lastUsedByMem);
areaInit(firstUsedByMem, lastUsedByMem, _stack_bottom, _stack_top);
cpu_context_subsystem_setup();