From a023b91b01dc72729fd0c085c48915e6f9f7073f Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 15 May 2019 21:02:16 +0200 Subject: [PATCH] Page Fault test --- Makefile | 20 +++++--------------- kaleid/kernel/mm/paging.c | 7 +++---- kaleid/kernel/sh/shcmds.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index cc6223b..7e44091 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ # Debug mode ?= debug +ram ?= 8G # Programs ASM=nasm @@ -202,26 +203,17 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR) @echo ${CL2}[$@] ${CL}Compiled.${CL3} test: all - @qemu-system-x86_64 -cpu core2duo -soundhw pcspk -rtc base=localtime -m 4G -hda $(BUILDDIR)/bin/disk.img \ + @qemu-system-x86_64 -cpu core2duo -soundhw pcspk -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & test32: all - @qemu-system-i386 -hda $(BUILDDIR)/bin/disk.img -d \ + @qemu-system-i386 -m $(ram) -hda $(BUILDDIR)/bin/disk.img -d \ cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & -debug: all - @setsid qemu-system-x86_64 -soundhw pcspk -rtc base=localtime -m 64M \ - -hda $(BUILDDIR)/bin/disk.img -no-reboot -no-shutdown -d \ - cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > $(BUILDDIR)/kaleid64_disasm.asm - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > $(BUILDDIR)/kaleid32_disasm.asm - gdb: all - @setsid qemu-system-x86_64 -m 64M -soundhw pcspk -rtc base=localtime \ + @setsid qemu-system-x86_64 -m $(ram) -soundhw pcspk -rtc base=localtime \ -hda $(BUILDDIR)/bin/disk.img -no-reboot -no-shutdown -d \ cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > kaleid64_disasm.asm - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > kaleid32_disasm.asm @gdb \ -ex "set arch i386:x86-64:intel" \ -ex "target remote localhost:1234" \ @@ -229,10 +221,8 @@ gdb: all -ex "break BtStartKern" \ ddd: all - @setsid qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \ + @setsid qemu-system-x86_64 -m $(ram) -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \ -no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log & - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > kaleid64_disasm.asm - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > kaleid32_disasm.asm @ddd install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 84f1dc6..10ddbe0 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -49,20 +49,19 @@ volatile pte_t MmPT[512 * NB_4K] __attribute__((__aligned__(4096)));; 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)); memzero((void *)&MmPT[0], sizeof(MmPT)); for (int i = 0; i < 512 * NB_4K; i++) { - // STACK GUARD PAGE if ((ulong)i*4096 == (ulong)BtLoaderInfo.stackEndAddr) { MmPT[i] = ((ulong)i * 4096); @@ -93,7 +92,7 @@ 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; + MmPD[i] = ((ulong)i * 2048 * 1024) | MF_READWRITE;// | MF_NX; continue; } @@ -106,5 +105,5 @@ void MmInitPaging(void) 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 b48e50a..eaed746 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -224,7 +224,13 @@ error_t CmdDie(int argc, char **argv, char *cmdline) error_t CmdPF(int argc, char **argv, char *cmdline) { - *((char*)BtLoaderInfo.stackEndAddr + 16) = 1; + if (argc != 2) + return EINVAL; + + ulong address = atoul(argv[1]); + KernLog("print: %s, %d\n", argv[1], address); + + *((char*)address) += 1; return EOK; } @@ -248,7 +254,7 @@ Command_t cmdtable[] = { "march", CmdStarWars, "Play the Imperial March"}, { "mmap", CmdMemMap, "Show memory map" }, { "musage", CmdMemUsage, "Show memory statistics" }, - { "pfault", CmdPF, "Provoke a PF" }, + { "pfault", CmdPF, "Provoke a PF. Usage : pfault
" }, { "pstest", CmdPsTest, "Scheduler test routine" }, { "quit", CmdQuit, "Alias for 'exit'" }, { "so", CmdStackOverflow, "Provoke a stack overflow" },