summaryrefslogtreecommitdiff
path: root/src/interrupt.c
blob: 54f9947034326c452263364ca49724259e3a61ba (plain) (blame)
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
#include "aplos.h"

struct handler {
	char8_t *description;
	bool (*fn)(uint32_t code);
} handlers[256] = {
	[0]  = {
		.description = u8"divide-by-zero-error"
	},
	[1]  = {
		.description = u8"debug"
	},
	[2]  = {
		.description = u8"non-maskable-interrupt"
	},
	[3]  = {
		.description = u8"breakpoint"
	},
	[4]  = {
		.description = u8"overflow"
	},
	[5]  = {
		.description = u8"bound-range"
	},
	[6]  = {
		.description = u8"invalid-opcode"
	},
	[7]  = {
		.description = u8"device-not-available"
	},
	[8]  = {
		.description = u8"double-fault"
	},
	[9]  = {
		.description = u8"coprocessor-segment-overrun"
	},
	[10] = {
		.description = u8"invalid-tss"
	},
	[11] = {
		.description = u8"segment-not-present"
	},
	[12] = {
		.description = u8"stack"
	},
	[13] = {
		.description = u8"general-protection"
	},
	[14] = {
		.description = u8"page-fault",
		.fn = page_fault_handler
	},
	[16] = {
		.description = u8"x87 floating-point exception-pending"
	},
	[17] = {
		.description = u8"alignment-check"
	},
	[18] = {
		.description = u8"machine-check"
	},
	[19] = {
		.description = u8"simd floating-point"
	},
	[21] = {
		.description = u8"control protection"
	},
	[28] = {
		.description = u8"hypervisor injection exception"
	},
	[29] = {
		.description = u8"vmm communication exception"
	},
	[30] = {
		.description = u8"security exception"
	}
};

void
interrupt_handler(uint8_t n, uint32_t code)
{
	struct handler *h = handlers+n;
	bool handled;
	if(h->fn)
		handled = h->fn(code);
	if(!handled){
		print(u8"Unhandled interrupt: %u8 (%s) with error code %x32\n", n, h->description ? h->description : u8"???", code);
		panic();
	}
}