From 7b9ceba6b25893e453d8a31d846cdafd21bf3e45 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 28 Oct 2021 00:32:35 +0200 Subject: [PATCH] Give stack information to area --- core/allocArea.c | 12 +++++++++--- core/allocArea.h | 2 +- core/main.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/allocArea.c b/core/allocArea.c index 6294df7..a30b60c 100644 --- a/core/allocArea.c +++ b/core/allocArea.c @@ -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(); diff --git a/core/allocArea.h b/core/allocArea.h index a2030c0..5a7618a 100644 --- a/core/allocArea.h +++ b/core/allocArea.h @@ -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); diff --git a/core/main.c b/core/main.c index cda08ef..4a5c249 100644 --- a/core/main.c +++ b/core/main.c @@ -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();