1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <panic.h>
#include <stdint.h>
#include <printf.h>
#include <addr.h>
#include <klog.h>
#include <isv.h>
#include <smp_sync.h>
static uint8_t panic_lock = 0;
void panic(int reason, void *eframe_p, struct registers *regs) { // will fill with debugging info latter
lock(&panic_lock);
#ifdef EASTEREGG_BLOATWARE
printf("\nKernel PANIC!!!!!!!\n");
printf(
" _.-^^---....,,-- \n"
" _-- --_ \n"
"< >)\n"
"| BOOM | <------- your computer\n"
" \\._ _./ \n"
" ```--. . , ; .--''' \n"
" | | | \n"
" .-=|| | |=-. \n"
" `-=#$%&%$#=-' \n"
" | ; :| \n"
" _____.,-#%&$@%#&#~,._____\n");
#else
printf("Kernel Panic!\n");
#endif
switch(reason) {
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");
case KERNEL_PANIC_SMP_FAILED:
printf("\nNot all cores booted successfully (see text before panic).\n");
break;
default:
printf("\nUnknown panic code %i\n.", reason);
break;
}
struct stack_frame *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("\t0x%p\n", frame->function_base);
}
//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);
asm("cli\nhlt");
}
|