diff --git a/include/asm.h b/include/asm.h index f69585c..aa39caf 100644 --- a/include/asm.h +++ b/include/asm.h @@ -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 // diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index c840426..2adcff9 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -23,7 +23,6 @@ //----------------------------------------------------------------------------// #include "init.h" -#include 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(); diff --git a/kaleid/kernel/init/init.h b/kaleid/kernel/init/init.h index 5aa43f1..5480722 100644 --- a/kaleid/kernel/init/init.h +++ b/kaleid/kernel/init/init.h @@ -32,6 +32,7 @@ #include #include #include +#include // info.c extern void BtDoSanityChecks(uint mbMagic); diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index b26df14..ea804c4 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -25,6 +25,7 @@ #include #include #include +#include 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); } diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 1f55c62..b22402d 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -24,6 +24,7 @@ #include #include +#include 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); diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 4c54ddd..6d33d14 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -3,6 +3,9 @@ #include #include #include +#include +#include + #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)