From d1a46d7acd131f98464ed1ea7d4931339e98efa5 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 19 May 2019 01:33:16 +0200 Subject: [PATCH] Crashdump yay --- include/ke/idt.h | 1 + kaleid/kernel/init/init.c | 2 +- kaleid/kernel/io/spkr.c | 5 +++- kaleid/kernel/ke/idt.c | 52 +++++---------------------------------- kaleid/kernel/ke/panic.c | 3 +-- kaleid/kernel/mm/gdt.asm | 3 +-- kaleid/kernel/mm/gdt.c | 7 ++---- kaleid/kernel/mm/paging.c | 47 +++-------------------------------- kaleid/libbuf/bputc.c | 5 ++++ 9 files changed, 25 insertions(+), 100 deletions(-) diff --git a/include/ke/idt.h b/include/ke/idt.h index 975004c..4b4f2be 100644 --- a/include/ke/idt.h +++ b/include/ke/idt.h @@ -73,6 +73,7 @@ void KeSetupIDT(void); void KeSendEOItoPIC(uchar isr); void KeSetIDTGate(uchar rank, ulong base, ushort selector, uchar flags); error_t KeRegisterISR(void (*isr)(ISRFrame_t *regs), uchar isrNo); +void KeBrkDumpRegisters(ISRFrame_t *regs); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 2adcff9..c259438 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -55,7 +55,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // Memory MmInitMemoryMap(); - //MmInitGdt(); + MmInitGdt(); MmInitPaging(); MmInitHeap(); diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c index 92f0957..1bc418a 100644 --- a/kaleid/kernel/io/spkr.c +++ b/kaleid/kernel/io/spkr.c @@ -25,6 +25,8 @@ #include #include +extern bool KeIdtIsInitialized; + void IoStartSpeaker(int freq) { uchar temp; @@ -58,7 +60,8 @@ void IoDoTone(uint tone, uint time) void IoDoBeep(void) { - IoDoTone(1000, 100); + if (KeIdtIsInitialized) + IoDoTone(1000, 100); } void IoDoStarWars(void) diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index 1937d28..204aebd 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -70,7 +70,6 @@ static char *ExceptionsChar[32] = { static void EnablePIC(void); static void EarlyExceptionHandler(ISRFrame_t *regs); -static void BreakPointHandler(ISRFrame_t *regs); // // Registers an isr with his IRQ to handle driver interrupts @@ -176,7 +175,7 @@ void KeSetupIDT(void) KeRegisterISR(EarlyExceptionHandler, i); } - KeRegisterISR(BreakPointHandler, 0x3); + KeRegisterISR(KeBrkDumpRegisters, 0x3); // Load IDT KeLoadIDT(); @@ -281,62 +280,23 @@ void _KeHandleISR(ISRFrame_t *regs) static void EarlyExceptionHandler(ISRFrame_t *regs) { bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x%x] Irrecoverable Kernel %s\n\n" - " Error code : 0x%x (%b)\n\n" + " Error code : 0x%x (%b)", - " 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_LIGHT_RED, regs->intNo, ExceptionsChar[regs->intNo], regs->ErrorCode, - regs->ErrorCode, - 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 + regs->ErrorCode ); + KeBrkDumpRegisters(regs); + BStdOut->flusher(BStdOut); KeHaltCPU(); } -static void BreakPointHandler(ISRFrame_t *regs) +void KeBrkDumpRegisters(ISRFrame_t *regs) { bprintf(BStdOut, "\n\n" diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 80b8d88..c0cb5af 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -51,6 +51,7 @@ noreturn void KeStartPanic(const char *fmt, ...) { va_list ap; + bprintf(BStdOut, "%C\nPANIC\n\a", VGA_COLOR_LIGHT_RED); KeDisableIRQs(); KeCurProc = NULL; @@ -73,8 +74,6 @@ 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", VGA_COLOR_LIGHT_RED); - va_start(ap, fmt); vbprintf(BStdOut, fmt, ap); diff --git a/kaleid/kernel/mm/gdt.asm b/kaleid/kernel/mm/gdt.asm index 49a2947..b7b503b 100644 --- a/kaleid/kernel/mm/gdt.asm +++ b/kaleid/kernel/mm/gdt.asm @@ -48,7 +48,6 @@ MmLoadGdt: ;; Stores the GDT ;; MmStoreGdt: - ;; Loading the gdt via the gdtPtr pointer - sgdt [rel gdtPtr] + sgdt [gdtPtr] ret diff --git a/kaleid/kernel/mm/gdt.c b/kaleid/kernel/mm/gdt.c index ec5d221..e736c5a 100644 --- a/kaleid/kernel/mm/gdt.c +++ b/kaleid/kernel/mm/gdt.c @@ -65,10 +65,7 @@ static void SetTssEntry(uchar index, ulong base, ulong limit) void MmInitGdt(void) { - gdtPtr.limit = (sizeof(GdtEntry_t) * 5) - 1; - gdtPtr.base = (uint)(ullong)&gdtEntries; - - MmStoreGdt(); + //MmStoreGdt(); /* SetGdtEntry(1, 0x0, 0xfffff, 0x02 | 0x08); */ @@ -76,7 +73,7 @@ void MmInitGdt(void) /* SetTssEntry(2, (ulong)&tssEntry, sizeof(TssEntry_t)); */ - MmLoadGdt(); + //MmLoadGdt(); } diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 950a95d..9b9d174 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -168,56 +168,17 @@ void MmReloadPaging(void) static void PagingHandler(ISRFrame_t *regs) { bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x%x] Irrecoverable Kernel Page Fault at %p\n\n" - " Error code : 0x%x (%b)\n\n" + " Error code : 0x%x (%b)", - " 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_LIGHT_RED, regs->intNo, regs->cr2, regs->ErrorCode, - regs->ErrorCode, - 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 + regs->ErrorCode ); + KeBrkDumpRegisters(regs); + BStdOut->flusher(BStdOut); KeHaltCPU(); diff --git a/kaleid/libbuf/bputc.c b/kaleid/libbuf/bputc.c index 059e9f0..d2d4ee1 100644 --- a/kaleid/libbuf/bputc.c +++ b/kaleid/libbuf/bputc.c @@ -23,6 +23,7 @@ //----------------------------------------------------------------------------// #include +#include // // Writes a character on a buffer @@ -77,6 +78,10 @@ error_t bputc(Buffer_t *buf, uchar ch) if (buf->flusher) buf->flusher(buf); } + else if (ch == '\a') { + IoDoBeep(); + } + // Deal with carriage returns else if (ch == '\r') { buf->wp -= buf->lastLF;