summaryrefslogtreecommitdiff
path: root/src/kernel/panic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/panic.c')
-rw-r--r--src/kernel/panic.c80
1 files changed, 58 insertions, 22 deletions
diff --git a/src/kernel/panic.c b/src/kernel/panic.c
index 851684a..82a761f 100644
--- a/src/kernel/panic.c
+++ b/src/kernel/panic.c
@@ -1,13 +1,15 @@
#include <panic.h>
#include <stdint.h>
#include <printf.h>
+#include <kernel.h>
+#include <serial.h>
+#include <isv.h>
-void panic(int reason, int type) { // will fill with debugging info latter
+void panic(int reason, void *eframe_p, struct registers *regs) { // will fill with debugging info latter
+
- struct stack_frame *frame;
-
#ifdef EASTEREGG_BLOATWARE
- printf("Kernel PANIC!!!!!!!\n");
+ printf("\nKernel PANIC!!!!!!!\n");
printf(
" _.-^^---....,,-- \n"
" _-- --_ \n"
@@ -24,31 +26,65 @@ void panic(int reason, int type) { // will fill with debugging info latter
printf("Kernel Panic!\n");
#endif
- printf("Reason:\n");
-
switch(reason) {
- case KERNEL_PANIC_PMAPSIZE :
- printf("\tThe physical map can't fit in the first memory zone.\n"
- "\tNote: If you have this issue, please contact me.\n"
- "\tIt's a fixable bug caused by an unlikely scenario.\n");
- break;
- case KERNEL_PANIC_RSDP_UNFOUND:
- printf("\tRSDP unfound!\n");
- break;
- case KERNEL_PANIC_KERNEL_RETURNED:
- printf("\tThe kernel (almost) reached its return!\n");
- break;
+ case KERNEL_PANIC_HW_EXCEPTION:
+ case KERNEL_PANIC_HW_EXCEPTION_ERR:
+ printf("\nHardware exception in kernel space!\n");
+ break;
+
+ case KERNEL_PANIC_RSDP_UNFOUND:
+ printf("\nRSDP unfound!\n");
+ break;
+ case KERNEL_PANIC_KERNEL_RETURNED:
+ printf("\nThe kernel (almost) reached its return!\n");
+ break;
+ case KERNEL_PANIC_INVALID_PFREE:
+ printf("\npfree was called with invalid paramaters.\n");
+ break;
+ case KERNEL_PANIC_INVALID_RSDT:
+ printf("\nInvalid RSDT or XSDT after RSDP verification.\nIf this happens, go buy some lottery tickets.\n");
+ break;
+ case KERNEL_PANIC_INVALID_IOAPIC_VEC:
+ printf("\nThe kernel tried to make a vector that was too high for the IOAPIC to handle.\n");
+ break;
+ case KERNEL_PANIC_HPET_REQUIRED:
+ printf("\nHPET is required. \nIf you get this error, let know;\nif enough people share this issue, I'll impliment PIT usage.\n");
+ default:
+ printf("\nUnknown panic code %i\n.", reason);
+ break;
}
- printf("\nStack trace:\n");
+ struct stack_frame *frame;
- asm("mov %%rbp,%0" : "=r"(frame) ::);
+ char reg_str[156];
+ if((reason == KERNEL_PANIC_HW_EXCEPTION) || (reason == KERNEL_PANIC_HW_EXCEPTION_ERR)) {
+ sprintf(reg_str, "rax:\t0x%lx\n"
+ "rbx:\t0x%lx\n"
+ "rcx:\t0x%lx\n"
+ "rdx:\t0x%lx\n"
+ "rsi:\t0x%lx\n"
+ "rdi:\t0x%lx\n", regs->rax, regs->rbx, regs->rcx, regs->rdx, regs->rsi, regs->rdi);
+ }
+ if(reason == KERNEL_PANIC_HW_EXCEPTION) {
+ struct int_frame *ex_frame = eframe_p;
+ printf("Offending instruction:\t0x%p\n", ex_frame->rip);
+ printf(reg_str);
+ }
+ else if (reason == KERNEL_PANIC_HW_EXCEPTION_ERR) {
+ struct exception_frame *ex_frame = eframe_p;
+ printf("Offending instruction: 0x%p\nError value: %x\n", ex_frame->frame.rip, ex_frame->err);
+ printf(reg_str);
+ }
+ asm("mov %0, rbp" : "=r"(frame) ::);
+ printf("\nCall trace:\n");
+
for(; frame->next != 0; frame = frame->next) {
- printf("\t%x\n", frame->function_base);
+ printf("\t0x%p\n", frame->function_base);
}
+
- //It's not public yet, but it will be
+ //It's not public yet, but if I ever get somewhere it will be
printf("\nAfter ensuring your computer meets the requirements specified, if you think this is a bug, please open an issue on the git repo or email me at %s.\n", DEV_EMAIL);
- for(;;);
+ asm("cli\nhlt");
}