From 2681fec9240dbcfb3ccda0ccc876fad32b83ec61 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 29 Dec 2019 02:11:11 +0200 Subject: [PATCH] Dump more information about page faults in userspace --- sys/amd64/hw/pfault.c | 30 +++++++++++++++++++++++++----- usr/Makefile | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/sys/amd64/hw/pfault.c b/sys/amd64/hw/pfault.c index 33cb953..7742fc4 100644 --- a/sys/amd64/hw/pfault.c +++ b/sys/amd64/hw/pfault.c @@ -6,22 +6,42 @@ extern void amd64_syscall_yield_stopped(); int amd64_pfault(uintptr_t cr2) { + // TODO: would be nice to get error code off the stack and check what kind of + // error happened struct cpu *cpu = get_cpu(); _assert(cpu); struct thread *thr = cpu->thread; - kdebug("Page fault in %s thread %u\n", + _assert(thr); + + struct cpu_context *ctx = (struct cpu_context *) thr->data.rsp0; + + kerror("Page fault in %s thread %u\n", thr->flags & THREAD_KERNEL ? "kernel" : "user", thr->pid); - kdebug("CR2 = %p\n", cr2); + kerror("CR2 = %p\n", cr2); + + // Dump registers + kerror("RAX = %p, RCX = %p\n", ctx->rax, ctx->rcx); + kerror("RDX = %p, RBX = %p\n", ctx->rdx, ctx->rbx); + kerror("RSP = %p, RBP = %p\n", ctx->rsp, ctx->rbp); + kerror("RSI = %p, RDI = %p\n", ctx->rsi, ctx->rdi); + kerror(" R8 = %p, R9 = %p\n", ctx->r8, ctx->r9); + kerror("R10 = %p, R11 = %p\n", ctx->r10, ctx->r11); + kerror("R12 = %p, R13 = %p\n", ctx->r12, ctx->r13); + kerror("R14 = %p, R15 = %p\n", ctx->r12, ctx->r15); + + // Can't access IRET-registers (CS/RIP and the likes) + // because they're presumably fucked up by error code + // push amd64_syscall_yield_stopped(); return -1; } void amd64_pfault_kernel(uintptr_t rip, uintptr_t cr2) { - kdebug("Kernel-space page fault:\n"); - kdebug("RIP = %p\n", rip); - kdebug("CR2 = %p\n", cr2); + kfatal("Kernel-space page fault:\n"); + kfatal("RIP = %p\n", rip); + kfatal("CR2 = %p\n", cr2); } diff --git a/usr/Makefile b/usr/Makefile index 35b4847..787bbf0 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -13,6 +13,7 @@ CFLAGS=-ffreestanding \ -mno-sse \ -mno-sse2 \ -Ilibc/include \ + -ggdb \ -O0 \ -I$(S)/include