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 // // IRQ-related stuff //
//------------------------------------------// //------------------------------------------//
//
// Launch interrupt
//
#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory")
// //
// Returns whether IRQs are enabled // Returns whether IRQs are enabled
// //

View File

@ -23,7 +23,6 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include "init.h" #include "init.h"
#include <io/vga.h>
void MmInitPaging(void); void MmInitPaging(void);
void MmActivatePageHandler(void); void MmActivatePageHandler(void);
@ -33,6 +32,8 @@ void MmActivatePageHandler(void);
// //
noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
{ {
KeDisableIRQs();
// Initialize the BootInfo_t structure // Initialize the BootInfo_t structure
BtInitBootInfo(mbInfo, codeSeg); BtInitBootInfo(mbInfo, codeSeg);
@ -41,8 +42,13 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoEnableCursor(); IoEnableCursor();
IoUpdateCursor(0, 0); IoUpdateCursor(0, 0);
KernLog("%C%c%c%c OS/K%C\n\n", VGA_COLOR_WHITE, KernLog("%C%c%c%c OS/K\n\n%C",
219, 219, 219, VGA_COLOR_LIGHT_GREY); VGA_COLOR_WHITE,
219,
219,
219,
VGA_COLOR_LIGHT_GREY
);
// Sanity checks // Sanity checks
BtDoSanityChecks(mbMagic); BtDoSanityChecks(mbMagic);
@ -62,15 +68,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoEnableKeyb(); IoEnableKeyb();
MmActivatePageHandler(); 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(); KeStartShell();
PoShutdown(); PoShutdown();

View File

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

View File

@ -25,6 +25,7 @@
#include <lib/buf.h> #include <lib/buf.h>
#include <init/boot.h> #include <init/boot.h>
#include <ke/idt.h> #include <ke/idt.h>
#include <io/vga.h>
IdtEntry_t idt[256] = { 0 }; IdtEntry_t idt[256] = { 0 };
IdtPtr_t _KeIdtPtr; IdtPtr_t _KeIdtPtr;
@ -68,8 +69,7 @@ static char *ExceptionsChar[32] = {
static void EnablePIC(void); static void EnablePIC(void);
static void EarlyExceptionHandler(ISRFrame_t *regs); static void EarlyExceptionHandler(ISRFrame_t *regs);
static void BreakPointHandler(ISRFrame_t *regs);
#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory")
// //
// Registers an isr with his IRQ to handle driver interrupts // Registers an isr with his IRQ to handle driver interrupts
@ -173,6 +173,8 @@ void KeSetupIDT(void)
KeRegisterISR(EarlyExceptionHandler, i); KeRegisterISR(EarlyExceptionHandler, i);
} }
KeRegisterISR(BreakPointHandler, 0x3);
// Load IDT // Load IDT
KeLoadIDT(); KeLoadIDT();
DebugLog("\tInterrupt table initialized at %p\n", _KeIdtPtr.base); DebugLog("\tInterrupt table initialized at %p\n", _KeIdtPtr.base);
@ -275,8 +277,8 @@ void _KeHandleISR(ISRFrame_t *regs)
// //
static void EarlyExceptionHandler(ISRFrame_t *regs) static void EarlyExceptionHandler(ISRFrame_t *regs)
{ {
KeStartPanic("[ISR 0x%x] Irrecoverable Kernel %s\n\n" bprintf(BStdOut, "\n\n%CPANIC\n%C[ISR 0x%x] Irrecoverable Kernel %s\n\n"
" Error code : 0x%x (%b)\n\n" " Error code : 0x%x (%b)\n\n%C"
" RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n" " RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n"
@ -292,10 +294,13 @@ static void EarlyExceptionHandler(ISRFrame_t *regs)
" R14: %#016lx R15: %#016lx \n\n" " R14: %#016lx R15: %#016lx \n\n"
" RFLAGS: %#022b (%#06x)", " RFLAGS: %#022b (%#06x)",
VGA_COLOR_WHITE,
VGA_COLOR_LIGHT_RED,
regs->intNo, regs->intNo,
ExceptionsChar[regs->intNo], ExceptionsChar[regs->intNo],
regs->ErrorCode, regs->ErrorCode,
regs->ErrorCode, regs->ErrorCode,
VGA_COLOR_WHITE,
regs->rip, regs->rip,
regs->rsp, regs->rsp,
regs->rbp, regs->rbp,
@ -324,4 +329,63 @@ static void EarlyExceptionHandler(ISRFrame_t *regs)
regs->rflags, regs->rflags,
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 <lib/buf.h>
#include <ke/proc.h> #include <ke/proc.h>
#include <io/vga.h>
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
@ -71,12 +72,15 @@ noreturn void KeStartPanic(const char *fmt, ...)
// We don't check vbprintf's output // We don't check vbprintf's output
// If it fails, what could we do anyway? // If it fails, what could we do anyway?
bprintf(BStdOut, "\nPANIC\n"); bprintf(BStdOut, "%C\nPANIC\n%C", VGA_COLOR_WHITE, VGA_COLOR_LIGHT_RED);
va_start(ap, fmt); va_start(ap, fmt);
vbprintf(BStdOut, fmt, ap); vbprintf(BStdOut, fmt, ap);
va_end(ap); va_end(ap);
interrupt(0x3);
bputc(BStdOut, '\n'); bputc(BStdOut, '\n');
BStdOut->flusher(BStdOut); BStdOut->flusher(BStdOut);

View File

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