Page Fault test

This commit is contained in:
Adrien Bourmault 2019-05-15 21:02:16 +02:00
parent 96dd593b88
commit a023b91b01
3 changed files with 16 additions and 21 deletions

View File

@ -29,6 +29,7 @@
# Debug # Debug
mode ?= debug mode ?= debug
ram ?= 8G
# Programs # Programs
ASM=nasm ASM=nasm
@ -202,26 +203,17 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR)
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
test: all 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 & -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
test32: all 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 & 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 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 \ -hda $(BUILDDIR)/bin/disk.img -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & 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 \ @gdb \
-ex "set arch i386:x86-64:intel" \ -ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \ -ex "target remote localhost:1234" \
@ -229,10 +221,8 @@ gdb: all
-ex "break BtStartKern" \ -ex "break BtStartKern" \
ddd: all 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 & -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 @ddd
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg

View File

@ -49,20 +49,19 @@ volatile pte_t MmPT[512 * NB_4K] __attribute__((__aligned__(4096)));;
volatile ulong MmStackGuards[2] = { 0 }; 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; extern MemoryMap_t memoryMap;
uint phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; 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));
memzero((void *)&MmPT[0], sizeof(MmPT)); memzero((void *)&MmPT[0], sizeof(MmPT));
for (int i = 0; i < 512 * NB_4K; i++) { for (int i = 0; i < 512 * NB_4K; i++) {
// STACK GUARD PAGE // STACK GUARD PAGE
if ((ulong)i*4096 == (ulong)BtLoaderInfo.stackEndAddr) { if ((ulong)i*4096 == (ulong)BtLoaderInfo.stackEndAddr) {
MmPT[i] = ((ulong)i * 4096); MmPT[i] = ((ulong)i * 4096);
@ -93,7 +92,7 @@ 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 // ENOMEM like
if ((ulong)i* 2048 * 1024 > (ulong)phRamSize) { 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; continue;
} }
@ -106,5 +105,5 @@ void MmInitPaging(void)
MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE; MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE;
MmLoadPML4((void *)MmPML4); //MmLoadPML4((void *)MmPML4);
} }

View File

@ -224,7 +224,13 @@ error_t CmdDie(int argc, char **argv, char *cmdline)
error_t CmdPF(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; return EOK;
} }
@ -248,7 +254,7 @@ Command_t cmdtable[] =
{ "march", CmdStarWars, "Play the Imperial March"}, { "march", CmdStarWars, "Play the Imperial March"},
{ "mmap", CmdMemMap, "Show memory map" }, { "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "pfault", CmdPF, "Provoke a PF" }, { "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" },
{ "pstest", CmdPsTest, "Scheduler test routine" }, { "pstest", CmdPsTest, "Scheduler test routine" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "so", CmdStackOverflow, "Provoke a stack overflow" }, { "so", CmdStackOverflow, "Provoke a stack overflow" },