summaryrefslogtreecommitdiff
path: root/kernel/panic.c
blob: bdd4e93a208dcc16d6af52aa74b97474f44acb88 (plain)
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
#include "panic.h"
#include "printf.h"

char* panic_msg[] = {
	"#DE - Divide error.",
	"#DB",
	"#2",
	"#BP",
	"#OF",
	"#BR",
	"#UD - Invalid opcode.",
	"#NM",
	"#DF - Double fault.",
	"#9",
	"#TS",
	"#NP",
	"#SS",
	"#GP - General protection fault.",
	"#PF - Page fault.",
	"#15",
	"#MF",
	"#AC",
	"#MC",
	"#XM",
	[20 ... 31] = "Undefined exception."
};

void panic(panic_stack_t stack) {
	printf("Kernel panic: %s\n", panic_msg[stack.num]);
	printf("INT: %8u      EC: %08x\n", stack.num, stack.error_code);
	printf(" CS:     %04x      DS:     %04x      SS: %04x\n", stack.cs, stack.ds, stack.ss);
	printf("EIP: %08x  EFLAGS: %08x\n", stack.eip, stack.eflags);
	printf("EAX: %08x     EBX: %08x     ECX: %08x     EDX: %08x\n", stack.eax, stack.ebx, stack.ecx, stack.edx);
	printf("ESP: %08x     EBP: %08x     ESI: %08x     EDI: %08x\n", stack.esp, stack.ebp, stack.esi, stack.edi);
	
	asm volatile(
		"cli\n"
		"hlt\n"
	);
	while(1);
}