From f07fdafd52e89754ab6d06852ce56e48333b2793 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 19 May 2019 00:38:58 +0200 Subject: [PATCH] Crashdump yay --- include/io/vga.h | 36 ++++++++++++++++++------------------ kaleid/kernel/init/info.c | 2 +- kaleid/kernel/ke/idt.c | 17 +++++++---------- kaleid/kernel/ke/panic.c | 10 +++++----- kaleid/kernel/mm/paging.c | 8 ++------ kaleid/kernel/sh/shcmds.c | 12 ++++++------ 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/include/io/vga.h b/include/io/vga.h index b0b8857..7155fcf 100644 --- a/include/io/vga.h +++ b/include/io/vga.h @@ -33,24 +33,24 @@ enum { - VGA_COLOR_BLACK, - VGA_COLOR_BLUE, - VGA_COLOR_GREEN, - VGA_COLOR_CYAN, - VGA_COLOR_RED, - VGA_COLOR_MAGENTA, - VGA_COLOR_BROWN, - VGA_COLOR_LIGHT_GREY, - VGA_COLOR_DARK_GREY, - VGA_COLOR_LIGHT_BLUE, - VGA_COLOR_LIGHT_GREEN, - VGA_COLOR_LIGHT_CYAN, - VGA_COLOR_LIGHT_RED, - VGA_COLOR_LIGHT_MAGENTA, - VGA_COLOR_LIGHT_BROWN, - VGA_COLOR_WHITE, - - VGA_COLOR_CURRENT = -1, + VGA_COLOR_BLACK, + VGA_COLOR_BLUE, + VGA_COLOR_GREEN, + VGA_COLOR_CYAN, + VGA_COLOR_RED, + VGA_COLOR_MAGENTA, + VGA_COLOR_BROWN, + VGA_COLOR_LIGHT_GREY, + VGA_COLOR_DARK_GREY, + VGA_COLOR_LIGHT_BLUE, + VGA_COLOR_LIGHT_GREEN, + VGA_COLOR_LIGHT_CYAN, + VGA_COLOR_LIGHT_RED, + VGA_COLOR_LIGHT_MAGENTA, + VGA_COLOR_LIGHT_BROWN, + VGA_COLOR_WHITE, + + VGA_COLOR_CURRENT = -1, }; extern const char *RtlColorNames[VGA_COLOR_WHITE+1]; diff --git a/kaleid/kernel/init/info.c b/kaleid/kernel/init/info.c index d68580c..8f8d6ae 100644 --- a/kaleid/kernel/init/info.c +++ b/kaleid/kernel/init/info.c @@ -112,7 +112,7 @@ void BtDoSanityChecks(uint mbMagic) { if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC)) KeStartPanic("Magic number %x is incorrect\n", mbMagic); - DebugLog("\tKernel successfully loaded at %p\n", + DebugLog("\t Kernel successfully loaded at %p\n", BtLoaderInfo.kernelAddr); } diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index ea804c4..1937d28 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -29,6 +29,7 @@ IdtEntry_t idt[256] = { 0 }; IdtPtr_t _KeIdtPtr; +bool KeIdtIsInitialized = 0; static ISRList_t isrList = { 0 }; @@ -79,7 +80,7 @@ error_t KeRegisterISR(void (*isr)(ISRFrame_t *regs), uchar isrNo) uchar n = isrList.n; int OverWriting = 0; - assert(idt[0].flags!=0); // IDT initialized + assert(KeIdtIsInitialized); // IDT initialized if (n == 0) goto settingUp; @@ -168,6 +169,8 @@ void KeSetupIDT(void) KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E); KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E); + KeIdtIsInitialized++; + //Setup Early Exception handler for (uchar i = 0 ; i < 0x20 ; i++) { KeRegisterISR(EarlyExceptionHandler, i); @@ -277,8 +280,8 @@ void _KeHandleISR(ISRFrame_t *regs) // static void EarlyExceptionHandler(ISRFrame_t *regs) { - bprintf(BStdOut, "\n\n%CPANIC\n%C[ISR 0x%x] Irrecoverable Kernel %s\n\n" - " Error code : 0x%x (%b)\n\n%C" + bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x%x] Irrecoverable Kernel %s\n\n" + " Error code : 0x%x (%b)\n\n" " RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n" @@ -294,13 +297,11 @@ 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, @@ -330,8 +331,6 @@ static void EarlyExceptionHandler(ISRFrame_t *regs) regs->rflags ); - bputc(BStdOut, '\n'); - BStdOut->flusher(BStdOut); KeHaltCPU(); @@ -355,7 +354,7 @@ static void BreakPointHandler(ISRFrame_t *regs) " R14: %#016lx R15: %#016lx \n\n" " RFLAGS: %#022b (%#06x)", - VGA_COLOR_WHITE, + VGA_COLOR_LIGHT_RED, regs->rip, regs->rsp, regs->rbp, @@ -385,7 +384,5 @@ static void BreakPointHandler(ISRFrame_t *regs) regs->rflags ); - bputc(BStdOut, '\n'); - BStdOut->flusher(BStdOut); } diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index b22402d..80b8d88 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -27,6 +27,7 @@ #include error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); +extern bool KeIdtIsInitialized; // // Failed assert() handler @@ -72,17 +73,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, "%C\nPANIC\n", VGA_COLOR_LIGHT_RED); va_start(ap, fmt); vbprintf(BStdOut, fmt, ap); va_end(ap); - - interrupt(0x3); - bputc(BStdOut, '\n'); - + if (KeIdtIsInitialized) + interrupt(0x3); + BStdOut->flusher(BStdOut); KeHaltCPU(); diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 6d33d14..950a95d 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -167,8 +167,8 @@ void MmReloadPaging(void) // static void PagingHandler(ISRFrame_t *regs) { - 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" + bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x%x] Irrecoverable Kernel Page Fault at %p\n\n" + " Error code : 0x%x (%b)\n\n" " RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n" @@ -184,13 +184,11 @@ 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, @@ -220,8 +218,6 @@ static void PagingHandler(ISRFrame_t *regs) regs->rflags ); - bputc(BStdOut, '\n'); - BStdOut->flusher(BStdOut); KeHaltCPU(); diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index 79e2c84..41d6eb4 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -207,13 +207,13 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline); error_t CmdVersion(int argc, char **argv, char *cmdline) { - KernLog("OS/K, version %s (x86-64)\n", _KALEID_VERSION); - KernLog("Copyright (C) 2019 The OS/K Team.\n"); - KernLog("License GPLv3+: GNU GPL version 3 " - "or later \n"); + KernLog("OS/K version %s (x86-64)\n", _KALEID_VERSION); + KernLog("Copyright (C) 2018-2019 The OS/K Team\n"); + KernLog("License GNU GPL version 3 " + "or later, see \n"); KernLog("This is free software; you are " "free to change and redistribute it.\n"); - KernLog("There is NO WARRANTY, to the extent permitted by law.\n"); + KernLog("There is NO WARRANTY, to the extent permitted by law.\n\n"); return EOK; } @@ -239,7 +239,7 @@ Command_t cmdtable[] = { "shell", CmdShell, "Start a new shell (nested)", }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" }, { "time", CmdTime, "Print time" }, - { "vers", CmdVersion, "Version and legal infos" }, + { "ver", CmdVersion, "Version and legal infos" }, { NULL, NULL, NULL } };