Crashdump yay

This commit is contained in:
Adrien Bourmault 2019-05-19 00:07:01 +02:00
parent 8ba2a74937
commit ec83428ec1
6 changed files with 104 additions and 21 deletions

View File

@ -33,6 +33,11 @@
// IRQ-related stuff //
//------------------------------------------//
//
// Launch interrupt
//
#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory")
//
// Returns whether IRQs are enabled
//

View File

@ -23,7 +23,6 @@
//----------------------------------------------------------------------------//
#include "init.h"
#include <io/vga.h>
void MmInitPaging(void);
void MmActivatePageHandler(void);
@ -33,6 +32,8 @@ void MmActivatePageHandler(void);
//
noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
{
KeDisableIRQs();
// Initialize the BootInfo_t structure
BtInitBootInfo(mbInfo, codeSeg);
@ -41,8 +42,13 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoEnableCursor();
IoUpdateCursor(0, 0);
KernLog("%C%c%c%c OS/K%C\n\n", VGA_COLOR_WHITE,
219, 219, 219, VGA_COLOR_LIGHT_GREY);
KernLog("%C%c%c%c OS/K\n\n%C",
VGA_COLOR_WHITE,
219,
219,
219,
VGA_COLOR_LIGHT_GREY
);
// Sanity checks
BtDoSanityChecks(mbMagic);
@ -56,21 +62,12 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Interrupts launching
KeSetupIDT();
KeEnableIRQs();
// Start drivers
KeEnableRTC();
IoEnableKeyb();
MmActivatePageHandler();
KernLog("\n%CThis %Cis %Ca %CColor %Ctest%C...%C\n",
VGA_COLOR_LIGHT_BLUE,
VGA_COLOR_BROWN,
VGA_COLOR_MAGENTA,
VGA_COLOR_LIGHT_GREEN,
VGA_COLOR_RED,
VGA_COLOR_DARK_GREY,
VGA_COLOR_LIGHT_GREY);
KeStartShell();
PoShutdown();

View File

@ -32,6 +32,7 @@
#include <po/shtdwn.h>
#include <mm/heap.h>
#include <mm/mm.h>
#include <io/vga.h>
// info.c
extern void BtDoSanityChecks(uint mbMagic);

View File

@ -25,6 +25,7 @@
#include <lib/buf.h>
#include <init/boot.h>
#include <ke/idt.h>
#include <io/vga.h>
IdtEntry_t idt[256] = { 0 };
IdtPtr_t _KeIdtPtr;
@ -68,8 +69,7 @@ static char *ExceptionsChar[32] = {
static void EnablePIC(void);
static void EarlyExceptionHandler(ISRFrame_t *regs);
#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory")
static void BreakPointHandler(ISRFrame_t *regs);
//
// Registers an isr with his IRQ to handle driver interrupts
@ -173,6 +173,8 @@ void KeSetupIDT(void)
KeRegisterISR(EarlyExceptionHandler, i);
}
KeRegisterISR(BreakPointHandler, 0x3);
// Load IDT
KeLoadIDT();
DebugLog("\tInterrupt table initialized at %p\n", _KeIdtPtr.base);
@ -275,8 +277,8 @@ void _KeHandleISR(ISRFrame_t *regs)
//
static void EarlyExceptionHandler(ISRFrame_t *regs)
{
KeStartPanic("[ISR 0x%x] Irrecoverable Kernel %s\n\n"
" Error code : 0x%x (%b)\n\n"
bprintf(BStdOut, "\n\n%CPANIC\n%C[ISR 0x%x] Irrecoverable Kernel %s\n\n"
" Error code : 0x%x (%b)\n\n%C"
" RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n"
@ -292,10 +294,13 @@ static void EarlyExceptionHandler(ISRFrame_t *regs)
" R14: %#016lx R15: %#016lx \n\n"
" RFLAGS: %#022b (%#06x)",
VGA_COLOR_WHITE,
VGA_COLOR_LIGHT_RED,
regs->intNo,
ExceptionsChar[regs->intNo],
regs->ErrorCode,
regs->ErrorCode,
VGA_COLOR_WHITE,
regs->rip,
regs->rsp,
regs->rbp,
@ -324,4 +329,63 @@ static void EarlyExceptionHandler(ISRFrame_t *regs)
regs->rflags,
regs->rflags
);
bputc(BStdOut, '\n');
BStdOut->flusher(BStdOut);
KeHaltCPU();
}
static void BreakPointHandler(ISRFrame_t *regs)
{
bprintf(BStdOut, "\n\n"
"%C RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n"
" SS: %#016lx CS: %#016lx CR0: %#016lx\n"
" CR2: %#016lx CR3: %#016lx CR4: %#016lx\n"
" CR8: %#016lx EFE: %#016lx \n\n"
" RAX: %#016lx RBX: %#016lx RCX: %#016lx\n"
" RDX: %#016lx RSI: %#016lx RDI: %#016lx\n"
" R8: %#016lx R9: %#016lx R10: %#016lx\n"
" R11: %#016lx R12: %#016lx R13: %#016lx\n"
" R14: %#016lx R15: %#016lx \n\n"
" RFLAGS: %#022b (%#06x)",
VGA_COLOR_WHITE,
regs->rip,
regs->rsp,
regs->rbp,
regs->ss,
regs->cs,
regs->cr0,
regs->cr2,
regs->cr3,
regs->cr4,
regs->cr8,
regs->efer,
regs->rax,
regs->rbx,
regs->rcx,
regs->rdx,
regs->rsi,
regs->rdi,
regs->r8,
regs->r9,
regs->r10,
regs->r11,
regs->r12,
regs->r13,
regs->r14,
regs->r15,
regs->rflags,
regs->rflags
);
bputc(BStdOut, '\n');
BStdOut->flusher(BStdOut);
}

View File

@ -24,6 +24,7 @@
#include <lib/buf.h>
#include <ke/proc.h>
#include <io/vga.h>
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
@ -70,13 +71,16 @@ noreturn void KeStartPanic(const char *fmt, ...)
// We don't check vbprintf's output
// If it fails, what could we do anyway?
bprintf(BStdOut, "%C\nPANIC\n%C", VGA_COLOR_WHITE, VGA_COLOR_LIGHT_RED);
bprintf(BStdOut, "\nPANIC\n");
va_start(ap, fmt);
vbprintf(BStdOut, fmt, ap);
va_end(ap);
interrupt(0x3);
bputc(BStdOut, '\n');
BStdOut->flusher(BStdOut);

View File

@ -3,6 +3,9 @@
#include <ex/malloc.h>
#include <mm/mm.h>
#include <ke/idt.h>
#include <lib/buf.h>
#include <io/vga.h>
#define KPAGESIZE (4 * KB)
#define UPAGESIZE (2 * MB)
@ -164,8 +167,8 @@ void MmReloadPaging(void)
//
static void PagingHandler(ISRFrame_t *regs)
{
KeStartPanic("[ISR 0x%x] Irrecoverable Kernel Page Fault at %p\n\n"
" Error code : 0x%x (%b)\n\n"
bprintf(BStdOut, "\n\n%CPANIC\n%C[ISR 0x%x] Irrecoverable Kernel Page Fault at %p\n\n"
" Error code : 0x%x (%b)\n\n%C"
" RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n"
@ -181,10 +184,13 @@ static void PagingHandler(ISRFrame_t *regs)
" R14: %#016lx R15: %#016lx \n\n"
" RFLAGS: %#022b (%#06x)",
VGA_COLOR_WHITE,
VGA_COLOR_LIGHT_RED,
regs->intNo,
regs->cr2,
regs->ErrorCode,
regs->ErrorCode,
VGA_COLOR_WHITE,
regs->rip,
regs->rsp,
regs->rbp,
@ -213,6 +219,12 @@ static void PagingHandler(ISRFrame_t *regs)
regs->rflags,
regs->rflags
);
bputc(BStdOut, '\n');
BStdOut->flusher(BStdOut);
KeHaltCPU();
}
void MmActivatePageHandler(void)