diff --git a/arch/x86/paging.c b/arch/x86/paging.c index 8b4ef08..666e0c3 100644 --- a/arch/x86/paging.c +++ b/arch/x86/paging.c @@ -25,20 +25,6 @@ #define PD_SHIFT 22 #define PD_MIRROR_PAGE_IDX 1023U -/** Frontier between kernel and user space virtual addresses */ -#define PAGING_BASE_USER_ADDRESS (0x40000000) /* 1GB (must be 4MB-aligned) */ -#define PAGING_TOP_USER_ADDRESS (0xFFFFFFFF) /* 4GB - 1B */ -#define PAGING_USER_SPACE_SIZE (0xc0000000) /* 3GB */ - -/** Length of the space reserved for the mirroring in the kernel - virtual space */ -#define PAGING_MIRROR_SIZE (PAGE_SIZE << 10) /* 1 PD = 1024 Page Tables = 4MB */ - -/** Virtual address where the mirroring takes place */ -#define PAGING_MIRROR_VADDR \ - (PAGING_BASE_USER_ADDRESS - PAGING_MIRROR_SIZE) - - static unsigned long mappedPage = 0; struct pde { diff --git a/arch/x86/paging.h b/arch/x86/paging.h index a862432..717a046 100644 --- a/arch/x86/paging.h +++ b/arch/x86/paging.h @@ -1,6 +1,19 @@ #pragma once #include "types.h" +/** Frontier between kernel and user space virtual addresses */ +#define PAGING_BASE_USER_ADDRESS (0x40000000) /* 1GB (must be 4MB-aligned) */ +#define PAGING_TOP_USER_ADDRESS (0xFFFFFFFF) /* 4GB - 1B */ +#define PAGING_USER_SPACE_SIZE (0xc0000000) /* 3GB */ + +/** Length of the space reserved for the mirroring in the kernel + virtual space */ +#define PAGING_MIRROR_SIZE (PAGE_SIZE << 10) /* 1 PD = 1024 Page Tables = 4MB */ + +/** Virtual address where the mirroring takes place */ +#define PAGING_MIRROR_VADDR \ + (PAGING_BASE_USER_ADDRESS - PAGING_MIRROR_SIZE) + #define PAGING_MEM_USER (1U << 0) #define PAGING_MEM_READ (1U << 1) #define PAGING_MEM_WRITE (1U << 2) diff --git a/core/allocArea.c b/core/allocArea.c index a30b60c..4c5bb20 100644 --- a/core/allocArea.c +++ b/core/allocArea.c @@ -33,8 +33,8 @@ void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr 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); + int nbFreePages = DIV_ROUND_UP((AREA_MEM_TOP - areaAddr), PAGE_SIZE); + areaAdd(ALIGN_DOWN(areaAddr + PAGE_SIZE, PAGE_SIZE), nbFreePages , TRUE); allocPopulate(); } diff --git a/core/allocArea.h b/core/allocArea.h index 5a7618a..afa8674 100644 --- a/core/allocArea.h +++ b/core/allocArea.h @@ -6,6 +6,7 @@ // areaAlloc map vmem to phy pages #define AREA_PHY_MAP (1<<0) +#define AREA_MEM_TOP PAGING_MIRROR_VADDR struct memArea { vaddr_t startAddr;