From 4f3bda6ec271749b42241f0949c3a80c82fefbb8 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 16 May 2019 23:56:23 +0200 Subject: [PATCH] Correcting dynamic paging --- Makefile | 4 ++-- boot/loader/mem/management.inc | 2 +- kaleid/kernel/init/init.c | 2 +- kaleid/kernel/mm/paging.c | 37 +++++++++++++++++----------------- kaleid/kernel/sh/shcmds.c | 29 +++++++++++++++++++++----- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 7e44091..5a63c8f 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ # Debug mode ?= debug -ram ?= 8G +ram ?= 4G # Programs ASM=nasm @@ -203,7 +203,7 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR) @echo ${CL2}[$@] ${CL}Compiled.${CL3} test: all - @qemu-system-x86_64 -cpu core2duo -soundhw pcspk -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \ + @qemu-system-x86_64 -cpu core2duo -soundhw pcspk -s -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & test32: all diff --git a/boot/loader/mem/management.inc b/boot/loader/mem/management.inc index f3ae8d6..d86345f 100644 --- a/boot/loader/mem/management.inc +++ b/boot/loader/mem/management.inc @@ -23,7 +23,7 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -%define MAX_MEMORY 4 ; GiB +%define MAX_MEMORY 1 ; GiB [BITS 32] [section .text] diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 15f3333..9af0beb 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -48,8 +48,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // Memory MmInitMemoryMap(); - MmInitHeap(); MmInitPaging(); + MmInitHeap(); // Interrupts launching KeSetupIDT(); diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 10ddbe0..6d82fe0 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -33,7 +33,7 @@ enum MF_NX = 1 << 31 }; -#define RAM_MAX 16 +#define RAM_MAX 32 #define NB_4K 150 // * 2 MB @@ -54,56 +54,55 @@ volatile ulong MmStackGuards[2] = { 0 }; void MmInitPaging(void) { extern MemoryMap_t memoryMap; - uint phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; + ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; memzero((void *)&MmPML4[0], sizeof(MmPML4)); memzero((void *)&MmPDP[0], sizeof(MmPDP)); memzero((void *)&MmPD[0], sizeof(MmPD)); memzero((void *)&MmPT[0], sizeof(MmPT)); - for (int i = 0; i < 512 * NB_4K; i++) { + for (volatile ulong i = 0; i < 512 * NB_4K; i++) { // STACK GUARD PAGE - if ((ulong)i*4096 == (ulong)BtLoaderInfo.stackEndAddr) { - MmPT[i] = ((ulong)i * 4096); + if ((ulong)(i*4096) == (ulong)BtLoaderInfo.stackEndAddr) { + MmPT[i] = ((ulong)(i*4096)); MmStackGuards[0] = i; continue; } // ENOMEM like - if ((ulong)i*4096 > (ulong)phRamSize) { - MmPT[i] = ((ulong)i * 4096) | MF_READWRITE;// | MF_NX; - continue; + if ((ulong)(i*4096) > (ulong)phRamSize) { + break; } // STACK GARD PAGE - if ((ulong)i*4096 == (ulong)BtLoaderInfo.kernelEndAddr) { - MmPT[i] = ((ulong)i * 4096); + if ((ulong)(i*4096) == (ulong)BtLoaderInfo.kernelEndAddr) { + MmPT[i] = ((ulong)(i*4096)); MmStackGuards[1] = i; continue; } - MmPT[i] = ((ulong)i * 4096) | MF_PRESENT | MF_READWRITE; + MmPT[i] = ((ulong)(i*4096)) | MF_PRESENT | MF_READWRITE; } - for (int i = 0; i < NB_4K; i++) { + for (volatile ulong i = 0; i < NB_4K; i++) { MmPD[i] = (ulong)(&MmPT[i*512])| MF_PRESENT | MF_READWRITE; } - for (int i = NB_4K; i < 512 * RAM_MAX; i++) { + for (volatile ulong i = NB_4K; i < 512 * RAM_MAX; i++) { // ENOMEM like - if ((ulong)i* 2048 * 1024 > (ulong)phRamSize) { - MmPD[i] = ((ulong)i * 2048 * 1024) | MF_READWRITE;// | MF_NX; - continue; + if ((ulong)(i* 2048 * 1024) > (ulong)phRamSize) { + break; } - MmPD[i] = ((ulong)i * 2048 * 1024) | MF_PRESENT | MF_READWRITE | MF_HUGE; + MmPD[i] = 0; + MmPD[i] = ((ulong)(i* 2048 * 1024)) | MF_PRESENT | MF_READWRITE | MF_HUGE; } - for (int i = 0; i < RAM_MAX; i++) { + for (volatile int i = 0; i < RAM_MAX; i++) { MmPDP[i] = (ulong)(&MmPD[i*512])| MF_PRESENT | MF_READWRITE; } MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE; - //MmLoadPML4((void *)MmPML4); + MmLoadPML4((void *)MmPML4); } diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index eaed746..365b595 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -224,13 +224,31 @@ error_t CmdDie(int argc, char **argv, char *cmdline) error_t CmdPF(int argc, char **argv, char *cmdline) { - if (argc != 2) - return EINVAL; + /* if (argc != 2) */ + /* return EINVAL; */ - ulong address = atoul(argv[1]); - KernLog("print: %s, %d\n", argv[1], address); + /* ulong address = atoul(argv[1]); */ + /* KernLog("print: %s, %d\n", argv[1], address); */ - *((char*)address) += 1; + /* *((char*)address) += 1; */ + + *((char*)(1*GB)) += 1; + KernLog("1GB "); + *((char*)(2*GB)) += 1; + KernLog("2GB "); + *((char*)(3*GB)) += 1; + KernLog("3GB "); + *((char*)(4*GB)) += 1; + KernLog("4GB "); + + return EOK; +} + +void MmInitPaging(void); + +error_t CmdReloadPage(int argc, char **argv, char *cmdline) +{ + MmInitPaging(); return EOK; } @@ -251,6 +269,7 @@ Command_t cmdtable[] = { "die", CmdDie, "Die painfully" }, { "exit", CmdQuit, "Initiate shutdown" }, { "help", CmdHelp, "Show this message" }, + { "rpag", CmdReloadPage, "Reload the pages directory" }, { "march", CmdStarWars, "Play the Imperial March"}, { "mmap", CmdMemMap, "Show memory map" }, { "musage", CmdMemUsage, "Show memory statistics" },