user_space #4
@ -28,7 +28,7 @@ align 4
|
||||
; stack is properly aligned and failure to align the stack will result in
|
||||
; undefined behavior.
|
||||
section .bss
|
||||
align 16
|
||||
align 4096
|
||||
stack_bottom:
|
||||
resb 16384 ; 16 KiB
|
||||
stack_top:
|
||||
|
@ -6,14 +6,11 @@
|
||||
#include "mem.h"
|
||||
#include "stdarg.h"
|
||||
|
||||
|
||||
static struct memArea *freeArea;
|
||||
static struct memArea *usedArea;
|
||||
|
||||
static int areaMergeFreeArea(struct memArea *prev, struct memArea *next);
|
||||
|
||||
|
||||
//Kernel stack is inside firstMemUsed-lastUsed
|
||||
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr_t stackTop)
|
||||
{
|
||||
list_init(freeArea);
|
||||
@ -27,14 +24,23 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr
|
||||
if (areaAddr != descAddr && areaAddr != entryAddr)
|
||||
areaAdd(areaAddr, 1, FALSE);
|
||||
|
||||
int nbPagesKernel = DIV_ROUND_UP((lastUsed - firstMemUsed), PAGE_SIZE);
|
||||
//kernel bootstrap part
|
||||
int nbPagesKernel = DIV_ROUND_UP((stackBottom - 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);
|
||||
}
|
||||
|
||||
//Initial kernel stack
|
||||
int nbPagesStack = DIV_ROUND_UP((stackTop - stackBottom), PAGE_SIZE);
|
||||
areaAdd(ALIGN_DOWN(stackBottom, PAGE_SIZE), nbPagesStack, FALSE);
|
||||
|
||||
// Rest of kernel code
|
||||
int nbPagesKernelCode = DIV_ROUND_UP((lastUsed - stackTop), PAGE_SIZE);
|
||||
areaAdd(ALIGN_DOWN(stackTop, PAGE_SIZE), nbPagesKernelCode, 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(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), nbFreePages, TRUE);
|
||||
|
||||
// Create allocBank for the rest of the system
|
||||
allocPopulate();
|
||||
}
|
||||
|
||||
@ -183,9 +189,11 @@ int areaFree(vaddr_t addr)
|
||||
pr_info("Cannot find memArea associated to %p\n", addr);
|
||||
return -1;
|
||||
}
|
||||
for(uint i = 0; i < area->nbPages; i++){
|
||||
pageUnmap( area->startAddr + i * PAGE_SIZE);
|
||||
|
||||
for (uint i = 0; i < area->nbPages; i++) {
|
||||
pageUnmap(area->startAddr + i * PAGE_SIZE);
|
||||
}
|
||||
|
||||
list_delete(usedArea, area);
|
||||
insertSorted(&freeArea, area);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user