Working static paging

This commit is contained in:
Adrien Bourmault 2019-05-15 19:11:47 +02:00
parent bee9793a8b
commit 96dd593b88
2 changed files with 18 additions and 12 deletions

View File

@ -48,15 +48,13 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Memory // Memory
MmInitMemoryMap(); MmInitMemoryMap();
MmInitHeap();
MmInitPaging(); MmInitPaging();
// Interrupts launching // Interrupts launching
KeSetupIDT(); KeSetupIDT();
KeEnableIRQs(); KeEnableIRQs();
// Several inits
MmInitHeap();
// Start drivers // Start drivers
KeEnableRTC(); KeEnableRTC();
IoEnableKeyb(); IoEnableKeyb();

View File

@ -1,5 +1,7 @@
#include <kernel.h> #include <kernel.h>
#include <init/boot.h> #include <init/boot.h>
#include <ex/malloc.h>
#include <mm/mm.h>
#define PAGESIZE (4 * KB) #define PAGESIZE (4 * KB)
@ -32,7 +34,8 @@ enum
}; };
#define RAM_MAX 16 #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 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 }; volatile ulong MmStackGuards[2] = { 0 };
@ -51,6 +54,8 @@ volatile ulong MmStackGuards[2] = { 0 };
// Creates our new page table structure and loads it // Creates our new page table structure and loads it
void MmInitPaging(void) void MmInitPaging(void)
{ {
extern MemoryMap_t memoryMap;
uint phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
memzero((void *)&MmPML4[0], sizeof(MmPML4)); memzero((void *)&MmPML4[0], sizeof(MmPML4));
memzero((void *)&MmPDP[0], sizeof(MmPDP)); memzero((void *)&MmPDP[0], sizeof(MmPDP));
memzero((void *)&MmPD[0], sizeof(MmPD)); memzero((void *)&MmPD[0], sizeof(MmPD));
@ -65,12 +70,9 @@ void MmInitPaging(void)
continue; continue;
} }
// STACK PAGES // ENOMEM like
if ( if ((ulong)i*4096 > (ulong)phRamSize) {
(ulong)i*4096 < (ulong)BtLoaderInfo.stackEndAddr && MmPT[i] = ((ulong)i * 4096) | MF_READWRITE;// | MF_NX;
(ulong)i*4096 > (ulong)BtLoaderInfo.kernelEndAddr
) {
MmPT[i] = ((ulong)i * 4096) | MF_PRESENT | MF_READWRITE;// | MF_NX;
continue; continue;
} }
@ -89,6 +91,12 @@ void MmInitPaging(void)
} }
for (int i = NB_4K; i < 512 * RAM_MAX; i++) { 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; MmPD[i] = ((ulong)i * 2048 * 1024) | MF_PRESENT | MF_READWRITE | MF_HUGE;
} }