diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 73e26d3..12d3792 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -63,13 +63,15 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // Memory MmInitMemoryMap(); MmInitGdt(); - MmInitHeap(); - MmInitPaging(); - // IDT + // Interrupts KeSetupIDT(); KeEnableIRQs(); + // Memory (2) + MmInitHeap(); + MmInitPaging(); + // Interrupt handlers MmActivatePageHandler(); KeEnableRTC(); diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index 251cf7a..d6fc0fc 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -26,7 +26,6 @@ #include #include #include -#include #include IdtEntry_t idt[256] = { 0 }; diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index af127e2..0bfd06f 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -11,7 +11,8 @@ //----------- -volatile pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE))); +static pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE))); +static ulong *MmPhysicalPageTable; extern ulong _text; extern ulong _text_end; @@ -51,6 +52,7 @@ void MmInitPaging(void) ulong lastKernelAddr = (ulong)(_heap_start + _heap_max); ulong firstDirectoryAddr = 0; ulong lastDirectoryAddr = 0; + ulong phDirSize = 0; // Maximum PHYSICAL address in memory ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; @@ -64,6 +66,10 @@ void MmInitPaging(void) //DebugLog("\tPaging gap : %u MB (%p)\n\tLast virtual address %p\n", diffKernUsr / MB, diffKernUsr, MmVirtLastAddress); memzero((void *)&MmPageMapLevel4[0], sizeof(MmPageMapLevel4)); + phDirSize = (phRamSize / KPAGESIZE)*sizeof(ulong); + + //MmPhysicalPageTable = (ulong*)malloc((phRamSize / KPAGESIZE)*sizeof(ulong)); + DebugLog("\t\tRam %u MB, pagesize %u KB, size %u MB\n", phRamSize / MB, KPAGESIZE / KB, phDirSize / MB); for (ulong curAddrPML4 = 0; curAddrPML4 < MmVirtLastAddress; @@ -157,6 +163,7 @@ void MmInitPaging(void) // While we're inside the userspace pages else if ((ulong)curAddrPT >= USERSPACE) { MmPT[index] = ((ulong)curAddrPT - diffKernUsr) | PRESENT; // Not present for instance + //MmPhysicalPageTable[(ulong)curAddrPT - diffKernUsr] = curAddrPT; if ((ulong)curAddrPT == USERSPACE) { DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr); @@ -174,9 +181,9 @@ void MmInitPaging(void) lastDirectoryAddr = (ulong)MmPT; MmLoadPML4((void *)MmPageMapLevel4); - MmEnableWriteProtect(); - DebugLog("\tPage table size : %u MB\n", (lastDirectoryAddr - firstDirectoryAddr)/MB); + + DebugLog("\tPage table size : %u MB\n", (lastDirectoryAddr - firstDirectoryAddr + phDirSize)/MB); } // @@ -221,7 +228,7 @@ void *MmTransVirtToPhyAddr(void* virtualAddr) void *MmTransPhyToVirtAddr(void* physicalAddr) { - return (void*)0; + return (void*)MmPhysicalPageTable[(ulong)physicalAddr]; } // @@ -272,6 +279,28 @@ void MmUnmapPage(void* virtualAddr) KeFlushTlbSingle(*page); } +// +// Kernel Page allocator +// +void *MmKAllocPageBlock(void *start) { + pte_t *startPage = MmGetPageDescriptorFromVirtual(start); + + //for (ulong curPage = 0; curPage < ) + + return NULL; +} + +// +// User page allocator +// +void *MmUAllocPageBlock(void *start) { + pte_t *startPage = MmGetPageDescriptorFromVirtual(start); + + //for (ulong curPage = 0; curPage < ) + + return NULL; +} + //----------- //