user_space #4

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

View File

@ -12,7 +12,9 @@ static struct memArea *usedArea;
static int areaMergeFreeArea(struct memArea *prev, struct memArea *next); 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(freeArea);
list_init(usedArea); list_init(usedArea);
@ -25,8 +27,12 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed)
if (areaAddr != descAddr && areaAddr != entryAddr) if (areaAddr != descAddr && areaAddr != entryAddr)
areaAdd(areaAddr, 1, FALSE); areaAdd(areaAddr, 1, FALSE);
int nbPages = DIV_ROUND_UP((lastUsed - firstMemUsed), PAGE_SIZE); int nbPagesKernel = DIV_ROUND_UP((lastUsed - firstMemUsed), PAGE_SIZE);
areaAdd(ALIGN_DOWN(firstMemUsed, PAGE_SIZE), nbPages, FALSE); 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 //TODO: fix the 300
areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), 300 , TRUE); areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), 300 , TRUE);
allocPopulate(); allocPopulate();

View File

@ -15,7 +15,7 @@ struct memArea {
struct memArea *prev; 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); 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 addr, uint nbPages, int isFree);

View File

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