From 96dd593b881707b18412b3727e86ff1500a85c06 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 15 May 2019 19:11:47 +0200 Subject: [PATCH] Working static paging --- kaleid/kernel/init/init.c | 4 +--- kaleid/kernel/mm/paging.c | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 5c2a9c2..15f3333 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -48,15 +48,13 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // Memory MmInitMemoryMap(); + MmInitHeap(); MmInitPaging(); // Interrupts launching KeSetupIDT(); KeEnableIRQs(); - // Several inits - MmInitHeap(); - // Start drivers KeEnableRTC(); IoEnableKeyb(); diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index b87920f..84f1dc6 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -1,5 +1,7 @@ #include #include +#include +#include #define PAGESIZE (4 * KB) @@ -32,7 +34,8 @@ enum }; #define RAM_MAX 16 -#define NB_4K 2 +#define NB_4K 150 + // * 2 MB //----------- @@ -40,9 +43,9 @@ volatile pdpe_t MmPML4[512] __attribute__((__aligned__(4096))); volatile pde_t MmPDP[512] __attribute__((__aligned__(4096))); -volatile pde_t MmPD[512 * RAM_MAX] __attribute__((__aligned__(4096))); +volatile pde_t MmPD[512 * RAM_MAX] __attribute__((__aligned__(4096)));; -volatile pte_t MmPT[512 * NB_4K] __attribute__((__aligned__(4096))); +volatile pte_t MmPT[512 * NB_4K] __attribute__((__aligned__(4096)));; volatile ulong MmStackGuards[2] = { 0 }; @@ -51,6 +54,8 @@ volatile ulong MmStackGuards[2] = { 0 }; // Creates our new page table structure and loads it void MmInitPaging(void) { + extern MemoryMap_t memoryMap; + uint phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; memzero((void *)&MmPML4[0], sizeof(MmPML4)); memzero((void *)&MmPDP[0], sizeof(MmPDP)); memzero((void *)&MmPD[0], sizeof(MmPD)); @@ -65,12 +70,9 @@ void MmInitPaging(void) continue; } - // STACK PAGES - if ( - (ulong)i*4096 < (ulong)BtLoaderInfo.stackEndAddr && - (ulong)i*4096 > (ulong)BtLoaderInfo.kernelEndAddr - ) { - MmPT[i] = ((ulong)i * 4096) | MF_PRESENT | MF_READWRITE;// | MF_NX; + // ENOMEM like + if ((ulong)i*4096 > (ulong)phRamSize) { + MmPT[i] = ((ulong)i * 4096) | MF_READWRITE;// | MF_NX; continue; } @@ -89,6 +91,12 @@ void MmInitPaging(void) } for (int i = NB_4K; i < 512 * RAM_MAX; i++) { + // ENOMEM like + if ((ulong)i* 2048 * 1024 > (ulong)phRamSize) { + MmPT[i] = ((ulong)i * 4096) | MF_READWRITE;// | MF_NX; + continue; + } + MmPD[i] = ((ulong)i * 2048 * 1024) | MF_PRESENT | MF_READWRITE | MF_HUGE; }