/* * @author xamidev * @brief Kernel panic * @license GPL-3.0-only */ #include #include "idt/idt.h" #include "io/serial/serial.h" #include "kernel.h" extern struct init_status init; /* * panic - Kernel panic * @ctx: CPU context (optional) * @str: Error message * * Ends execution of the kernel in case of an unrecoverable error. * Will display to terminal if it is initialized, otherwise serial only. * Can be called with or without a CPU context. */ void panic(struct cpu_status_t* ctx, const char* str) { CLEAR_INTERRUPTS; if (ctx == NULL) { DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)"); fctprintf((void*)&skputc, 0, "\x1b[38;5;231m\x1b[48;5;27m"); DIE_DEBUG(str); fctprintf((void*)&skputc, 0, "\x1b[0m"); skputc('\r'); skputc('\n'); DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m"); if (init.terminal) { printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[48;5;232m Something went horribly wrong! (no cpu ctx)"); printf("\r\n%s\r\n\x1b[38;5;231mend Kernel panic - halting...\x1b[0m", str); } hcf(); } DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rHalting...\x1b[0m", ctx->iret_rip, str, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags); if (init.terminal) { printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[48;5;232mat rip=%p\r\nSomething went horribly wrong! (%s) vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rHalting...\x1b[0m", ctx->iret_rip, str, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags); } debug_stack_trace(100); hcf(); }